aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
authorCharles Lew <[email protected]>2020-09-16 17:50:24 +0100
committerCharles Lew <[email protected]>2020-09-16 17:58:41 +0100
commit3fff5aa4d72df9775baca32f54728da8cb6c31ed (patch)
treecdbff6b12254ec46062a45e820353e59acd12db8 /crates/hir_ty
parenteb969647561f46c783469469284538ed95d77076 (diff)
Use Ty::apply instead of simple and fix method resolution.
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/lower.rs10
-rw-r--r--crates/hir_ty/src/method_resolution.rs8
-rw-r--r--crates/hir_ty/src/tests/method_resolution.rs4
3 files changed, 14 insertions, 8 deletions
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<Ty> {
1102 let ctx = 1102 let ctx =
1103 TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); 1103 TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
1104 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1104 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST);
1105 let inner = if db.type_alias_data(t).is_extern { 1105 if db.type_alias_data(t).is_extern {
1106 Ty::simple(TypeCtor::ForeignType(t)) 1106 Binders::new(substs.len(), Ty::apply(TypeCtor::ForeignType(t), substs))
1107 } else { 1107 } else {
1108 let type_ref = &db.type_alias_data(t).type_ref; 1108 let type_ref = &db.type_alias_data(t).type_ref;
1109 Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error)) 1109 let inner = Ty::from_hir(&ctx, type_ref.as_ref().unwrap_or(&TypeRef::Error));
1110 }; 1110 Binders::new(substs.len(), inner)
1111 Binders::new(substs.len(), inner) 1111 }
1112} 1112}
1113 1113
1114#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 1114#[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 {
250 TypeCtor::Adt(def_id) => { 250 TypeCtor::Adt(def_id) => {
251 return Some(std::iter::once(def_id.module(db.upcast()).krate).collect()) 251 return Some(std::iter::once(def_id.module(db.upcast()).krate).collect())
252 } 252 }
253 TypeCtor::ForeignType(type_alias_id) => {
254 return Some(
255 std::iter::once(
256 type_alias_id.lookup(db.upcast()).module(db.upcast()).krate,
257 )
258 .collect(),
259 )
260 }
253 TypeCtor::Bool => lang_item_crate!("bool"), 261 TypeCtor::Bool => lang_item_crate!("bool"),
254 TypeCtor::Char => lang_item_crate!("char"), 262 TypeCtor::Char => lang_item_crate!("char"),
255 TypeCtor::Float(f) => match f.bitness { 263 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() {
1072 s.foo(); 1072 s.foo();
1073 } 1073 }
1074 "#, 1074 "#,
1075 // FIXME: 's.foo()' should be `bool`.
1076 expect![[r#" 1075 expect![[r#"
1077 75..79 'self': &S 1076 75..79 'self': &S
1078 89..109 '{ ... }': bool 1077 89..109 '{ ... }': bool
@@ -1084,8 +1083,7 @@ fn method_resolution_foreign_opaque_type() {
1084 146..147 'f': fn f() -> &S 1083 146..147 'f': fn f() -> &S
1085 146..149 'f()': &S 1084 146..149 'f()': &S
1086 157..158 's': &S 1085 157..158 's': &S
1087 157..164 's.foo()': {unknown} 1086 157..164 's.foo()': bool
1088 "#]], 1087 "#]],
1089 ); 1088 );
1090} 1089}
1091