Skip to content

Commit

Permalink
Rollup merge of #57836 - oli-obk:existential_crisis, r=estebank
Browse files Browse the repository at this point in the history
Fix some cross crate existential type ICEs

fixes #53443
  • Loading branch information
Centril committed Jan 23, 2019
2 parents 5749bac + 5d6faf7 commit d17f62d
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 2 deletions.
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();
}

0 comments on commit d17f62d

Please sign in to comment.