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

Fix some cross crate existential type ICEs #57836

Merged
merged 2 commits into from
Jan 24, 2019
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
3 changes: 3 additions & 0 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,9 @@ impl<'a, 'tcx> CrateMetadata {
EntryKind::AssociatedType(container) => {
(ty::AssociatedKind::Type, container, false)
}
EntryKind::AssociatedExistential(container) => {
(ty::AssociatedKind::Existential, container, false)
}
_ => bug!("cannot get associated-item of `{:?}`", def_key)
};

Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ impl<'a> Resolver<'a> {
}
module.populated.set(true);
}
Def::Existential(..) |
Def::TraitAlias(..) => {
self.define(parent, ident, TypeNS, (def, vis, DUMMY_SP, expansion));
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,8 @@ fn check_existential_types<'a, 'fcx, 'gcx, 'tcx>(
if let ty::Opaque(def_id, substs) = ty.sty {
trace!("check_existential_types: opaque_ty, {:?}, {:?}", def_id, substs);
let generics = tcx.generics_of(def_id);
// only check named existential types
if generics.parent.is_none() {
// only check named existential types defined in this crate
if generics.parent.is_none() && def_id.is_local() {
let opaque_node_id = tcx.hir().as_local_node_id(def_id).unwrap();
if may_define_existential_type(tcx, fn_def_id, opaque_node_id) {
trace!("check_existential_types may define. Generics: {:#?}", generics);
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/existential_types/auxiliary/cross_crate_ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Crate that exports an existential type. Used for testing cross-crate.

#![crate_type="rlib"]

#![feature(existential_type)]

pub existential type Foo: std::fmt::Debug;

pub fn foo() -> Foo {
5
}

21 changes: 21 additions & 0 deletions src/test/ui/existential_types/auxiliary/cross_crate_ice2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Crate that exports an existential type. Used for testing cross-crate.

#![crate_type="rlib"]

#![feature(existential_type)]

pub trait View {
type Tmp: Iterator<Item = u32>;

fn test(&self) -> Self::Tmp;
}

pub struct X;

impl View for X {
existential type Tmp: Iterator<Item = u32>;

fn test(&self) -> Self::Tmp {
vec![1,2,3].into_iter()
}
}
16 changes: 16 additions & 0 deletions src/test/ui/existential_types/cross_crate_ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// aux-build:cross_crate_ice.rs
// compile-pass

extern crate cross_crate_ice;

struct Bar(cross_crate_ice::Foo);

impl Bar {
fn zero(&self) -> &cross_crate_ice::Foo {
&self.0
}
}

fn main() {
let _ = cross_crate_ice::foo();
}
11 changes: 11 additions & 0 deletions src/test/ui/existential_types/cross_crate_ice2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// aux-build:cross_crate_ice2.rs
// compile-pass

extern crate cross_crate_ice2;

use cross_crate_ice2::View;

fn main() {
let v = cross_crate_ice2::X;
v.test();
}