Skip to content

Commit

Permalink
Rollup merge of rust-lang#77375 - petrochenkov:inherext, r=oli-obk
Browse files Browse the repository at this point in the history
rustc_metadata: Do not forget to encode inherent impls for foreign types

So I tried to move FFI interface for LLVM from `rustc_codegen_llvm` to `rustc_llvm` and immediately encountered this fascinating issue.

Fixes rust-lang#46665.
  • Loading branch information
Dylan-DPC authored Oct 1, 2020
2 parents 260256b + 384eb26 commit 9b26c35
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,7 @@ impl EncodeContext<'a, 'tcx> {
self.encode_const_stability(def_id);
self.encode_deprecation(def_id);
self.encode_item_type(def_id);
self.encode_inherent_implementations(def_id);
if let hir::ForeignItemKind::Fn(..) = nitem.kind {
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
self.encode_variances_of(def_id);
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/extern/auxiliary/extern-types-inherent-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(extern_types)]

extern "C" {
pub type CrossCrate;
}

impl CrossCrate {
pub fn foo(&self) {}
}
23 changes: 15 additions & 8 deletions src/test/ui/extern/extern-types-inherent-impl.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
// run-pass
#![allow(dead_code)]
// Test that inherent impls can be defined for extern types.

// check-pass
// aux-build:extern-types-inherent-impl.rs

#![feature(extern_types)]

extern {
type A;
extern crate extern_types_inherent_impl;
use extern_types_inherent_impl::CrossCrate;

extern "C" {
type Local;
}

impl A {
fn foo(&self) { }
impl Local {
fn foo(&self) {}
}

fn use_foo(x: &A) {
fn use_foo(x: &Local, y: &CrossCrate) {
Local::foo(x);
x.foo();
CrossCrate::foo(y);
y.foo();
}

fn main() { }
fn main() {}

0 comments on commit 9b26c35

Please sign in to comment.