Use Ty::apply instead of simple and fix method resolution.

This commit is contained in:
Charles Lew 2020-09-17 00:50:24 +08:00
parent eb96964756
commit 3fff5aa4d7
3 changed files with 14 additions and 8 deletions

View file

@ -1102,13 +1102,13 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
let ctx =
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
let inner = if db.type_alias_data(t).is_extern {
Ty::simple(TypeCtor::ForeignType(t))
if db.type_alias_data(t).is_extern {
Binders::new(substs.len(), Ty::apply(TypeCtor::ForeignType(t), substs))
} else {
let type_ref = &db.type_alias_data(t).type_ref;
Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error))
};
Binders::new(substs.len(), inner)
let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error));
Binders::new(substs.len(), inner)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]

View file

@ -250,6 +250,14 @@ impl Ty {
TypeCtor::Adt(def_id) => {
return Some(std::iter::once(def_id.module(db.upcast()).krate).collect())
}
TypeCtor::ForeignType(type_alias_id) => {
return Some(
std::iter::once(
type_alias_id.lookup(db.upcast()).module(db.upcast()).krate,
)
.collect(),
)
}
TypeCtor::Bool => lang_item_crate!("bool"),
TypeCtor::Char => lang_item_crate!("char"),
TypeCtor::Float(f) => match f.bitness {

View file

@ -1072,7 +1072,6 @@ fn method_resolution_foreign_opaque_type() {
s.foo();
}
"#,
// FIXME: 's.foo()' should be `bool`.
expect![[r#"
75..79 'self': &S
89..109 '{ ... }': bool
@ -1084,8 +1083,7 @@ fn method_resolution_foreign_opaque_type() {
146..147 'f': fn f() -> &S
146..149 'f()': &S
157..158 's': &S
157..164 's.foo()': {unknown}
157..164 's.foo()': bool
"#]],
);
}