Fix some cross crate existential type ICEs

This commit is contained in:
Oliver Scherer 2019-01-22 15:08:31 +01:00
parent 70015373b4
commit 26edb28d31
7 changed files with 68 additions and 2 deletions

View File

@ -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)
};

View File

@ -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));
}

View File

@ -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);

View File

@ -0,0 +1,13 @@
// Crate that exports an existential type. Used for testing cross-crate.
#![feature(const_fn)]
#![crate_type="rlib"]
#![feature(existential_type)]
pub existential type Foo: std::fmt::Debug;
pub fn foo() -> Foo {
5
}

View File

@ -0,0 +1,22 @@
// Crate that exports an existential type. Used for testing cross-crate.
#![feature(const_fn)]
#![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()
}
}

View File

@ -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();
}

View File

@ -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();
}