From 3fff5aa4d72df9775baca32f54728da8cb6c31ed Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Thu, 17 Sep 2020 00:50:24 +0800 Subject: Use Ty::apply instead of simple and fix method resolution. --- crates/hir_ty/src/lower.rs | 10 +++++----- crates/hir_ty/src/method_resolution.rs | 8 ++++++++ crates/hir_ty/src/tests/method_resolution.rs | 4 +--- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 39252bc5e..708e2af0f 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -1102,13 +1102,13 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders { 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)] diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index ec59145c7..8961df404 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -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 { diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index 690f9d66e..0f17ff151 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs @@ -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 "#]], ); } - -- cgit v1.2.3