aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/display.rs2
-rw-r--r--crates/hir_ty/src/infer/expr.rs5
-rw-r--r--crates/hir_ty/src/lib.rs14
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/hir_ty/src/method_resolution.rs6
-rw-r--r--crates/hir_ty/src/test_db.rs2
-rw-r--r--crates/hir_ty/src/tests.rs8
-rw-r--r--crates/hir_ty/src/tests/simple.rs24
-rw-r--r--crates/hir_ty/src/traits/chalk.rs4
9 files changed, 48 insertions, 19 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index d2f1b4014..38a043c48 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -617,7 +617,7 @@ impl HirDisplay for FnSig {
617} 617}
618 618
619fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = TraitId> { 619fn fn_traits(db: &dyn DefDatabase, trait_: TraitId) -> impl Iterator<Item = TraitId> {
620 let krate = trait_.lookup(db).container.module(db).krate; 620 let krate = trait_.lookup(db).container.module(db).krate();
621 let fn_traits = [ 621 let fn_traits = [
622 db.lang_item(krate, "fn".into()), 622 db.lang_item(krate, "fn".into()),
623 db.lang_item(krate, "fn_mut".into()), 623 db.lang_item(krate, "fn_mut".into()),
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 9bf3b51b0..d7351d212 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -491,7 +491,10 @@ impl<'a> InferenceContext<'a> {
491 Expr::Box { expr } => { 491 Expr::Box { expr } => {
492 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 492 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
493 if let Some(box_) = self.resolve_boxed_box() { 493 if let Some(box_) = self.resolve_boxed_box() {
494 Ty::apply_one(TypeCtor::Adt(box_), inner_ty) 494 let mut sb = Substs::build_for_type_ctor(self.db, TypeCtor::Adt(box_));
495 sb = sb.push(inner_ty);
496 sb = sb.fill(repeat_with(|| self.table.new_type_var()));
497 Ty::apply(TypeCtor::Adt(box_), sb.build())
495 } else { 498 } else {
496 Ty::Unknown 499 Ty::Unknown
497 } 500 }
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index e00c7e176..d47f975d2 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -211,19 +211,21 @@ impl TypeCtor {
211 | TypeCtor::Tuple { .. } => None, 211 | TypeCtor::Tuple { .. } => None,
212 // Closure's krate is irrelevant for coherence I would think? 212 // Closure's krate is irrelevant for coherence I would think?
213 TypeCtor::Closure { .. } => None, 213 TypeCtor::Closure { .. } => None,
214 TypeCtor::Adt(adt) => Some(adt.module(db.upcast()).krate), 214 TypeCtor::Adt(adt) => Some(adt.module(db.upcast()).krate()),
215 TypeCtor::FnDef(callable) => Some(callable.krate(db)), 215 TypeCtor::FnDef(callable) => Some(callable.krate(db)),
216 TypeCtor::AssociatedType(type_alias) => { 216 TypeCtor::AssociatedType(type_alias) => {
217 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate) 217 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate())
218 } 218 }
219 TypeCtor::ForeignType(type_alias) => { 219 TypeCtor::ForeignType(type_alias) => {
220 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate) 220 Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate())
221 } 221 }
222 TypeCtor::OpaqueType(opaque_ty_id) => match opaque_ty_id { 222 TypeCtor::OpaqueType(opaque_ty_id) => match opaque_ty_id {
223 OpaqueTyId::ReturnTypeImplTrait(func, _) => { 223 OpaqueTyId::ReturnTypeImplTrait(func, _) => {
224 Some(func.lookup(db.upcast()).module(db.upcast()).krate) 224 Some(func.lookup(db.upcast()).module(db.upcast()).krate())
225 }
226 OpaqueTyId::AsyncBlockTypeImplTrait(def, _) => {
227 Some(def.module(db.upcast()).krate())
225 } 228 }
226 OpaqueTyId::AsyncBlockTypeImplTrait(def, _) => Some(def.module(db.upcast()).krate),
227 }, 229 },
228 } 230 }
229 } 231 }
@@ -870,7 +872,7 @@ impl Ty {
870 Ty::Apply(ApplicationTy { ctor: TypeCtor::OpaqueType(opaque_ty_id), .. }) => { 872 Ty::Apply(ApplicationTy { ctor: TypeCtor::OpaqueType(opaque_ty_id), .. }) => {
871 match opaque_ty_id { 873 match opaque_ty_id {
872 OpaqueTyId::AsyncBlockTypeImplTrait(def, _expr) => { 874 OpaqueTyId::AsyncBlockTypeImplTrait(def, _expr) => {
873 let krate = def.module(db.upcast()).krate; 875 let krate = def.module(db.upcast()).krate();
874 if let Some(future_trait) = db 876 if let Some(future_trait) = db
875 .lang_item(krate, "future_trait".into()) 877 .lang_item(krate, "future_trait".into())
876 .and_then(|item| item.as_trait()) 878 .and_then(|item| item.as_trait())
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 7a734c8b9..dfb573ff3 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -1147,7 +1147,7 @@ impl CallableDefId {
1147 CallableDefId::StructId(s) => s.lookup(db).container.module(db), 1147 CallableDefId::StructId(s) => s.lookup(db).container.module(db),
1148 CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container.module(db), 1148 CallableDefId::EnumVariantId(e) => e.parent.lookup(db).container.module(db),
1149 } 1149 }
1150 .krate 1150 .krate()
1151 } 1151 }
1152} 1152}
1153 1153
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index f06aeeb42..a302456b0 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -248,12 +248,12 @@ impl Ty {
248 let lang_item_targets = match self { 248 let lang_item_targets = match self {
249 Ty::Apply(a_ty) => match a_ty.ctor { 249 Ty::Apply(a_ty) => match a_ty.ctor {
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) => { 253 TypeCtor::ForeignType(type_alias_id) => {
254 return Some( 254 return Some(
255 std::iter::once( 255 std::iter::once(
256 type_alias_id.lookup(db.upcast()).module(db.upcast()).krate, 256 type_alias_id.lookup(db.upcast()).module(db.upcast()).krate(),
257 ) 257 )
258 .collect(), 258 .collect(),
259 ) 259 )
@@ -280,7 +280,7 @@ impl Ty {
280 LangItemTarget::ImplDefId(it) => Some(it), 280 LangItemTarget::ImplDefId(it) => Some(it),
281 _ => None, 281 _ => None,
282 }) 282 })
283 .map(|it| it.lookup(db.upcast()).container.module(db.upcast()).krate) 283 .map(|it| it.lookup(db.upcast()).container.module(db.upcast()).krate())
284 .collect(); 284 .collect();
285 Some(res) 285 Some(res)
286 } 286 }
diff --git a/crates/hir_ty/src/test_db.rs b/crates/hir_ty/src/test_db.rs
index 3bbcbc242..09696fcf4 100644
--- a/crates/hir_ty/src/test_db.rs
+++ b/crates/hir_ty/src/test_db.rs
@@ -83,7 +83,7 @@ impl TestDB {
83 let crate_def_map = self.crate_def_map(krate); 83 let crate_def_map = self.crate_def_map(krate);
84 for (local_id, data) in crate_def_map.modules() { 84 for (local_id, data) in crate_def_map.modules() {
85 if data.origin.file_id() == Some(file_id) { 85 if data.origin.file_id() == Some(file_id) {
86 return ModuleId { krate, local_id }; 86 return ModuleId::top_level(krate, local_id);
87 } 87 }
88 } 88 }
89 } 89 }
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs
index 4a3fcea8d..7386a4e7b 100644
--- a/crates/hir_ty/src/tests.rs
+++ b/crates/hir_ty/src/tests.rs
@@ -188,10 +188,10 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
188 }; 188 };
189 189
190 let module = db.module_for_file(file_id); 190 let module = db.module_for_file(file_id);
191 let crate_def_map = db.crate_def_map(module.krate); 191 let def_map = module.def_map(&db);
192 192
193 let mut defs: Vec<DefWithBodyId> = Vec::new(); 193 let mut defs: Vec<DefWithBodyId> = Vec::new();
194 visit_module(&db, &crate_def_map, module.local_id, &mut |it| defs.push(it)); 194 visit_module(&db, &def_map, module.local_id, &mut |it| defs.push(it));
195 defs.sort_by_key(|def| match def { 195 defs.sort_by_key(|def| match def {
196 DefWithBodyId::FunctionId(it) => { 196 DefWithBodyId::FunctionId(it) => {
197 let loc = it.lookup(&db); 197 let loc = it.lookup(&db);
@@ -321,7 +321,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
321 { 321 {
322 let events = db.log_executed(|| { 322 let events = db.log_executed(|| {
323 let module = db.module_for_file(pos.file_id); 323 let module = db.module_for_file(pos.file_id);
324 let crate_def_map = db.crate_def_map(module.krate); 324 let crate_def_map = module.def_map(&db);
325 visit_module(&db, &crate_def_map, module.local_id, &mut |def| { 325 visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
326 db.infer(def); 326 db.infer(def);
327 }); 327 });
@@ -343,7 +343,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
343 { 343 {
344 let events = db.log_executed(|| { 344 let events = db.log_executed(|| {
345 let module = db.module_for_file(pos.file_id); 345 let module = db.module_for_file(pos.file_id);
346 let crate_def_map = db.crate_def_map(module.krate); 346 let crate_def_map = module.def_map(&db);
347 visit_module(&db, &crate_def_map, module.local_id, &mut |def| { 347 visit_module(&db, &crate_def_map, module.local_id, &mut |def| {
348 db.infer(def); 348 db.infer(def);
349 }); 349 });
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs
index 8d431b920..16682f76f 100644
--- a/crates/hir_ty/src/tests/simple.rs
+++ b/crates/hir_ty/src/tests/simple.rs
@@ -29,6 +29,30 @@ mod boxed {
29} 29}
30 30
31#[test] 31#[test]
32fn infer_box_with_allocator() {
33 check_types(
34 r#"
35//- /main.rs crate:main deps:std
36fn test() {
37 let x = box 1;
38 let t = (x, box x, box &1, box [1]);
39 t;
40} //^ (Box<i32, {unknown}>, Box<Box<i32, {unknown}>, {unknown}>, Box<&i32, {unknown}>, Box<[i32; _], {unknown}>)
41
42//- /std.rs crate:std
43#[prelude_import] use prelude::*;
44mod boxed {
45 #[lang = "owned_box"]
46 pub struct Box<T: ?Sized, A: Allocator> {
47 inner: *mut T,
48 allocator: A,
49 }
50}
51"#,
52 );
53}
54
55#[test]
32fn infer_adt_self() { 56fn infer_adt_self() {
33 check_types( 57 check_types(
34 r#" 58 r#"
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index 2196af677..cfb756158 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -426,7 +426,7 @@ pub(crate) fn trait_datum_query(
426 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 426 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST);
427 let flags = rust_ir::TraitFlags { 427 let flags = rust_ir::TraitFlags {
428 auto: trait_data.auto, 428 auto: trait_data.auto,
429 upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate != krate, 429 upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate() != krate,
430 non_enumerable: true, 430 non_enumerable: true,
431 coinductive: false, // only relevant for Chalk testing 431 coinductive: false, // only relevant for Chalk testing
432 // FIXME: set these flags correctly 432 // FIXME: set these flags correctly
@@ -549,7 +549,7 @@ fn impl_def_datum(
549 let generic_params = generics(db.upcast(), impl_id.into()); 549 let generic_params = generics(db.upcast(), impl_id.into());
550 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); 550 let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST);
551 let trait_ = trait_ref.trait_; 551 let trait_ = trait_ref.trait_;
552 let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate == krate { 552 let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate() == krate {
553 rust_ir::ImplType::Local 553 rust_ir::ImplType::Local
554 } else { 554 } else {
555 rust_ir::ImplType::External 555 rust_ir::ImplType::External