about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2020-10-02 08:25:20 +0900
committerGitHub <noreply@github.com>2020-10-02 08:25:20 +0900
commitb97334f65ed5092e0172fd2fa01fd6c47e5a1841 (patch)
treeb88484e709e983650e1a7958dd8a519af8ca4626
parent55d0959328d2212c0b16906200bdde3dc8ec2cc5 (diff)
parent384eb2691f53bb0cdeb17a5ccf73c83e861d9aa1 (diff)
downloadrust-b97334f65ed5092e0172fd2fa01fd6c47e5a1841.tar.gz
rust-b97334f65ed5092e0172fd2fa01fd6c47e5a1841.zip
Rollup merge of #77375 - petrochenkov:inherext, r=oli-obk
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 https://github.com/rust-lang/rust/issues/46665.
-rw-r--r--compiler/rustc_metadata/src/rmeta/encoder.rs1
-rw-r--r--src/test/ui/extern/auxiliary/extern-types-inherent-impl.rs9
-rw-r--r--src/test/ui/extern/extern-types-inherent-impl.rs23
3 files changed, 25 insertions, 8 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index 757156e5a7d..f58a792ef58 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -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);
diff --git a/src/test/ui/extern/auxiliary/extern-types-inherent-impl.rs b/src/test/ui/extern/auxiliary/extern-types-inherent-impl.rs
new file mode 100644
index 00000000000..a1efe181843
--- /dev/null
+++ b/src/test/ui/extern/auxiliary/extern-types-inherent-impl.rs
@@ -0,0 +1,9 @@
+#![feature(extern_types)]
+
+extern "C" {
+    pub type CrossCrate;
+}
+
+impl CrossCrate {
+    pub fn foo(&self) {}
+}
diff --git a/src/test/ui/extern/extern-types-inherent-impl.rs b/src/test/ui/extern/extern-types-inherent-impl.rs
index fc98f55dc07..3f09ac7b8c3 100644
--- a/src/test/ui/extern/extern-types-inherent-impl.rs
+++ b/src/test/ui/extern/extern-types-inherent-impl.rs
@@ -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() {}