Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_metadata: Do not forget to encode inherent impls for foreign types #77375

Merged
merged 1 commit into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably deduplicate the extern item/regular item encoding logic (well, the parts that are shared between them). While I think this would be good to have, you can r=me this PR and just open an E-easy issue for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made an issue - #77393.

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() {}