diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-16 16:42:58 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-16 16:42:58 +0000 |
commit | adcc89137d3feea8f19fad461bbde6f4bce048e5 (patch) | |
tree | 160af959553ce57fdfcbc0a6c79bafcc3611aeea /crates/ra_hir_ty/src | |
parent | 648df02953a6ebf87a5876668eceba208687e8a7 (diff) | |
parent | 9faea2364dee4fbc9391ad233c570b70256ef002 (diff) |
Merge #3584
3584: Switch to dynamic dispatch r=matklad a=matklad
Benches are in https://github.com/rust-analyzer/rust-analyzer/issues/1987#issuecomment-598807185
TL;DR:
* 33% faster release build
* slightly worse/same perf
* no changes for debug build
* slightly smaller binary
cc @flodiebold I genuinely don't know if it is a good idea or not.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/autoderef.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/display.rs | 50 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/expr.rs | 19 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer.rs | 38 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/coerce.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 23 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/pat.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/path.rs | 15 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/unify.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 36 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/lower.rs | 220 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 43 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/test_db.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/builtin.rs | 36 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 111 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/utils.rs | 16 |
18 files changed, 337 insertions, 346 deletions
diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs index f32d5786a..53e81e85d 100644 --- a/crates/ra_hir_ty/src/autoderef.rs +++ b/crates/ra_hir_ty/src/autoderef.rs | |||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | const AUTODEREF_RECURSION_LIMIT: usize = 10; | 20 | const AUTODEREF_RECURSION_LIMIT: usize = 10; |
21 | 21 | ||
22 | pub fn autoderef<'a>( | 22 | pub fn autoderef<'a>( |
23 | db: &'a impl HirDatabase, | 23 | db: &'a dyn HirDatabase, |
24 | krate: Option<CrateId>, | 24 | krate: Option<CrateId>, |
25 | ty: InEnvironment<Canonical<Ty>>, | 25 | ty: InEnvironment<Canonical<Ty>>, |
26 | ) -> impl Iterator<Item = Canonical<Ty>> + 'a { | 26 | ) -> impl Iterator<Item = Canonical<Ty>> + 'a { |
@@ -32,7 +32,7 @@ pub fn autoderef<'a>( | |||
32 | } | 32 | } |
33 | 33 | ||
34 | pub(crate) fn deref( | 34 | pub(crate) fn deref( |
35 | db: &impl HirDatabase, | 35 | db: &dyn HirDatabase, |
36 | krate: CrateId, | 36 | krate: CrateId, |
37 | ty: InEnvironment<&Canonical<Ty>>, | 37 | ty: InEnvironment<&Canonical<Ty>>, |
38 | ) -> Option<Canonical<Ty>> { | 38 | ) -> Option<Canonical<Ty>> { |
@@ -44,7 +44,7 @@ pub(crate) fn deref( | |||
44 | } | 44 | } |
45 | 45 | ||
46 | fn deref_by_trait( | 46 | fn deref_by_trait( |
47 | db: &impl HirDatabase, | 47 | db: &dyn HirDatabase, |
48 | krate: CrateId, | 48 | krate: CrateId, |
49 | ty: InEnvironment<&Canonical<Ty>>, | 49 | ty: InEnvironment<&Canonical<Ty>>, |
50 | ) -> Option<Canonical<Ty>> { | 50 | ) -> Option<Canonical<Ty>> { |
@@ -54,7 +54,7 @@ fn deref_by_trait( | |||
54 | }; | 54 | }; |
55 | let target = db.trait_data(deref_trait).associated_type_by_name(&name![Target])?; | 55 | let target = db.trait_data(deref_trait).associated_type_by_name(&name![Target])?; |
56 | 56 | ||
57 | let generic_params = generics(db, target.into()); | 57 | let generic_params = generics(db.upcast(), target.into()); |
58 | if generic_params.len() != 1 { | 58 | if generic_params.len() != 1 { |
59 | // the Target type + Deref trait should only have one generic parameter, | 59 | // the Target type + Deref trait should only have one generic parameter, |
60 | // namely Deref's Self type | 60 | // namely Deref's Self type |
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index 74b309005..11fc2ac3d 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs | |||
@@ -7,7 +7,7 @@ use hir_def::{ | |||
7 | VariantId, | 7 | VariantId, |
8 | }; | 8 | }; |
9 | use ra_arena::map::ArenaMap; | 9 | use ra_arena::map::ArenaMap; |
10 | use ra_db::{impl_intern_key, salsa, CrateId}; | 10 | use ra_db::{impl_intern_key, salsa, CrateId, Upcast}; |
11 | use ra_prof::profile; | 11 | use ra_prof::profile; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
@@ -20,7 +20,7 @@ use hir_expand::name::Name; | |||
20 | 20 | ||
21 | #[salsa::query_group(HirDatabaseStorage)] | 21 | #[salsa::query_group(HirDatabaseStorage)] |
22 | #[salsa::requires(salsa::Database)] | 22 | #[salsa::requires(salsa::Database)] |
23 | pub trait HirDatabase: DefDatabase { | 23 | pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> { |
24 | #[salsa::invoke(infer_wait)] | 24 | #[salsa::invoke(infer_wait)] |
25 | fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>; | 25 | fn infer(&self, def: DefWithBodyId) -> Arc<InferenceResult>; |
26 | 26 | ||
diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index 14e089cf4..a6ef44a31 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs | |||
@@ -9,8 +9,8 @@ use crate::{ | |||
9 | use hir_def::{generics::TypeParamProvenance, AdtId, AssocContainerId, Lookup}; | 9 | use hir_def::{generics::TypeParamProvenance, AdtId, AssocContainerId, Lookup}; |
10 | use hir_expand::name::Name; | 10 | use hir_expand::name::Name; |
11 | 11 | ||
12 | pub struct HirFormatter<'a, 'b, DB> { | 12 | pub struct HirFormatter<'a, 'b> { |
13 | pub db: &'a DB, | 13 | pub db: &'a dyn HirDatabase, |
14 | fmt: &'a mut fmt::Formatter<'b>, | 14 | fmt: &'a mut fmt::Formatter<'b>, |
15 | buf: String, | 15 | buf: String, |
16 | curr_size: usize, | 16 | curr_size: usize, |
@@ -19,20 +19,20 @@ pub struct HirFormatter<'a, 'b, DB> { | |||
19 | } | 19 | } |
20 | 20 | ||
21 | pub trait HirDisplay { | 21 | pub trait HirDisplay { |
22 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result; | 22 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result; |
23 | 23 | ||
24 | fn display<'a, DB>(&'a self, db: &'a DB) -> HirDisplayWrapper<'a, DB, Self> | 24 | fn display<'a>(&'a self, db: &'a dyn HirDatabase) -> HirDisplayWrapper<'a, Self> |
25 | where | 25 | where |
26 | Self: Sized, | 26 | Self: Sized, |
27 | { | 27 | { |
28 | HirDisplayWrapper(db, self, None, false) | 28 | HirDisplayWrapper(db, self, None, false) |
29 | } | 29 | } |
30 | 30 | ||
31 | fn display_truncated<'a, DB>( | 31 | fn display_truncated<'a>( |
32 | &'a self, | 32 | &'a self, |
33 | db: &'a DB, | 33 | db: &'a dyn HirDatabase, |
34 | max_size: Option<usize>, | 34 | max_size: Option<usize>, |
35 | ) -> HirDisplayWrapper<'a, DB, Self> | 35 | ) -> HirDisplayWrapper<'a, Self> |
36 | where | 36 | where |
37 | Self: Sized, | 37 | Self: Sized, |
38 | { | 38 | { |
@@ -40,10 +40,7 @@ pub trait HirDisplay { | |||
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | impl<'a, 'b, DB> HirFormatter<'a, 'b, DB> | 43 | impl<'a, 'b> HirFormatter<'a, 'b> { |
44 | where | ||
45 | DB: HirDatabase, | ||
46 | { | ||
47 | pub fn write_joined<T: HirDisplay>( | 44 | pub fn write_joined<T: HirDisplay>( |
48 | &mut self, | 45 | &mut self, |
49 | iter: impl IntoIterator<Item = T>, | 46 | iter: impl IntoIterator<Item = T>, |
@@ -84,11 +81,10 @@ where | |||
84 | } | 81 | } |
85 | } | 82 | } |
86 | 83 | ||
87 | pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option<usize>, bool); | 84 | pub struct HirDisplayWrapper<'a, T>(&'a dyn HirDatabase, &'a T, Option<usize>, bool); |
88 | 85 | ||
89 | impl<'a, DB, T> fmt::Display for HirDisplayWrapper<'a, DB, T> | 86 | impl<'a, T> fmt::Display for HirDisplayWrapper<'a, T> |
90 | where | 87 | where |
91 | DB: HirDatabase, | ||
92 | T: HirDisplay, | 88 | T: HirDisplay, |
93 | { | 89 | { |
94 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 90 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
@@ -106,13 +102,13 @@ where | |||
106 | const TYPE_HINT_TRUNCATION: &str = "…"; | 102 | const TYPE_HINT_TRUNCATION: &str = "…"; |
107 | 103 | ||
108 | impl HirDisplay for &Ty { | 104 | impl HirDisplay for &Ty { |
109 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 105 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { |
110 | HirDisplay::hir_fmt(*self, f) | 106 | HirDisplay::hir_fmt(*self, f) |
111 | } | 107 | } |
112 | } | 108 | } |
113 | 109 | ||
114 | impl HirDisplay for ApplicationTy { | 110 | impl HirDisplay for ApplicationTy { |
115 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 111 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { |
116 | if f.should_truncate() { | 112 | if f.should_truncate() { |
117 | return write!(f, "{}", TYPE_HINT_TRUNCATION); | 113 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
118 | } | 114 | } |
@@ -178,7 +174,7 @@ impl HirDisplay for ApplicationTy { | |||
178 | } | 174 | } |
179 | } | 175 | } |
180 | if self.parameters.len() > 0 { | 176 | if self.parameters.len() > 0 { |
181 | let generics = generics(f.db, def.into()); | 177 | let generics = generics(f.db.upcast(), def.into()); |
182 | let (parent_params, self_param, type_params, _impl_trait_params) = | 178 | let (parent_params, self_param, type_params, _impl_trait_params) = |
183 | generics.provenance_split(); | 179 | generics.provenance_split(); |
184 | let total_len = parent_params + self_param + type_params; | 180 | let total_len = parent_params + self_param + type_params; |
@@ -238,7 +234,7 @@ impl HirDisplay for ApplicationTy { | |||
238 | } | 234 | } |
239 | } | 235 | } |
240 | TypeCtor::AssociatedType(type_alias) => { | 236 | TypeCtor::AssociatedType(type_alias) => { |
241 | let trait_ = match type_alias.lookup(f.db).container { | 237 | let trait_ = match type_alias.lookup(f.db.upcast()).container { |
242 | AssocContainerId::TraitId(it) => it, | 238 | AssocContainerId::TraitId(it) => it, |
243 | _ => panic!("not an associated type"), | 239 | _ => panic!("not an associated type"), |
244 | }; | 240 | }; |
@@ -272,7 +268,7 @@ impl HirDisplay for ApplicationTy { | |||
272 | } | 268 | } |
273 | 269 | ||
274 | impl HirDisplay for ProjectionTy { | 270 | impl HirDisplay for ProjectionTy { |
275 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 271 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { |
276 | if f.should_truncate() { | 272 | if f.should_truncate() { |
277 | return write!(f, "{}", TYPE_HINT_TRUNCATION); | 273 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
278 | } | 274 | } |
@@ -290,7 +286,7 @@ impl HirDisplay for ProjectionTy { | |||
290 | } | 286 | } |
291 | 287 | ||
292 | impl HirDisplay for Ty { | 288 | impl HirDisplay for Ty { |
293 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 289 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { |
294 | if f.should_truncate() { | 290 | if f.should_truncate() { |
295 | return write!(f, "{}", TYPE_HINT_TRUNCATION); | 291 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
296 | } | 292 | } |
@@ -299,7 +295,7 @@ impl HirDisplay for Ty { | |||
299 | Ty::Apply(a_ty) => a_ty.hir_fmt(f)?, | 295 | Ty::Apply(a_ty) => a_ty.hir_fmt(f)?, |
300 | Ty::Projection(p_ty) => p_ty.hir_fmt(f)?, | 296 | Ty::Projection(p_ty) => p_ty.hir_fmt(f)?, |
301 | Ty::Placeholder(id) => { | 297 | Ty::Placeholder(id) => { |
302 | let generics = generics(f.db, id.parent); | 298 | let generics = generics(f.db.upcast(), id.parent); |
303 | let param_data = &generics.params.types[id.local_id]; | 299 | let param_data = &generics.params.types[id.local_id]; |
304 | match param_data.provenance { | 300 | match param_data.provenance { |
305 | TypeParamProvenance::TypeParamList | TypeParamProvenance::TraitSelf => { | 301 | TypeParamProvenance::TypeParamList | TypeParamProvenance::TraitSelf => { |
@@ -334,7 +330,7 @@ impl HirDisplay for Ty { | |||
334 | 330 | ||
335 | fn write_bounds_like_dyn_trait( | 331 | fn write_bounds_like_dyn_trait( |
336 | predicates: &[GenericPredicate], | 332 | predicates: &[GenericPredicate], |
337 | f: &mut HirFormatter<impl HirDatabase>, | 333 | f: &mut HirFormatter, |
338 | ) -> fmt::Result { | 334 | ) -> fmt::Result { |
339 | // Note: This code is written to produce nice results (i.e. | 335 | // Note: This code is written to produce nice results (i.e. |
340 | // corresponding to surface Rust) for types that can occur in | 336 | // corresponding to surface Rust) for types that can occur in |
@@ -398,7 +394,7 @@ fn write_bounds_like_dyn_trait( | |||
398 | } | 394 | } |
399 | 395 | ||
400 | impl TraitRef { | 396 | impl TraitRef { |
401 | fn hir_fmt_ext(&self, f: &mut HirFormatter<impl HirDatabase>, use_as: bool) -> fmt::Result { | 397 | fn hir_fmt_ext(&self, f: &mut HirFormatter, use_as: bool) -> fmt::Result { |
402 | if f.should_truncate() { | 398 | if f.should_truncate() { |
403 | return write!(f, "{}", TYPE_HINT_TRUNCATION); | 399 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
404 | } | 400 | } |
@@ -420,19 +416,19 @@ impl TraitRef { | |||
420 | } | 416 | } |
421 | 417 | ||
422 | impl HirDisplay for TraitRef { | 418 | impl HirDisplay for TraitRef { |
423 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 419 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { |
424 | self.hir_fmt_ext(f, false) | 420 | self.hir_fmt_ext(f, false) |
425 | } | 421 | } |
426 | } | 422 | } |
427 | 423 | ||
428 | impl HirDisplay for &GenericPredicate { | 424 | impl HirDisplay for &GenericPredicate { |
429 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 425 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { |
430 | HirDisplay::hir_fmt(*self, f) | 426 | HirDisplay::hir_fmt(*self, f) |
431 | } | 427 | } |
432 | } | 428 | } |
433 | 429 | ||
434 | impl HirDisplay for GenericPredicate { | 430 | impl HirDisplay for GenericPredicate { |
435 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 431 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { |
436 | if f.should_truncate() { | 432 | if f.should_truncate() { |
437 | return write!(f, "{}", TYPE_HINT_TRUNCATION); | 433 | return write!(f, "{}", TYPE_HINT_TRUNCATION); |
438 | } | 434 | } |
@@ -456,7 +452,7 @@ impl HirDisplay for GenericPredicate { | |||
456 | } | 452 | } |
457 | 453 | ||
458 | impl HirDisplay for Obligation { | 454 | impl HirDisplay for Obligation { |
459 | fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { | 455 | fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { |
460 | match self { | 456 | match self { |
461 | Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db)), | 457 | Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db)), |
462 | Obligation::Projection(proj) => write!( | 458 | Obligation::Projection(proj) => write!( |
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index d8cdf5266..b7b476b4c 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs | |||
@@ -46,7 +46,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
46 | ExprValidator { func, infer, sink } | 46 | ExprValidator { func, infer, sink } |
47 | } | 47 | } |
48 | 48 | ||
49 | pub fn validate_body(&mut self, db: &impl HirDatabase) { | 49 | pub fn validate_body(&mut self, db: &dyn HirDatabase) { |
50 | let body = db.body(self.func.into()); | 50 | let body = db.body(self.func.into()); |
51 | 51 | ||
52 | for e in body.exprs.iter() { | 52 | for e in body.exprs.iter() { |
@@ -67,7 +67,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
67 | _path: &Option<Path>, | 67 | _path: &Option<Path>, |
68 | fields: &[RecordLitField], | 68 | fields: &[RecordLitField], |
69 | spread: Option<ExprId>, | 69 | spread: Option<ExprId>, |
70 | db: &impl HirDatabase, | 70 | db: &dyn HirDatabase, |
71 | ) { | 71 | ) { |
72 | if spread.is_some() { | 72 | if spread.is_some() { |
73 | return; | 73 | return; |
@@ -80,7 +80,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | 82 | ||
83 | let variant_data = variant_data(db, variant_def); | 83 | let variant_data = variant_data(db.upcast(), variant_def); |
84 | 84 | ||
85 | let lit_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); | 85 | let lit_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); |
86 | let missed_fields: Vec<Name> = variant_data | 86 | let missed_fields: Vec<Name> = variant_data |
@@ -102,7 +102,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
102 | 102 | ||
103 | if let Ok(source_ptr) = source_map.expr_syntax(id) { | 103 | if let Ok(source_ptr) = source_map.expr_syntax(id) { |
104 | if let Some(expr) = source_ptr.value.left() { | 104 | if let Some(expr) = source_ptr.value.left() { |
105 | let root = source_ptr.file_syntax(db); | 105 | let root = source_ptr.file_syntax(db.upcast()); |
106 | if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { | 106 | if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { |
107 | if let Some(field_list) = record_lit.record_field_list() { | 107 | if let Some(field_list) = record_lit.record_field_list() { |
108 | self.sink.push(MissingFields { | 108 | self.sink.push(MissingFields { |
@@ -116,12 +116,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | fn validate_results_in_tail_expr( | 119 | fn validate_results_in_tail_expr(&mut self, body_id: ExprId, id: ExprId, db: &dyn HirDatabase) { |
120 | &mut self, | ||
121 | body_id: ExprId, | ||
122 | id: ExprId, | ||
123 | db: &impl HirDatabase, | ||
124 | ) { | ||
125 | // the mismatch will be on the whole block currently | 120 | // the mismatch will be on the whole block currently |
126 | let mismatch = match self.infer.type_mismatch_for_expr(body_id) { | 121 | let mismatch = match self.infer.type_mismatch_for_expr(body_id) { |
127 | Some(m) => m, | 122 | Some(m) => m, |
@@ -130,8 +125,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> { | |||
130 | 125 | ||
131 | let std_result_path = path![std::result::Result]; | 126 | let std_result_path = path![std::result::Result]; |
132 | 127 | ||
133 | let resolver = self.func.resolver(db); | 128 | let resolver = self.func.resolver(db.upcast()); |
134 | let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) { | 129 | let std_result_enum = match resolver.resolve_known_enum(db.upcast(), &std_result_path) { |
135 | Some(it) => it, | 130 | Some(it) => it, |
136 | _ => return, | 131 | _ => return, |
137 | }; | 132 | }; |
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 947833412..246b0e9be 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -63,9 +63,9 @@ mod pat; | |||
63 | mod coerce; | 63 | mod coerce; |
64 | 64 | ||
65 | /// The entry point of type inference. | 65 | /// The entry point of type inference. |
66 | pub(crate) fn infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { | 66 | pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> { |
67 | let _p = profile("infer_query"); | 67 | let _p = profile("infer_query"); |
68 | let resolver = def.resolver(db); | 68 | let resolver = def.resolver(db.upcast()); |
69 | let mut ctx = InferenceContext::new(db, def, resolver); | 69 | let mut ctx = InferenceContext::new(db, def, resolver); |
70 | 70 | ||
71 | match def { | 71 | match def { |
@@ -164,7 +164,7 @@ impl InferenceResult { | |||
164 | } | 164 | } |
165 | pub fn add_diagnostics( | 165 | pub fn add_diagnostics( |
166 | &self, | 166 | &self, |
167 | db: &impl HirDatabase, | 167 | db: &dyn HirDatabase, |
168 | owner: FunctionId, | 168 | owner: FunctionId, |
169 | sink: &mut DiagnosticSink, | 169 | sink: &mut DiagnosticSink, |
170 | ) { | 170 | ) { |
@@ -190,8 +190,8 @@ impl Index<PatId> for InferenceResult { | |||
190 | 190 | ||
191 | /// The inference context contains all information needed during type inference. | 191 | /// The inference context contains all information needed during type inference. |
192 | #[derive(Clone, Debug)] | 192 | #[derive(Clone, Debug)] |
193 | struct InferenceContext<'a, D: HirDatabase> { | 193 | struct InferenceContext<'a> { |
194 | db: &'a D, | 194 | db: &'a dyn HirDatabase, |
195 | owner: DefWithBodyId, | 195 | owner: DefWithBodyId, |
196 | body: Arc<Body>, | 196 | body: Arc<Body>, |
197 | resolver: Resolver, | 197 | resolver: Resolver, |
@@ -208,8 +208,8 @@ struct InferenceContext<'a, D: HirDatabase> { | |||
208 | return_ty: Ty, | 208 | return_ty: Ty, |
209 | } | 209 | } |
210 | 210 | ||
211 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 211 | impl<'a> InferenceContext<'a> { |
212 | fn new(db: &'a D, owner: DefWithBodyId, resolver: Resolver) -> Self { | 212 | fn new(db: &'a dyn HirDatabase, owner: DefWithBodyId, resolver: Resolver) -> Self { |
213 | InferenceContext { | 213 | InferenceContext { |
214 | result: InferenceResult::default(), | 214 | result: InferenceResult::default(), |
215 | table: unify::InferenceTable::new(), | 215 | table: unify::InferenceTable::new(), |
@@ -425,7 +425,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
425 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); | 425 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); |
426 | // FIXME: this should resolve assoc items as well, see this example: | 426 | // FIXME: this should resolve assoc items as well, see this example: |
427 | // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 | 427 | // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 |
428 | return match resolver.resolve_path_in_type_ns_fully(self.db, path.mod_path()) { | 428 | return match resolver.resolve_path_in_type_ns_fully(self.db.upcast(), path.mod_path()) { |
429 | Some(TypeNs::AdtId(AdtId::StructId(strukt))) => { | 429 | Some(TypeNs::AdtId(AdtId::StructId(strukt))) => { |
430 | let substs = Ty::substs_from_path(&ctx, path, strukt.into()); | 430 | let substs = Ty::substs_from_path(&ctx, path, strukt.into()); |
431 | let ty = self.db.ty(strukt.into()); | 431 | let ty = self.db.ty(strukt.into()); |
@@ -439,7 +439,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
439 | (ty, Some(var.into())) | 439 | (ty, Some(var.into())) |
440 | } | 440 | } |
441 | Some(TypeNs::SelfType(impl_id)) => { | 441 | Some(TypeNs::SelfType(impl_id)) => { |
442 | let generics = crate::utils::generics(self.db, impl_id.into()); | 442 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); |
443 | let substs = Substs::type_params_for_generics(&generics); | 443 | let substs = Substs::type_params_for_generics(&generics); |
444 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); | 444 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); |
445 | let variant = ty_variant(&ty); | 445 | let variant = ty_variant(&ty); |
@@ -500,13 +500,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
500 | 500 | ||
501 | fn resolve_into_iter_item(&self) -> Option<TypeAliasId> { | 501 | fn resolve_into_iter_item(&self) -> Option<TypeAliasId> { |
502 | let path = path![std::iter::IntoIterator]; | 502 | let path = path![std::iter::IntoIterator]; |
503 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 503 | let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?; |
504 | self.db.trait_data(trait_).associated_type_by_name(&name![Item]) | 504 | self.db.trait_data(trait_).associated_type_by_name(&name![Item]) |
505 | } | 505 | } |
506 | 506 | ||
507 | fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> { | 507 | fn resolve_ops_try_ok(&self) -> Option<TypeAliasId> { |
508 | let path = path![std::ops::Try]; | 508 | let path = path![std::ops::Try]; |
509 | let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; | 509 | let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?; |
510 | self.db.trait_data(trait_).associated_type_by_name(&name![Ok]) | 510 | self.db.trait_data(trait_).associated_type_by_name(&name![Ok]) |
511 | } | 511 | } |
512 | 512 | ||
@@ -532,37 +532,37 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
532 | 532 | ||
533 | fn resolve_range_full(&self) -> Option<AdtId> { | 533 | fn resolve_range_full(&self) -> Option<AdtId> { |
534 | let path = path![std::ops::RangeFull]; | 534 | let path = path![std::ops::RangeFull]; |
535 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 535 | let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; |
536 | Some(struct_.into()) | 536 | Some(struct_.into()) |
537 | } | 537 | } |
538 | 538 | ||
539 | fn resolve_range(&self) -> Option<AdtId> { | 539 | fn resolve_range(&self) -> Option<AdtId> { |
540 | let path = path![std::ops::Range]; | 540 | let path = path![std::ops::Range]; |
541 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 541 | let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; |
542 | Some(struct_.into()) | 542 | Some(struct_.into()) |
543 | } | 543 | } |
544 | 544 | ||
545 | fn resolve_range_inclusive(&self) -> Option<AdtId> { | 545 | fn resolve_range_inclusive(&self) -> Option<AdtId> { |
546 | let path = path![std::ops::RangeInclusive]; | 546 | let path = path![std::ops::RangeInclusive]; |
547 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 547 | let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; |
548 | Some(struct_.into()) | 548 | Some(struct_.into()) |
549 | } | 549 | } |
550 | 550 | ||
551 | fn resolve_range_from(&self) -> Option<AdtId> { | 551 | fn resolve_range_from(&self) -> Option<AdtId> { |
552 | let path = path![std::ops::RangeFrom]; | 552 | let path = path![std::ops::RangeFrom]; |
553 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 553 | let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; |
554 | Some(struct_.into()) | 554 | Some(struct_.into()) |
555 | } | 555 | } |
556 | 556 | ||
557 | fn resolve_range_to(&self) -> Option<AdtId> { | 557 | fn resolve_range_to(&self) -> Option<AdtId> { |
558 | let path = path![std::ops::RangeTo]; | 558 | let path = path![std::ops::RangeTo]; |
559 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 559 | let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; |
560 | Some(struct_.into()) | 560 | Some(struct_.into()) |
561 | } | 561 | } |
562 | 562 | ||
563 | fn resolve_range_to_inclusive(&self) -> Option<AdtId> { | 563 | fn resolve_range_to_inclusive(&self) -> Option<AdtId> { |
564 | let path = path![std::ops::RangeToInclusive]; | 564 | let path = path![std::ops::RangeToInclusive]; |
565 | let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; | 565 | let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; |
566 | Some(struct_.into()) | 566 | Some(struct_.into()) |
567 | } | 567 | } |
568 | 568 | ||
@@ -676,13 +676,13 @@ mod diagnostics { | |||
676 | impl InferenceDiagnostic { | 676 | impl InferenceDiagnostic { |
677 | pub(super) fn add_to( | 677 | pub(super) fn add_to( |
678 | &self, | 678 | &self, |
679 | db: &impl HirDatabase, | 679 | db: &dyn HirDatabase, |
680 | owner: FunctionId, | 680 | owner: FunctionId, |
681 | sink: &mut DiagnosticSink, | 681 | sink: &mut DiagnosticSink, |
682 | ) { | 682 | ) { |
683 | match self { | 683 | match self { |
684 | InferenceDiagnostic::NoSuchField { expr, field } => { | 684 | InferenceDiagnostic::NoSuchField { expr, field } => { |
685 | let file = owner.lookup(db).source(db).file_id; | 685 | let file = owner.lookup(db.upcast()).source(db.upcast()).file_id; |
686 | let (_, source_map) = db.body_with_source_map(owner.into()); | 686 | let (_, source_map) = db.body_with_source_map(owner.into()); |
687 | let field = source_map.field_syntax(*expr, *field); | 687 | let field = source_map.field_syntax(*expr, *field); |
688 | sink.push(NoSuchField { file, field }) | 688 | sink.push(NoSuchField { file, field }) |
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index 95ac3c713..959b1e212 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs | |||
@@ -7,13 +7,11 @@ | |||
7 | use hir_def::{lang_item::LangItemTarget, type_ref::Mutability}; | 7 | use hir_def::{lang_item::LangItemTarget, type_ref::Mutability}; |
8 | use test_utils::tested_by; | 8 | use test_utils::tested_by; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{autoderef, traits::Solution, Obligation, Substs, TraitRef, Ty, TypeCtor}; |
11 | autoderef, db::HirDatabase, traits::Solution, Obligation, Substs, TraitRef, Ty, TypeCtor, | ||
12 | }; | ||
13 | 11 | ||
14 | use super::{unify::TypeVarValue, InEnvironment, InferTy, InferenceContext}; | 12 | use super::{unify::TypeVarValue, InEnvironment, InferTy, InferenceContext}; |
15 | 13 | ||
16 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 14 | impl<'a> InferenceContext<'a> { |
17 | /// Unify two types, but may coerce the first one to the second one | 15 | /// Unify two types, but may coerce the first one to the second one |
18 | /// using "implicit coercion rules" if needed. | 16 | /// using "implicit coercion rules" if needed. |
19 | pub(super) fn coerce(&mut self, from_ty: &Ty, to_ty: &Ty) -> bool { | 17 | pub(super) fn coerce(&mut self, from_ty: &Ty, to_ty: &Ty) -> bool { |
@@ -126,7 +124,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
126 | _ => return None, | 124 | _ => return None, |
127 | }; | 125 | }; |
128 | 126 | ||
129 | let generic_params = crate::utils::generics(self.db, coerce_unsized_trait.into()); | 127 | let generic_params = crate::utils::generics(self.db.upcast(), coerce_unsized_trait.into()); |
130 | if generic_params.len() != 2 { | 128 | if generic_params.len() != 2 { |
131 | // The CoerceUnsized trait should have two generic params: Self and T. | 129 | // The CoerceUnsized trait should have two generic params: Self and T. |
132 | return None; | 130 | return None; |
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index e89cc7298..1fdb235a0 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -14,9 +14,7 @@ use hir_expand::name::Name; | |||
14 | use ra_syntax::ast::RangeOp; | 14 | use ra_syntax::ast::RangeOp; |
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
17 | autoderef, | 17 | autoderef, method_resolution, op, |
18 | db::HirDatabase, | ||
19 | method_resolution, op, | ||
20 | traits::InEnvironment, | 18 | traits::InEnvironment, |
21 | utils::{generics, variant_data, Generics}, | 19 | utils::{generics, variant_data, Generics}, |
22 | ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, | 20 | ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, |
@@ -25,7 +23,7 @@ use crate::{ | |||
25 | 23 | ||
26 | use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; | 24 | use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; |
27 | 25 | ||
28 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 26 | impl<'a> InferenceContext<'a> { |
29 | pub(super) fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { | 27 | pub(super) fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { |
30 | let ty = self.infer_expr_inner(tgt_expr, expected); | 28 | let ty = self.infer_expr_inner(tgt_expr, expected); |
31 | let could_unify = self.unify(&ty, &expected.ty); | 29 | let could_unify = self.unify(&ty, &expected.ty); |
@@ -184,7 +182,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
184 | } | 182 | } |
185 | Expr::Path(p) => { | 183 | Expr::Path(p) => { |
186 | // FIXME this could be more efficient... | 184 | // FIXME this could be more efficient... |
187 | let resolver = resolver_for_expr(self.db, self.owner, tgt_expr); | 185 | let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr); |
188 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) | 186 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) |
189 | } | 187 | } |
190 | Expr::Continue => Ty::simple(TypeCtor::Never), | 188 | Expr::Continue => Ty::simple(TypeCtor::Never), |
@@ -214,7 +212,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
214 | 212 | ||
215 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 213 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
216 | let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); | 214 | let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); |
217 | let variant_data = def_id.map(|it| variant_data(self.db, it)); | 215 | let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it)); |
218 | for (field_idx, field) in fields.iter().enumerate() { | 216 | for (field_idx, field) in fields.iter().enumerate() { |
219 | let field_def = | 217 | let field_def = |
220 | variant_data.as_ref().and_then(|it| match it.field(&field.name) { | 218 | variant_data.as_ref().and_then(|it| match it.field(&field.name) { |
@@ -579,7 +577,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
579 | let receiver_ty = self.infer_expr(receiver, &Expectation::none()); | 577 | let receiver_ty = self.infer_expr(receiver, &Expectation::none()); |
580 | let canonicalized_receiver = self.canonicalizer().canonicalize_ty(receiver_ty.clone()); | 578 | let canonicalized_receiver = self.canonicalizer().canonicalize_ty(receiver_ty.clone()); |
581 | 579 | ||
582 | let traits_in_scope = self.resolver.traits_in_scope(self.db); | 580 | let traits_in_scope = self.resolver.traits_in_scope(self.db.upcast()); |
583 | 581 | ||
584 | let resolved = self.resolver.krate().and_then(|krate| { | 582 | let resolved = self.resolver.krate().and_then(|krate| { |
585 | method_resolution::lookup_method( | 583 | method_resolution::lookup_method( |
@@ -595,7 +593,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
595 | Some((ty, func)) => { | 593 | Some((ty, func)) => { |
596 | let ty = canonicalized_receiver.decanonicalize_ty(ty); | 594 | let ty = canonicalized_receiver.decanonicalize_ty(ty); |
597 | self.write_method_resolution(tgt_expr, func); | 595 | self.write_method_resolution(tgt_expr, func); |
598 | (ty, self.db.value_ty(func.into()), Some(generics(self.db, func.into()))) | 596 | (ty, self.db.value_ty(func.into()), Some(generics(self.db.upcast(), func.into()))) |
599 | } | 597 | } |
600 | None => (receiver_ty, Binders::new(0, Ty::Unknown), None), | 598 | None => (receiver_ty, Binders::new(0, Ty::Unknown), None), |
601 | }; | 599 | }; |
@@ -703,10 +701,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
703 | // add obligation for trait implementation, if this is a trait method | 701 | // add obligation for trait implementation, if this is a trait method |
704 | match def { | 702 | match def { |
705 | CallableDef::FunctionId(f) => { | 703 | CallableDef::FunctionId(f) => { |
706 | if let AssocContainerId::TraitId(trait_) = f.lookup(self.db).container { | 704 | if let AssocContainerId::TraitId(trait_) = |
705 | f.lookup(self.db.upcast()).container | ||
706 | { | ||
707 | // construct a TraitDef | 707 | // construct a TraitDef |
708 | let substs = | 708 | let substs = a_ty |
709 | a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); | 709 | .parameters |
710 | .prefix(generics(self.db.upcast(), trait_.into()).len()); | ||
710 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); | 711 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); |
711 | } | 712 | } |
712 | } | 713 | } |
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index 7a84e47f8..baed6225b 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs | |||
@@ -12,9 +12,9 @@ use hir_expand::name::Name; | |||
12 | use test_utils::tested_by; | 12 | use test_utils::tested_by; |
13 | 13 | ||
14 | use super::{BindingMode, InferenceContext}; | 14 | use super::{BindingMode, InferenceContext}; |
15 | use crate::{db::HirDatabase, utils::variant_data, Substs, Ty, TypeCtor}; | 15 | use crate::{utils::variant_data, Substs, Ty, TypeCtor}; |
16 | 16 | ||
17 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 17 | impl<'a> InferenceContext<'a> { |
18 | fn infer_tuple_struct_pat( | 18 | fn infer_tuple_struct_pat( |
19 | &mut self, | 19 | &mut self, |
20 | path: Option<&Path>, | 20 | path: Option<&Path>, |
@@ -23,7 +23,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
23 | default_bm: BindingMode, | 23 | default_bm: BindingMode, |
24 | ) -> Ty { | 24 | ) -> Ty { |
25 | let (ty, def) = self.resolve_variant(path); | 25 | let (ty, def) = self.resolve_variant(path); |
26 | let var_data = def.map(|it| variant_data(self.db, it)); | 26 | let var_data = def.map(|it| variant_data(self.db.upcast(), it)); |
27 | self.unify(&ty, expected); | 27 | self.unify(&ty, expected); |
28 | 28 | ||
29 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 29 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
@@ -51,7 +51,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
51 | id: PatId, | 51 | id: PatId, |
52 | ) -> Ty { | 52 | ) -> Ty { |
53 | let (ty, def) = self.resolve_variant(path); | 53 | let (ty, def) = self.resolve_variant(path); |
54 | let var_data = def.map(|it| variant_data(self.db, it)); | 54 | let var_data = def.map(|it| variant_data(self.db.upcast(), it)); |
55 | if let Some(variant) = def { | 55 | if let Some(variant) = def { |
56 | self.write_variant_resolution(id.into(), variant); | 56 | self.write_variant_resolution(id.into(), variant); |
57 | } | 57 | } |
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index c733b9e1d..318652c61 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs | |||
@@ -9,11 +9,11 @@ use hir_def::{ | |||
9 | }; | 9 | }; |
10 | use hir_expand::name::Name; | 10 | use hir_expand::name::Name; |
11 | 11 | ||
12 | use crate::{db::HirDatabase, method_resolution, Substs, Ty, ValueTyDefId}; | 12 | use crate::{method_resolution, Substs, Ty, ValueTyDefId}; |
13 | 13 | ||
14 | use super::{ExprOrPatId, InferenceContext, TraitRef}; | 14 | use super::{ExprOrPatId, InferenceContext, TraitRef}; |
15 | 15 | ||
16 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 16 | impl<'a> InferenceContext<'a> { |
17 | pub(super) fn infer_path( | 17 | pub(super) fn infer_path( |
18 | &mut self, | 18 | &mut self, |
19 | resolver: &Resolver, | 19 | resolver: &Resolver, |
@@ -47,7 +47,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
47 | id, | 47 | id, |
48 | )? | 48 | )? |
49 | } else { | 49 | } else { |
50 | let value_or_partial = resolver.resolve_path_in_value_ns(self.db, path.mod_path())?; | 50 | let value_or_partial = |
51 | resolver.resolve_path_in_value_ns(self.db.upcast(), path.mod_path())?; | ||
51 | 52 | ||
52 | match value_or_partial { | 53 | match value_or_partial { |
53 | ResolveValueResult::ValueNs(it) => (it, None), | 54 | ResolveValueResult::ValueNs(it) => (it, None), |
@@ -192,7 +193,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
192 | 193 | ||
193 | let canonical_ty = self.canonicalizer().canonicalize_ty(ty.clone()); | 194 | let canonical_ty = self.canonicalizer().canonicalize_ty(ty.clone()); |
194 | let krate = self.resolver.krate()?; | 195 | let krate = self.resolver.krate()?; |
195 | let traits_in_scope = self.resolver.traits_in_scope(self.db); | 196 | let traits_in_scope = self.resolver.traits_in_scope(self.db.upcast()); |
196 | 197 | ||
197 | method_resolution::iterate_method_candidates( | 198 | method_resolution::iterate_method_candidates( |
198 | &canonical_ty.value, | 199 | &canonical_ty.value, |
@@ -205,9 +206,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
205 | move |_ty, item| { | 206 | move |_ty, item| { |
206 | let (def, container) = match item { | 207 | let (def, container) = match item { |
207 | AssocItemId::FunctionId(f) => { | 208 | AssocItemId::FunctionId(f) => { |
208 | (ValueNs::FunctionId(f), f.lookup(self.db).container) | 209 | (ValueNs::FunctionId(f), f.lookup(self.db.upcast()).container) |
210 | } | ||
211 | AssocItemId::ConstId(c) => { | ||
212 | (ValueNs::ConstId(c), c.lookup(self.db.upcast()).container) | ||
209 | } | 213 | } |
210 | AssocItemId::ConstId(c) => (ValueNs::ConstId(c), c.lookup(self.db).container), | ||
211 | AssocItemId::TypeAliasId(_) => unreachable!(), | 214 | AssocItemId::TypeAliasId(_) => unreachable!(), |
212 | }; | 215 | }; |
213 | let substs = match container { | 216 | let substs = match container { |
diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/ra_hir_ty/src/infer/unify.rs index 82b85d570..0bf8fbd63 100644 --- a/crates/ra_hir_ty/src/infer/unify.rs +++ b/crates/ra_hir_ty/src/infer/unify.rs | |||
@@ -7,10 +7,10 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; | |||
7 | use test_utils::tested_by; | 7 | use test_utils::tested_by; |
8 | 8 | ||
9 | use super::{InferenceContext, Obligation}; | 9 | use super::{InferenceContext, Obligation}; |
10 | use crate::{db::HirDatabase, Canonical, InEnvironment, InferTy, Substs, Ty, TypeCtor, TypeWalk}; | 10 | use crate::{Canonical, InEnvironment, InferTy, Substs, Ty, TypeCtor, TypeWalk}; |
11 | 11 | ||
12 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 12 | impl<'a> InferenceContext<'a> { |
13 | pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D> | 13 | pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b> |
14 | where | 14 | where |
15 | 'a: 'b, | 15 | 'a: 'b, |
16 | { | 16 | { |
@@ -18,11 +18,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
18 | } | 18 | } |
19 | } | 19 | } |
20 | 20 | ||
21 | pub(super) struct Canonicalizer<'a, 'b, D: HirDatabase> | 21 | pub(super) struct Canonicalizer<'a, 'b> |
22 | where | 22 | where |
23 | 'a: 'b, | 23 | 'a: 'b, |
24 | { | 24 | { |
25 | ctx: &'b mut InferenceContext<'a, D>, | 25 | ctx: &'b mut InferenceContext<'a>, |
26 | free_vars: Vec<InferTy>, | 26 | free_vars: Vec<InferTy>, |
27 | /// A stack of type variables that is used to detect recursive types (which | 27 | /// A stack of type variables that is used to detect recursive types (which |
28 | /// are an error, but we need to protect against them to avoid stack | 28 | /// are an error, but we need to protect against them to avoid stack |
@@ -35,7 +35,7 @@ pub(super) struct Canonicalized<T> { | |||
35 | free_vars: Vec<InferTy>, | 35 | free_vars: Vec<InferTy>, |
36 | } | 36 | } |
37 | 37 | ||
38 | impl<'a, 'b, D: HirDatabase> Canonicalizer<'a, 'b, D> | 38 | impl<'a, 'b> Canonicalizer<'a, 'b> |
39 | where | 39 | where |
40 | 'a: 'b, | 40 | 'a: 'b, |
41 | { | 41 | { |
@@ -123,11 +123,7 @@ impl<T> Canonicalized<T> { | |||
123 | ty | 123 | ty |
124 | } | 124 | } |
125 | 125 | ||
126 | pub fn apply_solution( | 126 | pub fn apply_solution(&self, ctx: &mut InferenceContext<'_>, solution: Canonical<Vec<Ty>>) { |
127 | &self, | ||
128 | ctx: &mut InferenceContext<'_, impl HirDatabase>, | ||
129 | solution: Canonical<Vec<Ty>>, | ||
130 | ) { | ||
131 | // the solution may contain new variables, which we need to convert to new inference vars | 127 | // the solution may contain new variables, which we need to convert to new inference vars |
132 | let new_vars = Substs((0..solution.num_vars).map(|_| ctx.table.new_type_var()).collect()); | 128 | let new_vars = Substs((0..solution.num_vars).map(|_| ctx.table.new_type_var()).collect()); |
133 | for (i, ty) in solution.value.into_iter().enumerate() { | 129 | for (i, ty) in solution.value.into_iter().enumerate() { |
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 4127f1a8d..6c5469ecd 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -152,7 +152,7 @@ pub struct TypeCtorId(salsa::InternId); | |||
152 | impl_intern_key!(TypeCtorId); | 152 | impl_intern_key!(TypeCtorId); |
153 | 153 | ||
154 | impl TypeCtor { | 154 | impl TypeCtor { |
155 | pub fn num_ty_params(self, db: &impl HirDatabase) -> usize { | 155 | pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize { |
156 | match self { | 156 | match self { |
157 | TypeCtor::Bool | 157 | TypeCtor::Bool |
158 | | TypeCtor::Char | 158 | | TypeCtor::Char |
@@ -167,15 +167,15 @@ impl TypeCtor { | |||
167 | | TypeCtor::Closure { .. } // 1 param representing the signature of the closure | 167 | | TypeCtor::Closure { .. } // 1 param representing the signature of the closure |
168 | => 1, | 168 | => 1, |
169 | TypeCtor::Adt(adt) => { | 169 | TypeCtor::Adt(adt) => { |
170 | let generic_params = generics(db, adt.into()); | 170 | let generic_params = generics(db.upcast(), adt.into()); |
171 | generic_params.len() | 171 | generic_params.len() |
172 | } | 172 | } |
173 | TypeCtor::FnDef(callable) => { | 173 | TypeCtor::FnDef(callable) => { |
174 | let generic_params = generics(db, callable.into()); | 174 | let generic_params = generics(db.upcast(), callable.into()); |
175 | generic_params.len() | 175 | generic_params.len() |
176 | } | 176 | } |
177 | TypeCtor::AssociatedType(type_alias) => { | 177 | TypeCtor::AssociatedType(type_alias) => { |
178 | let generic_params = generics(db, type_alias.into()); | 178 | let generic_params = generics(db.upcast(), type_alias.into()); |
179 | generic_params.len() | 179 | generic_params.len() |
180 | } | 180 | } |
181 | TypeCtor::FnPtr { num_args } => num_args as usize + 1, | 181 | TypeCtor::FnPtr { num_args } => num_args as usize + 1, |
@@ -183,7 +183,7 @@ impl TypeCtor { | |||
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | pub fn krate(self, db: &impl HirDatabase) -> Option<CrateId> { | 186 | pub fn krate(self, db: &dyn HirDatabase) -> Option<CrateId> { |
187 | match self { | 187 | match self { |
188 | TypeCtor::Bool | 188 | TypeCtor::Bool |
189 | | TypeCtor::Char | 189 | | TypeCtor::Char |
@@ -199,9 +199,11 @@ impl TypeCtor { | |||
199 | | TypeCtor::Tuple { .. } => None, | 199 | | TypeCtor::Tuple { .. } => None, |
200 | // Closure's krate is irrelevant for coherence I would think? | 200 | // Closure's krate is irrelevant for coherence I would think? |
201 | TypeCtor::Closure { .. } => None, | 201 | TypeCtor::Closure { .. } => None, |
202 | TypeCtor::Adt(adt) => Some(adt.module(db).krate), | 202 | TypeCtor::Adt(adt) => Some(adt.module(db.upcast()).krate), |
203 | TypeCtor::FnDef(callable) => Some(callable.krate(db)), | 203 | TypeCtor::FnDef(callable) => Some(callable.krate(db)), |
204 | TypeCtor::AssociatedType(type_alias) => Some(type_alias.lookup(db).module(db).krate), | 204 | TypeCtor::AssociatedType(type_alias) => { |
205 | Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate) | ||
206 | } | ||
205 | } | 207 | } |
206 | } | 208 | } |
207 | 209 | ||
@@ -246,12 +248,12 @@ pub struct ProjectionTy { | |||
246 | } | 248 | } |
247 | 249 | ||
248 | impl ProjectionTy { | 250 | impl ProjectionTy { |
249 | pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { | 251 | pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef { |
250 | TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } | 252 | TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } |
251 | } | 253 | } |
252 | 254 | ||
253 | fn trait_(&self, db: &impl HirDatabase) -> TraitId { | 255 | fn trait_(&self, db: &dyn HirDatabase) -> TraitId { |
254 | match self.associated_ty.lookup(db).container { | 256 | match self.associated_ty.lookup(db.upcast()).container { |
255 | AssocContainerId::TraitId(it) => it, | 257 | AssocContainerId::TraitId(it) => it, |
256 | _ => panic!("projection ty without parent trait"), | 258 | _ => panic!("projection ty without parent trait"), |
257 | } | 259 | } |
@@ -372,8 +374,8 @@ impl Substs { | |||
372 | } | 374 | } |
373 | 375 | ||
374 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). | 376 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). |
375 | pub fn type_params(db: &impl HirDatabase, def: impl Into<GenericDefId>) -> Substs { | 377 | pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substs { |
376 | let params = generics(db, def.into()); | 378 | let params = generics(db.upcast(), def.into()); |
377 | Substs::type_params_for_generics(¶ms) | 379 | Substs::type_params_for_generics(¶ms) |
378 | } | 380 | } |
379 | 381 | ||
@@ -382,9 +384,9 @@ impl Substs { | |||
382 | Substs(generic_params.iter().enumerate().map(|(idx, _)| Ty::Bound(idx as u32)).collect()) | 384 | Substs(generic_params.iter().enumerate().map(|(idx, _)| Ty::Bound(idx as u32)).collect()) |
383 | } | 385 | } |
384 | 386 | ||
385 | pub fn build_for_def(db: &impl HirDatabase, def: impl Into<GenericDefId>) -> SubstsBuilder { | 387 | pub fn build_for_def(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> SubstsBuilder { |
386 | let def = def.into(); | 388 | let def = def.into(); |
387 | let params = generics(db, def); | 389 | let params = generics(db.upcast(), def); |
388 | let param_count = params.len(); | 390 | let param_count = params.len(); |
389 | Substs::builder(param_count) | 391 | Substs::builder(param_count) |
390 | } | 392 | } |
@@ -393,7 +395,7 @@ impl Substs { | |||
393 | Substs::builder(generic_params.len()) | 395 | Substs::builder(generic_params.len()) |
394 | } | 396 | } |
395 | 397 | ||
396 | pub fn build_for_type_ctor(db: &impl HirDatabase, type_ctor: TypeCtor) -> SubstsBuilder { | 398 | pub fn build_for_type_ctor(db: &dyn HirDatabase, type_ctor: TypeCtor) -> SubstsBuilder { |
397 | Substs::builder(type_ctor.num_ty_params(db)) | 399 | Substs::builder(type_ctor.num_ty_params(db)) |
398 | } | 400 | } |
399 | 401 | ||
@@ -538,7 +540,7 @@ impl GenericPredicate { | |||
538 | } | 540 | } |
539 | } | 541 | } |
540 | 542 | ||
541 | pub fn trait_ref(&self, db: &impl HirDatabase) -> Option<TraitRef> { | 543 | pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option<TraitRef> { |
542 | match self { | 544 | match self { |
543 | GenericPredicate::Implemented(tr) => Some(tr.clone()), | 545 | GenericPredicate::Implemented(tr) => Some(tr.clone()), |
544 | GenericPredicate::Projection(proj) => Some(proj.projection_ty.trait_ref(db)), | 546 | GenericPredicate::Projection(proj) => Some(proj.projection_ty.trait_ref(db)), |
@@ -693,7 +695,7 @@ impl Ty { | |||
693 | } | 695 | } |
694 | } | 696 | } |
695 | 697 | ||
696 | fn callable_sig(&self, db: &impl HirDatabase) -> Option<FnSig> { | 698 | fn callable_sig(&self, db: &dyn HirDatabase) -> Option<FnSig> { |
697 | match self { | 699 | match self { |
698 | Ty::Apply(a_ty) => match a_ty.ctor { | 700 | Ty::Apply(a_ty) => match a_ty.ctor { |
699 | TypeCtor::FnPtr { .. } => Some(FnSig::from_fn_ptr_substs(&a_ty.parameters)), | 701 | TypeCtor::FnPtr { .. } => Some(FnSig::from_fn_ptr_substs(&a_ty.parameters)), |
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index b96dc126c..d7f250783 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs | |||
@@ -34,8 +34,8 @@ use crate::{ | |||
34 | }; | 34 | }; |
35 | 35 | ||
36 | #[derive(Debug)] | 36 | #[derive(Debug)] |
37 | pub struct TyLoweringContext<'a, DB: HirDatabase> { | 37 | pub struct TyLoweringContext<'a> { |
38 | pub db: &'a DB, | 38 | pub db: &'a dyn HirDatabase, |
39 | pub resolver: &'a Resolver, | 39 | pub resolver: &'a Resolver, |
40 | /// Note: Conceptually, it's thinkable that we could be in a location where | 40 | /// Note: Conceptually, it's thinkable that we could be in a location where |
41 | /// some type params should be represented as placeholders, and others | 41 | /// some type params should be represented as placeholders, and others |
@@ -46,8 +46,8 @@ pub struct TyLoweringContext<'a, DB: HirDatabase> { | |||
46 | pub impl_trait_counter: std::cell::Cell<u16>, | 46 | pub impl_trait_counter: std::cell::Cell<u16>, |
47 | } | 47 | } |
48 | 48 | ||
49 | impl<'a, DB: HirDatabase> TyLoweringContext<'a, DB> { | 49 | impl<'a> TyLoweringContext<'a> { |
50 | pub fn new(db: &'a DB, resolver: &'a Resolver) -> Self { | 50 | pub fn new(db: &'a dyn HirDatabase, resolver: &'a Resolver) -> Self { |
51 | let impl_trait_counter = std::cell::Cell::new(0); | 51 | let impl_trait_counter = std::cell::Cell::new(0); |
52 | let impl_trait_mode = ImplTraitLoweringMode::Disallowed; | 52 | let impl_trait_mode = ImplTraitLoweringMode::Disallowed; |
53 | let type_param_mode = TypeParamLoweringMode::Placeholder; | 53 | let type_param_mode = TypeParamLoweringMode::Placeholder; |
@@ -90,13 +90,10 @@ pub enum TypeParamLoweringMode { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | impl Ty { | 92 | impl Ty { |
93 | pub fn from_hir(ctx: &TyLoweringContext<'_, impl HirDatabase>, type_ref: &TypeRef) -> Self { | 93 | pub fn from_hir(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> Self { |
94 | Ty::from_hir_ext(ctx, type_ref).0 | 94 | Ty::from_hir_ext(ctx, type_ref).0 |
95 | } | 95 | } |
96 | pub fn from_hir_ext( | 96 | pub fn from_hir_ext(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> (Self, Option<TypeNs>) { |
97 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | ||
98 | type_ref: &TypeRef, | ||
99 | ) -> (Self, Option<TypeNs>) { | ||
100 | let mut res = None; | 97 | let mut res = None; |
101 | let ty = match type_ref { | 98 | let ty = match type_ref { |
102 | TypeRef::Never => Ty::simple(TypeCtor::Never), | 99 | TypeRef::Never => Ty::simple(TypeCtor::Never), |
@@ -157,7 +154,7 @@ impl Ty { | |||
157 | let idx = ctx.impl_trait_counter.get(); | 154 | let idx = ctx.impl_trait_counter.get(); |
158 | ctx.impl_trait_counter.set(idx + 1); | 155 | ctx.impl_trait_counter.set(idx + 1); |
159 | if let Some(def) = ctx.resolver.generic_def() { | 156 | if let Some(def) = ctx.resolver.generic_def() { |
160 | let generics = generics(ctx.db, def); | 157 | let generics = generics(ctx.db.upcast(), def); |
161 | let param = generics | 158 | let param = generics |
162 | .iter() | 159 | .iter() |
163 | .filter(|(_, data)| { | 160 | .filter(|(_, data)| { |
@@ -175,7 +172,7 @@ impl Ty { | |||
175 | ctx.impl_trait_counter.set(idx + 1); | 172 | ctx.impl_trait_counter.set(idx + 1); |
176 | let (parent_params, self_params, list_params, _impl_trait_params) = | 173 | let (parent_params, self_params, list_params, _impl_trait_params) = |
177 | if let Some(def) = ctx.resolver.generic_def() { | 174 | if let Some(def) = ctx.resolver.generic_def() { |
178 | let generics = generics(ctx.db, def); | 175 | let generics = generics(ctx.db.upcast(), def); |
179 | generics.provenance_split() | 176 | generics.provenance_split() |
180 | } else { | 177 | } else { |
181 | (0, 0, 0, 0) | 178 | (0, 0, 0, 0) |
@@ -201,10 +198,7 @@ impl Ty { | |||
201 | /// This is only for `generic_predicates_for_param`, where we can't just | 198 | /// This is only for `generic_predicates_for_param`, where we can't just |
202 | /// lower the self types of the predicates since that could lead to cycles. | 199 | /// lower the self types of the predicates since that could lead to cycles. |
203 | /// So we just check here if the `type_ref` resolves to a generic param, and which. | 200 | /// So we just check here if the `type_ref` resolves to a generic param, and which. |
204 | fn from_hir_only_param( | 201 | fn from_hir_only_param(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> Option<TypeParamId> { |
205 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | ||
206 | type_ref: &TypeRef, | ||
207 | ) -> Option<TypeParamId> { | ||
208 | let path = match type_ref { | 202 | let path = match type_ref { |
209 | TypeRef::Path(path) => path, | 203 | TypeRef::Path(path) => path, |
210 | _ => return None, | 204 | _ => return None, |
@@ -215,10 +209,11 @@ impl Ty { | |||
215 | if path.segments().len() > 1 { | 209 | if path.segments().len() > 1 { |
216 | return None; | 210 | return None; |
217 | } | 211 | } |
218 | let resolution = match ctx.resolver.resolve_path_in_type_ns(ctx.db, path.mod_path()) { | 212 | let resolution = |
219 | Some((it, None)) => it, | 213 | match ctx.resolver.resolve_path_in_type_ns(ctx.db.upcast(), path.mod_path()) { |
220 | _ => return None, | 214 | Some((it, None)) => it, |
221 | }; | 215 | _ => return None, |
216 | }; | ||
222 | if let TypeNs::GenericParam(param_id) = resolution { | 217 | if let TypeNs::GenericParam(param_id) = resolution { |
223 | Some(param_id) | 218 | Some(param_id) |
224 | } else { | 219 | } else { |
@@ -227,7 +222,7 @@ impl Ty { | |||
227 | } | 222 | } |
228 | 223 | ||
229 | pub(crate) fn from_type_relative_path( | 224 | pub(crate) fn from_type_relative_path( |
230 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 225 | ctx: &TyLoweringContext<'_>, |
231 | ty: Ty, | 226 | ty: Ty, |
232 | // We need the original resolution to lower `Self::AssocTy` correctly | 227 | // We need the original resolution to lower `Self::AssocTy` correctly |
233 | res: Option<TypeNs>, | 228 | res: Option<TypeNs>, |
@@ -246,7 +241,7 @@ impl Ty { | |||
246 | } | 241 | } |
247 | 242 | ||
248 | pub(crate) fn from_partly_resolved_hir_path( | 243 | pub(crate) fn from_partly_resolved_hir_path( |
249 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 244 | ctx: &TyLoweringContext<'_>, |
250 | resolution: TypeNs, | 245 | resolution: TypeNs, |
251 | resolved_segment: PathSegment<'_>, | 246 | resolved_segment: PathSegment<'_>, |
252 | remaining_segments: PathSegments<'_>, | 247 | remaining_segments: PathSegments<'_>, |
@@ -260,7 +255,7 @@ impl Ty { | |||
260 | let ty = if remaining_segments.len() == 1 { | 255 | let ty = if remaining_segments.len() == 1 { |
261 | let segment = remaining_segments.first().unwrap(); | 256 | let segment = remaining_segments.first().unwrap(); |
262 | let associated_ty = associated_type_by_name_including_super_traits( | 257 | let associated_ty = associated_type_by_name_including_super_traits( |
263 | ctx.db, | 258 | ctx.db.upcast(), |
264 | trait_ref.trait_, | 259 | trait_ref.trait_, |
265 | &segment.name, | 260 | &segment.name, |
266 | ); | 261 | ); |
@@ -286,8 +281,10 @@ impl Ty { | |||
286 | return (ty, None); | 281 | return (ty, None); |
287 | } | 282 | } |
288 | TypeNs::GenericParam(param_id) => { | 283 | TypeNs::GenericParam(param_id) => { |
289 | let generics = | 284 | let generics = generics( |
290 | generics(ctx.db, ctx.resolver.generic_def().expect("generics in scope")); | 285 | ctx.db.upcast(), |
286 | ctx.resolver.generic_def().expect("generics in scope"), | ||
287 | ); | ||
291 | match ctx.type_param_mode { | 288 | match ctx.type_param_mode { |
292 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), | 289 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), |
293 | TypeParamLoweringMode::Variable => { | 290 | TypeParamLoweringMode::Variable => { |
@@ -297,7 +294,7 @@ impl Ty { | |||
297 | } | 294 | } |
298 | } | 295 | } |
299 | TypeNs::SelfType(impl_id) => { | 296 | TypeNs::SelfType(impl_id) => { |
300 | let generics = generics(ctx.db, impl_id.into()); | 297 | let generics = generics(ctx.db.upcast(), impl_id.into()); |
301 | let substs = match ctx.type_param_mode { | 298 | let substs = match ctx.type_param_mode { |
302 | TypeParamLoweringMode::Placeholder => { | 299 | TypeParamLoweringMode::Placeholder => { |
303 | Substs::type_params_for_generics(&generics) | 300 | Substs::type_params_for_generics(&generics) |
@@ -307,7 +304,7 @@ impl Ty { | |||
307 | ctx.db.impl_self_ty(impl_id).subst(&substs) | 304 | ctx.db.impl_self_ty(impl_id).subst(&substs) |
308 | } | 305 | } |
309 | TypeNs::AdtSelfType(adt) => { | 306 | TypeNs::AdtSelfType(adt) => { |
310 | let generics = generics(ctx.db, adt.into()); | 307 | let generics = generics(ctx.db.upcast(), adt.into()); |
311 | let substs = match ctx.type_param_mode { | 308 | let substs = match ctx.type_param_mode { |
312 | TypeParamLoweringMode::Placeholder => { | 309 | TypeParamLoweringMode::Placeholder => { |
313 | Substs::type_params_for_generics(&generics) | 310 | Substs::type_params_for_generics(&generics) |
@@ -327,17 +324,14 @@ impl Ty { | |||
327 | Ty::from_type_relative_path(ctx, ty, Some(resolution), remaining_segments) | 324 | Ty::from_type_relative_path(ctx, ty, Some(resolution), remaining_segments) |
328 | } | 325 | } |
329 | 326 | ||
330 | pub(crate) fn from_hir_path( | 327 | pub(crate) fn from_hir_path(ctx: &TyLoweringContext<'_>, path: &Path) -> (Ty, Option<TypeNs>) { |
331 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | ||
332 | path: &Path, | ||
333 | ) -> (Ty, Option<TypeNs>) { | ||
334 | // Resolve the path (in type namespace) | 328 | // Resolve the path (in type namespace) |
335 | if let Some(type_ref) = path.type_anchor() { | 329 | if let Some(type_ref) = path.type_anchor() { |
336 | let (ty, res) = Ty::from_hir_ext(ctx, &type_ref); | 330 | let (ty, res) = Ty::from_hir_ext(ctx, &type_ref); |
337 | return Ty::from_type_relative_path(ctx, ty, res, path.segments()); | 331 | return Ty::from_type_relative_path(ctx, ty, res, path.segments()); |
338 | } | 332 | } |
339 | let (resolution, remaining_index) = | 333 | let (resolution, remaining_index) = |
340 | match ctx.resolver.resolve_path_in_type_ns(ctx.db, path.mod_path()) { | 334 | match ctx.resolver.resolve_path_in_type_ns(ctx.db.upcast(), path.mod_path()) { |
341 | Some(it) => it, | 335 | Some(it) => it, |
342 | None => return (Ty::Unknown, None), | 336 | None => return (Ty::Unknown, None), |
343 | }; | 337 | }; |
@@ -352,7 +346,7 @@ impl Ty { | |||
352 | } | 346 | } |
353 | 347 | ||
354 | fn select_associated_type( | 348 | fn select_associated_type( |
355 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 349 | ctx: &TyLoweringContext<'_>, |
356 | self_ty: Ty, | 350 | self_ty: Ty, |
357 | res: Option<TypeNs>, | 351 | res: Option<TypeNs>, |
358 | segment: PathSegment<'_>, | 352 | segment: PathSegment<'_>, |
@@ -374,7 +368,7 @@ impl Ty { | |||
374 | } | 368 | } |
375 | _ => return Ty::Unknown, | 369 | _ => return Ty::Unknown, |
376 | }; | 370 | }; |
377 | let traits = traits_from_env.into_iter().flat_map(|t| all_super_traits(ctx.db, t)); | 371 | let traits = traits_from_env.into_iter().flat_map(|t| all_super_traits(ctx.db.upcast(), t)); |
378 | for t in traits { | 372 | for t in traits { |
379 | if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name) | 373 | if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name) |
380 | { | 374 | { |
@@ -388,7 +382,7 @@ impl Ty { | |||
388 | } | 382 | } |
389 | 383 | ||
390 | fn from_hir_path_inner( | 384 | fn from_hir_path_inner( |
391 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 385 | ctx: &TyLoweringContext<'_>, |
392 | segment: PathSegment<'_>, | 386 | segment: PathSegment<'_>, |
393 | typable: TyDefId, | 387 | typable: TyDefId, |
394 | ) -> Ty { | 388 | ) -> Ty { |
@@ -404,7 +398,7 @@ impl Ty { | |||
404 | /// Collect generic arguments from a path into a `Substs`. See also | 398 | /// Collect generic arguments from a path into a `Substs`. See also |
405 | /// `create_substs_for_ast_path` and `def_to_ty` in rustc. | 399 | /// `create_substs_for_ast_path` and `def_to_ty` in rustc. |
406 | pub(super) fn substs_from_path( | 400 | pub(super) fn substs_from_path( |
407 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 401 | ctx: &TyLoweringContext<'_>, |
408 | path: &Path, | 402 | path: &Path, |
409 | // Note that we don't call `db.value_type(resolved)` here, | 403 | // Note that we don't call `db.value_type(resolved)` here, |
410 | // `ValueTyDefId` is just a convenient way to pass generics and | 404 | // `ValueTyDefId` is just a convenient way to pass generics and |
@@ -437,13 +431,13 @@ impl Ty { | |||
437 | } | 431 | } |
438 | 432 | ||
439 | pub(super) fn substs_from_path_segment( | 433 | pub(super) fn substs_from_path_segment( |
440 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 434 | ctx: &TyLoweringContext<'_>, |
441 | segment: PathSegment<'_>, | 435 | segment: PathSegment<'_>, |
442 | def_generic: Option<GenericDefId>, | 436 | def_generic: Option<GenericDefId>, |
443 | _add_self_param: bool, | 437 | _add_self_param: bool, |
444 | ) -> Substs { | 438 | ) -> Substs { |
445 | let mut substs = Vec::new(); | 439 | let mut substs = Vec::new(); |
446 | let def_generics = def_generic.map(|def| generics(ctx.db, def)); | 440 | let def_generics = def_generic.map(|def| generics(ctx.db.upcast(), def)); |
447 | 441 | ||
448 | let (parent_params, self_params, type_params, impl_trait_params) = | 442 | let (parent_params, self_params, type_params, impl_trait_params) = |
449 | def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); | 443 | def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); |
@@ -489,20 +483,21 @@ pub(super) fn substs_from_path_segment( | |||
489 | 483 | ||
490 | impl TraitRef { | 484 | impl TraitRef { |
491 | fn from_path( | 485 | fn from_path( |
492 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 486 | ctx: &TyLoweringContext<'_>, |
493 | path: &Path, | 487 | path: &Path, |
494 | explicit_self_ty: Option<Ty>, | 488 | explicit_self_ty: Option<Ty>, |
495 | ) -> Option<Self> { | 489 | ) -> Option<Self> { |
496 | let resolved = match ctx.resolver.resolve_path_in_type_ns_fully(ctx.db, path.mod_path())? { | 490 | let resolved = |
497 | TypeNs::TraitId(tr) => tr, | 491 | match ctx.resolver.resolve_path_in_type_ns_fully(ctx.db.upcast(), path.mod_path())? { |
498 | _ => return None, | 492 | TypeNs::TraitId(tr) => tr, |
499 | }; | 493 | _ => return None, |
494 | }; | ||
500 | let segment = path.segments().last().expect("path should have at least one segment"); | 495 | let segment = path.segments().last().expect("path should have at least one segment"); |
501 | Some(TraitRef::from_resolved_path(ctx, resolved, segment, explicit_self_ty)) | 496 | Some(TraitRef::from_resolved_path(ctx, resolved, segment, explicit_self_ty)) |
502 | } | 497 | } |
503 | 498 | ||
504 | pub(crate) fn from_resolved_path( | 499 | pub(crate) fn from_resolved_path( |
505 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 500 | ctx: &TyLoweringContext<'_>, |
506 | resolved: TraitId, | 501 | resolved: TraitId, |
507 | segment: PathSegment<'_>, | 502 | segment: PathSegment<'_>, |
508 | explicit_self_ty: Option<Ty>, | 503 | explicit_self_ty: Option<Ty>, |
@@ -515,7 +510,7 @@ impl TraitRef { | |||
515 | } | 510 | } |
516 | 511 | ||
517 | fn from_hir( | 512 | fn from_hir( |
518 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 513 | ctx: &TyLoweringContext<'_>, |
519 | type_ref: &TypeRef, | 514 | type_ref: &TypeRef, |
520 | explicit_self_ty: Option<Ty>, | 515 | explicit_self_ty: Option<Ty>, |
521 | ) -> Option<Self> { | 516 | ) -> Option<Self> { |
@@ -527,7 +522,7 @@ impl TraitRef { | |||
527 | } | 522 | } |
528 | 523 | ||
529 | fn substs_from_path( | 524 | fn substs_from_path( |
530 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 525 | ctx: &TyLoweringContext<'_>, |
531 | segment: PathSegment<'_>, | 526 | segment: PathSegment<'_>, |
532 | resolved: TraitId, | 527 | resolved: TraitId, |
533 | ) -> Substs { | 528 | ) -> Substs { |
@@ -537,7 +532,7 @@ impl TraitRef { | |||
537 | } | 532 | } |
538 | 533 | ||
539 | pub(crate) fn from_type_bound( | 534 | pub(crate) fn from_type_bound( |
540 | ctx: &TyLoweringContext<'_, impl HirDatabase>, | 535 | ctx: &TyLoweringContext<'_>, |
541 | bound: &TypeBound, | 536 | bound: &TypeBound, |
542 | self_ty: Ty, | 537 | self_ty: Ty, |
543 | ) -> Option<TraitRef> { | 538 | ) -> Option<TraitRef> { |
@@ -550,14 +545,14 @@ impl TraitRef { | |||
550 | 545 | ||
551 | impl GenericPredicate { | 546 | impl GenericPredicate { |
552 | pub(crate) fn from_where_predicate<'a>( | 547 | pub(crate) fn from_where_predicate<'a>( |
553 | ctx: &'a TyLoweringContext<'a, impl HirDatabase>, | 548 | ctx: &'a TyLoweringContext<'a>, |
554 | where_predicate: &'a WherePredicate, | 549 | where_predicate: &'a WherePredicate, |
555 | ) -> impl Iterator<Item = GenericPredicate> + 'a { | 550 | ) -> impl Iterator<Item = GenericPredicate> + 'a { |
556 | let self_ty = match &where_predicate.target { | 551 | let self_ty = match &where_predicate.target { |
557 | WherePredicateTarget::TypeRef(type_ref) => Ty::from_hir(ctx, type_ref), | 552 | WherePredicateTarget::TypeRef(type_ref) => Ty::from_hir(ctx, type_ref), |
558 | WherePredicateTarget::TypeParam(param_id) => { | 553 | WherePredicateTarget::TypeParam(param_id) => { |
559 | let generic_def = ctx.resolver.generic_def().expect("generics in scope"); | 554 | let generic_def = ctx.resolver.generic_def().expect("generics in scope"); |
560 | let generics = generics(ctx.db, generic_def); | 555 | let generics = generics(ctx.db.upcast(), generic_def); |
561 | let param_id = hir_def::TypeParamId { parent: generic_def, local_id: *param_id }; | 556 | let param_id = hir_def::TypeParamId { parent: generic_def, local_id: *param_id }; |
562 | match ctx.type_param_mode { | 557 | match ctx.type_param_mode { |
563 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), | 558 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), |
@@ -572,7 +567,7 @@ impl GenericPredicate { | |||
572 | } | 567 | } |
573 | 568 | ||
574 | pub(crate) fn from_type_bound<'a>( | 569 | pub(crate) fn from_type_bound<'a>( |
575 | ctx: &'a TyLoweringContext<'a, impl HirDatabase>, | 570 | ctx: &'a TyLoweringContext<'a>, |
576 | bound: &'a TypeBound, | 571 | bound: &'a TypeBound, |
577 | self_ty: Ty, | 572 | self_ty: Ty, |
578 | ) -> impl Iterator<Item = GenericPredicate> + 'a { | 573 | ) -> impl Iterator<Item = GenericPredicate> + 'a { |
@@ -587,7 +582,7 @@ impl GenericPredicate { | |||
587 | } | 582 | } |
588 | 583 | ||
589 | fn assoc_type_bindings_from_type_bound<'a>( | 584 | fn assoc_type_bindings_from_type_bound<'a>( |
590 | ctx: &'a TyLoweringContext<'a, impl HirDatabase>, | 585 | ctx: &'a TyLoweringContext<'a>, |
591 | bound: &'a TypeBound, | 586 | bound: &'a TypeBound, |
592 | trait_ref: TraitRef, | 587 | trait_ref: TraitRef, |
593 | ) -> impl Iterator<Item = GenericPredicate> + 'a { | 588 | ) -> impl Iterator<Item = GenericPredicate> + 'a { |
@@ -600,8 +595,11 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
600 | .flat_map(|segment| segment.args_and_bindings.into_iter()) | 595 | .flat_map(|segment| segment.args_and_bindings.into_iter()) |
601 | .flat_map(|args_and_bindings| args_and_bindings.bindings.iter()) | 596 | .flat_map(|args_and_bindings| args_and_bindings.bindings.iter()) |
602 | .map(move |(name, type_ref)| { | 597 | .map(move |(name, type_ref)| { |
603 | let associated_ty = | 598 | let associated_ty = associated_type_by_name_including_super_traits( |
604 | associated_type_by_name_including_super_traits(ctx.db, trait_ref.trait_, &name); | 599 | ctx.db.upcast(), |
600 | trait_ref.trait_, | ||
601 | &name, | ||
602 | ); | ||
605 | let associated_ty = match associated_ty { | 603 | let associated_ty = match associated_ty { |
606 | None => return GenericPredicate::Error, | 604 | None => return GenericPredicate::Error, |
607 | Some(t) => t, | 605 | Some(t) => t, |
@@ -615,7 +613,7 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
615 | } | 613 | } |
616 | 614 | ||
617 | /// Build the signature of a callable item (function, struct or enum variant). | 615 | /// Build the signature of a callable item (function, struct or enum variant). |
618 | pub fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> PolyFnSig { | 616 | pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig { |
619 | match def { | 617 | match def { |
620 | CallableDef::FunctionId(f) => fn_sig_for_fn(db, f), | 618 | CallableDef::FunctionId(f) => fn_sig_for_fn(db, f), |
621 | CallableDef::StructId(s) => fn_sig_for_struct_constructor(db, s), | 619 | CallableDef::StructId(s) => fn_sig_for_struct_constructor(db, s), |
@@ -625,16 +623,16 @@ pub fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> PolyFnSig { | |||
625 | 623 | ||
626 | /// Build the type of all specific fields of a struct or enum variant. | 624 | /// Build the type of all specific fields of a struct or enum variant. |
627 | pub(crate) fn field_types_query( | 625 | pub(crate) fn field_types_query( |
628 | db: &impl HirDatabase, | 626 | db: &dyn HirDatabase, |
629 | variant_id: VariantId, | 627 | variant_id: VariantId, |
630 | ) -> Arc<ArenaMap<LocalStructFieldId, Binders<Ty>>> { | 628 | ) -> Arc<ArenaMap<LocalStructFieldId, Binders<Ty>>> { |
631 | let var_data = variant_data(db, variant_id); | 629 | let var_data = variant_data(db.upcast(), variant_id); |
632 | let (resolver, def): (_, GenericDefId) = match variant_id { | 630 | let (resolver, def): (_, GenericDefId) = match variant_id { |
633 | VariantId::StructId(it) => (it.resolver(db), it.into()), | 631 | VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()), |
634 | VariantId::UnionId(it) => (it.resolver(db), it.into()), | 632 | VariantId::UnionId(it) => (it.resolver(db.upcast()), it.into()), |
635 | VariantId::EnumVariantId(it) => (it.parent.resolver(db), it.parent.into()), | 633 | VariantId::EnumVariantId(it) => (it.parent.resolver(db.upcast()), it.parent.into()), |
636 | }; | 634 | }; |
637 | let generics = generics(db, def); | 635 | let generics = generics(db.upcast(), def); |
638 | let mut res = ArenaMap::default(); | 636 | let mut res = ArenaMap::default(); |
639 | let ctx = | 637 | let ctx = |
640 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 638 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
@@ -653,13 +651,13 @@ pub(crate) fn field_types_query( | |||
653 | /// following bounds are disallowed: `T: Foo<U::Item>, U: Foo<T::Item>`, but | 651 | /// following bounds are disallowed: `T: Foo<U::Item>, U: Foo<T::Item>`, but |
654 | /// these are fine: `T: Foo<U::Item>, U: Foo<()>`. | 652 | /// these are fine: `T: Foo<U::Item>, U: Foo<()>`. |
655 | pub(crate) fn generic_predicates_for_param_query( | 653 | pub(crate) fn generic_predicates_for_param_query( |
656 | db: &impl HirDatabase, | 654 | db: &dyn HirDatabase, |
657 | param_id: TypeParamId, | 655 | param_id: TypeParamId, |
658 | ) -> Arc<[Binders<GenericPredicate>]> { | 656 | ) -> Arc<[Binders<GenericPredicate>]> { |
659 | let resolver = param_id.parent.resolver(db); | 657 | let resolver = param_id.parent.resolver(db.upcast()); |
660 | let ctx = | 658 | let ctx = |
661 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 659 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
662 | let generics = generics(db, param_id.parent); | 660 | let generics = generics(db.upcast(), param_id.parent); |
663 | resolver | 661 | resolver |
664 | .where_predicates_in_scope() | 662 | .where_predicates_in_scope() |
665 | // we have to filter out all other predicates *first*, before attempting to lower them | 663 | // we have to filter out all other predicates *first*, before attempting to lower them |
@@ -677,7 +675,7 @@ pub(crate) fn generic_predicates_for_param_query( | |||
677 | } | 675 | } |
678 | 676 | ||
679 | pub(crate) fn generic_predicates_for_param_recover( | 677 | pub(crate) fn generic_predicates_for_param_recover( |
680 | _db: &impl HirDatabase, | 678 | _db: &dyn HirDatabase, |
681 | _cycle: &[String], | 679 | _cycle: &[String], |
682 | _param_id: &TypeParamId, | 680 | _param_id: &TypeParamId, |
683 | ) -> Arc<[Binders<GenericPredicate>]> { | 681 | ) -> Arc<[Binders<GenericPredicate>]> { |
@@ -685,7 +683,7 @@ pub(crate) fn generic_predicates_for_param_recover( | |||
685 | } | 683 | } |
686 | 684 | ||
687 | impl TraitEnvironment { | 685 | impl TraitEnvironment { |
688 | pub fn lower(db: &impl HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> { | 686 | pub fn lower(db: &dyn HirDatabase, resolver: &Resolver) -> Arc<TraitEnvironment> { |
689 | let ctx = TyLoweringContext::new(db, &resolver) | 687 | let ctx = TyLoweringContext::new(db, &resolver) |
690 | .with_type_param_mode(TypeParamLoweringMode::Placeholder); | 688 | .with_type_param_mode(TypeParamLoweringMode::Placeholder); |
691 | let mut predicates = resolver | 689 | let mut predicates = resolver |
@@ -696,13 +694,13 @@ impl TraitEnvironment { | |||
696 | if let Some(def) = resolver.generic_def() { | 694 | if let Some(def) = resolver.generic_def() { |
697 | let container: Option<AssocContainerId> = match def { | 695 | let container: Option<AssocContainerId> = match def { |
698 | // FIXME: is there a function for this? | 696 | // FIXME: is there a function for this? |
699 | GenericDefId::FunctionId(f) => Some(f.lookup(db).container), | 697 | GenericDefId::FunctionId(f) => Some(f.lookup(db.upcast()).container), |
700 | GenericDefId::AdtId(_) => None, | 698 | GenericDefId::AdtId(_) => None, |
701 | GenericDefId::TraitId(_) => None, | 699 | GenericDefId::TraitId(_) => None, |
702 | GenericDefId::TypeAliasId(t) => Some(t.lookup(db).container), | 700 | GenericDefId::TypeAliasId(t) => Some(t.lookup(db.upcast()).container), |
703 | GenericDefId::ImplId(_) => None, | 701 | GenericDefId::ImplId(_) => None, |
704 | GenericDefId::EnumVariantId(_) => None, | 702 | GenericDefId::EnumVariantId(_) => None, |
705 | GenericDefId::ConstId(c) => Some(c.lookup(db).container), | 703 | GenericDefId::ConstId(c) => Some(c.lookup(db.upcast()).container), |
706 | }; | 704 | }; |
707 | if let Some(AssocContainerId::TraitId(trait_id)) = container { | 705 | if let Some(AssocContainerId::TraitId(trait_id)) = container { |
708 | // add `Self: Trait<T1, T2, ...>` to the environment in trait | 706 | // add `Self: Trait<T1, T2, ...>` to the environment in trait |
@@ -723,13 +721,13 @@ impl TraitEnvironment { | |||
723 | 721 | ||
724 | /// Resolve the where clause(s) of an item with generics. | 722 | /// Resolve the where clause(s) of an item with generics. |
725 | pub(crate) fn generic_predicates_query( | 723 | pub(crate) fn generic_predicates_query( |
726 | db: &impl HirDatabase, | 724 | db: &dyn HirDatabase, |
727 | def: GenericDefId, | 725 | def: GenericDefId, |
728 | ) -> Arc<[Binders<GenericPredicate>]> { | 726 | ) -> Arc<[Binders<GenericPredicate>]> { |
729 | let resolver = def.resolver(db); | 727 | let resolver = def.resolver(db.upcast()); |
730 | let ctx = | 728 | let ctx = |
731 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 729 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
732 | let generics = generics(db, def); | 730 | let generics = generics(db.upcast(), def); |
733 | resolver | 731 | resolver |
734 | .where_predicates_in_scope() | 732 | .where_predicates_in_scope() |
735 | .flat_map(|pred| { | 733 | .flat_map(|pred| { |
@@ -740,10 +738,10 @@ pub(crate) fn generic_predicates_query( | |||
740 | } | 738 | } |
741 | 739 | ||
742 | /// Resolve the default type params from generics | 740 | /// Resolve the default type params from generics |
743 | pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { | 741 | pub(crate) fn generic_defaults_query(db: &dyn HirDatabase, def: GenericDefId) -> Substs { |
744 | let resolver = def.resolver(db); | 742 | let resolver = def.resolver(db.upcast()); |
745 | let ctx = TyLoweringContext::new(db, &resolver); | 743 | let ctx = TyLoweringContext::new(db, &resolver); |
746 | let generic_params = generics(db, def); | 744 | let generic_params = generics(db.upcast(), def); |
747 | 745 | ||
748 | let defaults = generic_params | 746 | let defaults = generic_params |
749 | .iter() | 747 | .iter() |
@@ -753,33 +751,33 @@ pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) - | |||
753 | Substs(defaults) | 751 | Substs(defaults) |
754 | } | 752 | } |
755 | 753 | ||
756 | fn fn_sig_for_fn(db: &impl HirDatabase, def: FunctionId) -> PolyFnSig { | 754 | fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig { |
757 | let data = db.function_data(def); | 755 | let data = db.function_data(def); |
758 | let resolver = def.resolver(db); | 756 | let resolver = def.resolver(db.upcast()); |
759 | let ctx_params = TyLoweringContext::new(db, &resolver) | 757 | let ctx_params = TyLoweringContext::new(db, &resolver) |
760 | .with_impl_trait_mode(ImplTraitLoweringMode::Variable) | 758 | .with_impl_trait_mode(ImplTraitLoweringMode::Variable) |
761 | .with_type_param_mode(TypeParamLoweringMode::Variable); | 759 | .with_type_param_mode(TypeParamLoweringMode::Variable); |
762 | let params = data.params.iter().map(|tr| Ty::from_hir(&ctx_params, tr)).collect::<Vec<_>>(); | 760 | let params = data.params.iter().map(|tr| Ty::from_hir(&ctx_params, tr)).collect::<Vec<_>>(); |
763 | let ctx_ret = ctx_params.with_impl_trait_mode(ImplTraitLoweringMode::Opaque); | 761 | let ctx_ret = ctx_params.with_impl_trait_mode(ImplTraitLoweringMode::Opaque); |
764 | let ret = Ty::from_hir(&ctx_ret, &data.ret_type); | 762 | let ret = Ty::from_hir(&ctx_ret, &data.ret_type); |
765 | let generics = generics(db, def.into()); | 763 | let generics = generics(db.upcast(), def.into()); |
766 | let num_binders = generics.len(); | 764 | let num_binders = generics.len(); |
767 | Binders::new(num_binders, FnSig::from_params_and_return(params, ret)) | 765 | Binders::new(num_binders, FnSig::from_params_and_return(params, ret)) |
768 | } | 766 | } |
769 | 767 | ||
770 | /// Build the declared type of a function. This should not need to look at the | 768 | /// Build the declared type of a function. This should not need to look at the |
771 | /// function body. | 769 | /// function body. |
772 | fn type_for_fn(db: &impl HirDatabase, def: FunctionId) -> Binders<Ty> { | 770 | fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> { |
773 | let generics = generics(db, def.into()); | 771 | let generics = generics(db.upcast(), def.into()); |
774 | let substs = Substs::bound_vars(&generics); | 772 | let substs = Substs::bound_vars(&generics); |
775 | Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) | 773 | Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) |
776 | } | 774 | } |
777 | 775 | ||
778 | /// Build the declared type of a const. | 776 | /// Build the declared type of a const. |
779 | fn type_for_const(db: &impl HirDatabase, def: ConstId) -> Binders<Ty> { | 777 | fn type_for_const(db: &dyn HirDatabase, def: ConstId) -> Binders<Ty> { |
780 | let data = db.const_data(def); | 778 | let data = db.const_data(def); |
781 | let generics = generics(db, def.into()); | 779 | let generics = generics(db.upcast(), def.into()); |
782 | let resolver = def.resolver(db); | 780 | let resolver = def.resolver(db.upcast()); |
783 | let ctx = | 781 | let ctx = |
784 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 782 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
785 | 783 | ||
@@ -787,9 +785,9 @@ fn type_for_const(db: &impl HirDatabase, def: ConstId) -> Binders<Ty> { | |||
787 | } | 785 | } |
788 | 786 | ||
789 | /// Build the declared type of a static. | 787 | /// Build the declared type of a static. |
790 | fn type_for_static(db: &impl HirDatabase, def: StaticId) -> Binders<Ty> { | 788 | fn type_for_static(db: &dyn HirDatabase, def: StaticId) -> Binders<Ty> { |
791 | let data = db.static_data(def); | 789 | let data = db.static_data(def); |
792 | let resolver = def.resolver(db); | 790 | let resolver = def.resolver(db.upcast()); |
793 | let ctx = TyLoweringContext::new(db, &resolver); | 791 | let ctx = TyLoweringContext::new(db, &resolver); |
794 | 792 | ||
795 | Binders::new(0, Ty::from_hir(&ctx, &data.type_ref)) | 793 | Binders::new(0, Ty::from_hir(&ctx, &data.type_ref)) |
@@ -806,10 +804,10 @@ fn type_for_builtin(def: BuiltinType) -> Ty { | |||
806 | }) | 804 | }) |
807 | } | 805 | } |
808 | 806 | ||
809 | fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFnSig { | 807 | fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnSig { |
810 | let struct_data = db.struct_data(def); | 808 | let struct_data = db.struct_data(def); |
811 | let fields = struct_data.variant_data.fields(); | 809 | let fields = struct_data.variant_data.fields(); |
812 | let resolver = def.resolver(db); | 810 | let resolver = def.resolver(db.upcast()); |
813 | let ctx = | 811 | let ctx = |
814 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 812 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
815 | let params = | 813 | let params = |
@@ -819,21 +817,21 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFn | |||
819 | } | 817 | } |
820 | 818 | ||
821 | /// Build the type of a tuple struct constructor. | 819 | /// Build the type of a tuple struct constructor. |
822 | fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders<Ty> { | 820 | fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Binders<Ty> { |
823 | let struct_data = db.struct_data(def); | 821 | let struct_data = db.struct_data(def); |
824 | if let StructKind::Unit = struct_data.variant_data.kind() { | 822 | if let StructKind::Unit = struct_data.variant_data.kind() { |
825 | return type_for_adt(db, def.into()); | 823 | return type_for_adt(db, def.into()); |
826 | } | 824 | } |
827 | let generics = generics(db, def.into()); | 825 | let generics = generics(db.upcast(), def.into()); |
828 | let substs = Substs::bound_vars(&generics); | 826 | let substs = Substs::bound_vars(&generics); |
829 | Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) | 827 | Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) |
830 | } | 828 | } |
831 | 829 | ||
832 | fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> PolyFnSig { | 830 | fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> PolyFnSig { |
833 | let enum_data = db.enum_data(def.parent); | 831 | let enum_data = db.enum_data(def.parent); |
834 | let var_data = &enum_data.variants[def.local_id]; | 832 | let var_data = &enum_data.variants[def.local_id]; |
835 | let fields = var_data.variant_data.fields(); | 833 | let fields = var_data.variant_data.fields(); |
836 | let resolver = def.parent.resolver(db); | 834 | let resolver = def.parent.resolver(db.upcast()); |
837 | let ctx = | 835 | let ctx = |
838 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 836 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
839 | let params = | 837 | let params = |
@@ -843,26 +841,26 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId | |||
843 | } | 841 | } |
844 | 842 | ||
845 | /// Build the type of a tuple enum variant constructor. | 843 | /// Build the type of a tuple enum variant constructor. |
846 | fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> Binders<Ty> { | 844 | fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> Binders<Ty> { |
847 | let enum_data = db.enum_data(def.parent); | 845 | let enum_data = db.enum_data(def.parent); |
848 | let var_data = &enum_data.variants[def.local_id].variant_data; | 846 | let var_data = &enum_data.variants[def.local_id].variant_data; |
849 | if let StructKind::Unit = var_data.kind() { | 847 | if let StructKind::Unit = var_data.kind() { |
850 | return type_for_adt(db, def.parent.into()); | 848 | return type_for_adt(db, def.parent.into()); |
851 | } | 849 | } |
852 | let generics = generics(db, def.parent.into()); | 850 | let generics = generics(db.upcast(), def.parent.into()); |
853 | let substs = Substs::bound_vars(&generics); | 851 | let substs = Substs::bound_vars(&generics); |
854 | Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) | 852 | Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) |
855 | } | 853 | } |
856 | 854 | ||
857 | fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Binders<Ty> { | 855 | fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { |
858 | let generics = generics(db, adt.into()); | 856 | let generics = generics(db.upcast(), adt.into()); |
859 | let substs = Substs::bound_vars(&generics); | 857 | let substs = Substs::bound_vars(&generics); |
860 | Binders::new(substs.len(), Ty::apply(TypeCtor::Adt(adt), substs)) | 858 | Binders::new(substs.len(), Ty::apply(TypeCtor::Adt(adt), substs)) |
861 | } | 859 | } |
862 | 860 | ||
863 | fn type_for_type_alias(db: &impl HirDatabase, t: TypeAliasId) -> Binders<Ty> { | 861 | fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> { |
864 | let generics = generics(db, t.into()); | 862 | let generics = generics(db.upcast(), t.into()); |
865 | let resolver = t.resolver(db); | 863 | let resolver = t.resolver(db.upcast()); |
866 | let ctx = | 864 | let ctx = |
867 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 865 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
868 | let type_ref = &db.type_alias_data(t).type_ref; | 866 | let type_ref = &db.type_alias_data(t).type_ref; |
@@ -880,7 +878,8 @@ pub enum CallableDef { | |||
880 | impl_froms!(CallableDef: FunctionId, StructId, EnumVariantId); | 878 | impl_froms!(CallableDef: FunctionId, StructId, EnumVariantId); |
881 | 879 | ||
882 | impl CallableDef { | 880 | impl CallableDef { |
883 | pub fn krate(self, db: &impl HirDatabase) -> CrateId { | 881 | pub fn krate(self, db: &dyn HirDatabase) -> CrateId { |
882 | let db = db.upcast(); | ||
884 | match self { | 883 | match self { |
885 | CallableDef::FunctionId(f) => f.lookup(db).module(db), | 884 | CallableDef::FunctionId(f) => f.lookup(db).module(db), |
886 | CallableDef::StructId(s) => s.lookup(db).container.module(db), | 885 | CallableDef::StructId(s) => s.lookup(db).container.module(db), |
@@ -922,7 +921,7 @@ impl_froms!(ValueTyDefId: FunctionId, StructId, EnumVariantId, ConstId, StaticId | |||
922 | /// `struct Foo(usize)`, we have two types: The type of the struct itself, and | 921 | /// `struct Foo(usize)`, we have two types: The type of the struct itself, and |
923 | /// the constructor function `(usize) -> Foo` which lives in the values | 922 | /// the constructor function `(usize) -> Foo` which lives in the values |
924 | /// namespace. | 923 | /// namespace. |
925 | pub(crate) fn ty_query(db: &impl HirDatabase, def: TyDefId) -> Binders<Ty> { | 924 | pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders<Ty> { |
926 | match def { | 925 | match def { |
927 | TyDefId::BuiltinType(it) => Binders::new(0, type_for_builtin(it)), | 926 | TyDefId::BuiltinType(it) => Binders::new(0, type_for_builtin(it)), |
928 | TyDefId::AdtId(it) => type_for_adt(db, it), | 927 | TyDefId::AdtId(it) => type_for_adt(db, it), |
@@ -930,16 +929,16 @@ pub(crate) fn ty_query(db: &impl HirDatabase, def: TyDefId) -> Binders<Ty> { | |||
930 | } | 929 | } |
931 | } | 930 | } |
932 | 931 | ||
933 | pub(crate) fn ty_recover(db: &impl HirDatabase, _cycle: &[String], def: &TyDefId) -> Binders<Ty> { | 932 | pub(crate) fn ty_recover(db: &dyn HirDatabase, _cycle: &[String], def: &TyDefId) -> Binders<Ty> { |
934 | let num_binders = match *def { | 933 | let num_binders = match *def { |
935 | TyDefId::BuiltinType(_) => 0, | 934 | TyDefId::BuiltinType(_) => 0, |
936 | TyDefId::AdtId(it) => generics(db, it.into()).len(), | 935 | TyDefId::AdtId(it) => generics(db.upcast(), it.into()).len(), |
937 | TyDefId::TypeAliasId(it) => generics(db, it.into()).len(), | 936 | TyDefId::TypeAliasId(it) => generics(db.upcast(), it.into()).len(), |
938 | }; | 937 | }; |
939 | Binders::new(num_binders, Ty::Unknown) | 938 | Binders::new(num_binders, Ty::Unknown) |
940 | } | 939 | } |
941 | 940 | ||
942 | pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Binders<Ty> { | 941 | pub(crate) fn value_ty_query(db: &dyn HirDatabase, def: ValueTyDefId) -> Binders<Ty> { |
943 | match def { | 942 | match def { |
944 | ValueTyDefId::FunctionId(it) => type_for_fn(db, it), | 943 | ValueTyDefId::FunctionId(it) => type_for_fn(db, it), |
945 | ValueTyDefId::StructId(it) => type_for_struct_constructor(db, it), | 944 | ValueTyDefId::StructId(it) => type_for_struct_constructor(db, it), |
@@ -949,30 +948,27 @@ pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Binder | |||
949 | } | 948 | } |
950 | } | 949 | } |
951 | 950 | ||
952 | pub(crate) fn impl_self_ty_query(db: &impl HirDatabase, impl_id: ImplId) -> Binders<Ty> { | 951 | pub(crate) fn impl_self_ty_query(db: &dyn HirDatabase, impl_id: ImplId) -> Binders<Ty> { |
953 | let impl_data = db.impl_data(impl_id); | 952 | let impl_data = db.impl_data(impl_id); |
954 | let resolver = impl_id.resolver(db); | 953 | let resolver = impl_id.resolver(db.upcast()); |
955 | let generics = generics(db, impl_id.into()); | 954 | let generics = generics(db.upcast(), impl_id.into()); |
956 | let ctx = | 955 | let ctx = |
957 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 956 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
958 | Binders::new(generics.len(), Ty::from_hir(&ctx, &impl_data.target_type)) | 957 | Binders::new(generics.len(), Ty::from_hir(&ctx, &impl_data.target_type)) |
959 | } | 958 | } |
960 | 959 | ||
961 | pub(crate) fn impl_self_ty_recover( | 960 | pub(crate) fn impl_self_ty_recover( |
962 | db: &impl HirDatabase, | 961 | db: &dyn HirDatabase, |
963 | _cycle: &[String], | 962 | _cycle: &[String], |
964 | impl_id: &ImplId, | 963 | impl_id: &ImplId, |
965 | ) -> Binders<Ty> { | 964 | ) -> Binders<Ty> { |
966 | let generics = generics(db, (*impl_id).into()); | 965 | let generics = generics(db.upcast(), (*impl_id).into()); |
967 | Binders::new(generics.len(), Ty::Unknown) | 966 | Binders::new(generics.len(), Ty::Unknown) |
968 | } | 967 | } |
969 | 968 | ||
970 | pub(crate) fn impl_trait_query( | 969 | pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option<Binders<TraitRef>> { |
971 | db: &impl HirDatabase, | ||
972 | impl_id: ImplId, | ||
973 | ) -> Option<Binders<TraitRef>> { | ||
974 | let impl_data = db.impl_data(impl_id); | 970 | let impl_data = db.impl_data(impl_id); |
975 | let resolver = impl_id.resolver(db); | 971 | let resolver = impl_id.resolver(db.upcast()); |
976 | let ctx = | 972 | let ctx = |
977 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); | 973 | TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); |
978 | let self_ty = db.impl_self_ty(impl_id); | 974 | let self_ty = db.impl_self_ty(impl_id); |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 7f5e1469e..69c059ac8 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -48,10 +48,7 @@ pub struct CrateImplDefs { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | impl CrateImplDefs { | 50 | impl CrateImplDefs { |
51 | pub(crate) fn impls_in_crate_query( | 51 | pub(crate) fn impls_in_crate_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<CrateImplDefs> { |
52 | db: &impl HirDatabase, | ||
53 | krate: CrateId, | ||
54 | ) -> Arc<CrateImplDefs> { | ||
55 | let _p = profile("impls_in_crate_query"); | 52 | let _p = profile("impls_in_crate_query"); |
56 | let mut res = | 53 | let mut res = |
57 | CrateImplDefs { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; | 54 | CrateImplDefs { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; |
@@ -92,7 +89,7 @@ impl CrateImplDefs { | |||
92 | impl Ty { | 89 | impl Ty { |
93 | pub fn def_crates( | 90 | pub fn def_crates( |
94 | &self, | 91 | &self, |
95 | db: &impl HirDatabase, | 92 | db: &dyn HirDatabase, |
96 | cur_crate: CrateId, | 93 | cur_crate: CrateId, |
97 | ) -> Option<ArrayVec<[CrateId; 2]>> { | 94 | ) -> Option<ArrayVec<[CrateId; 2]>> { |
98 | // Types like slice can have inherent impls in several crates, (core and alloc). | 95 | // Types like slice can have inherent impls in several crates, (core and alloc). |
@@ -110,7 +107,7 @@ impl Ty { | |||
110 | let lang_item_targets = match self { | 107 | let lang_item_targets = match self { |
111 | Ty::Apply(a_ty) => match a_ty.ctor { | 108 | Ty::Apply(a_ty) => match a_ty.ctor { |
112 | TypeCtor::Adt(def_id) => { | 109 | TypeCtor::Adt(def_id) => { |
113 | return Some(std::iter::once(def_id.module(db).krate).collect()) | 110 | return Some(std::iter::once(def_id.module(db.upcast()).krate).collect()) |
114 | } | 111 | } |
115 | TypeCtor::Bool => lang_item_crate!("bool"), | 112 | TypeCtor::Bool => lang_item_crate!("bool"), |
116 | TypeCtor::Char => lang_item_crate!("char"), | 113 | TypeCtor::Char => lang_item_crate!("char"), |
@@ -134,7 +131,7 @@ impl Ty { | |||
134 | LangItemTarget::ImplDefId(it) => Some(it), | 131 | LangItemTarget::ImplDefId(it) => Some(it), |
135 | _ => None, | 132 | _ => None, |
136 | }) | 133 | }) |
137 | .map(|it| it.lookup(db).container.module(db).krate) | 134 | .map(|it| it.lookup(db.upcast()).container.module(db.upcast()).krate) |
138 | .collect(); | 135 | .collect(); |
139 | Some(res) | 136 | Some(res) |
140 | } | 137 | } |
@@ -143,7 +140,7 @@ impl Ty { | |||
143 | /// receiver type (but without autoref applied yet). | 140 | /// receiver type (but without autoref applied yet). |
144 | pub(crate) fn lookup_method( | 141 | pub(crate) fn lookup_method( |
145 | ty: &Canonical<Ty>, | 142 | ty: &Canonical<Ty>, |
146 | db: &impl HirDatabase, | 143 | db: &dyn HirDatabase, |
147 | env: Arc<TraitEnvironment>, | 144 | env: Arc<TraitEnvironment>, |
148 | krate: CrateId, | 145 | krate: CrateId, |
149 | traits_in_scope: &FxHashSet<TraitId>, | 146 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -181,7 +178,7 @@ pub enum LookupMode { | |||
181 | // FIXME add a context type here? | 178 | // FIXME add a context type here? |
182 | pub fn iterate_method_candidates<T>( | 179 | pub fn iterate_method_candidates<T>( |
183 | ty: &Canonical<Ty>, | 180 | ty: &Canonical<Ty>, |
184 | db: &impl HirDatabase, | 181 | db: &dyn HirDatabase, |
185 | env: Arc<TraitEnvironment>, | 182 | env: Arc<TraitEnvironment>, |
186 | krate: CrateId, | 183 | krate: CrateId, |
187 | traits_in_scope: &FxHashSet<TraitId>, | 184 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -247,7 +244,7 @@ pub fn iterate_method_candidates<T>( | |||
247 | 244 | ||
248 | fn iterate_method_candidates_with_autoref<T>( | 245 | fn iterate_method_candidates_with_autoref<T>( |
249 | deref_chain: &[Canonical<Ty>], | 246 | deref_chain: &[Canonical<Ty>], |
250 | db: &impl HirDatabase, | 247 | db: &dyn HirDatabase, |
251 | env: Arc<TraitEnvironment>, | 248 | env: Arc<TraitEnvironment>, |
252 | krate: CrateId, | 249 | krate: CrateId, |
253 | traits_in_scope: &FxHashSet<TraitId>, | 250 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -304,7 +301,7 @@ fn iterate_method_candidates_with_autoref<T>( | |||
304 | fn iterate_method_candidates_by_receiver<T>( | 301 | fn iterate_method_candidates_by_receiver<T>( |
305 | receiver_ty: &Canonical<Ty>, | 302 | receiver_ty: &Canonical<Ty>, |
306 | rest_of_deref_chain: &[Canonical<Ty>], | 303 | rest_of_deref_chain: &[Canonical<Ty>], |
307 | db: &impl HirDatabase, | 304 | db: &dyn HirDatabase, |
308 | env: Arc<TraitEnvironment>, | 305 | env: Arc<TraitEnvironment>, |
309 | krate: CrateId, | 306 | krate: CrateId, |
310 | traits_in_scope: &FxHashSet<TraitId>, | 307 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -340,7 +337,7 @@ fn iterate_method_candidates_by_receiver<T>( | |||
340 | 337 | ||
341 | fn iterate_method_candidates_for_self_ty<T>( | 338 | fn iterate_method_candidates_for_self_ty<T>( |
342 | self_ty: &Canonical<Ty>, | 339 | self_ty: &Canonical<Ty>, |
343 | db: &impl HirDatabase, | 340 | db: &dyn HirDatabase, |
344 | env: Arc<TraitEnvironment>, | 341 | env: Arc<TraitEnvironment>, |
345 | krate: CrateId, | 342 | krate: CrateId, |
346 | traits_in_scope: &FxHashSet<TraitId>, | 343 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -367,7 +364,7 @@ fn iterate_method_candidates_for_self_ty<T>( | |||
367 | 364 | ||
368 | fn iterate_trait_method_candidates<T>( | 365 | fn iterate_trait_method_candidates<T>( |
369 | self_ty: &Canonical<Ty>, | 366 | self_ty: &Canonical<Ty>, |
370 | db: &impl HirDatabase, | 367 | db: &dyn HirDatabase, |
371 | env: Arc<TraitEnvironment>, | 368 | env: Arc<TraitEnvironment>, |
372 | krate: CrateId, | 369 | krate: CrateId, |
373 | traits_in_scope: &FxHashSet<TraitId>, | 370 | traits_in_scope: &FxHashSet<TraitId>, |
@@ -381,7 +378,7 @@ fn iterate_trait_method_candidates<T>( | |||
381 | // if we have `T: Trait` in the param env, the trait doesn't need to be in scope | 378 | // if we have `T: Trait` in the param env, the trait doesn't need to be in scope |
382 | env.trait_predicates_for_self_ty(&self_ty.value) | 379 | env.trait_predicates_for_self_ty(&self_ty.value) |
383 | .map(|tr| tr.trait_) | 380 | .map(|tr| tr.trait_) |
384 | .flat_map(|t| all_super_traits(db, t)) | 381 | .flat_map(|t| all_super_traits(db.upcast(), t)) |
385 | .collect() | 382 | .collect() |
386 | } else { | 383 | } else { |
387 | Vec::new() | 384 | Vec::new() |
@@ -416,7 +413,7 @@ fn iterate_trait_method_candidates<T>( | |||
416 | 413 | ||
417 | fn iterate_inherent_methods<T>( | 414 | fn iterate_inherent_methods<T>( |
418 | self_ty: &Canonical<Ty>, | 415 | self_ty: &Canonical<Ty>, |
419 | db: &impl HirDatabase, | 416 | db: &dyn HirDatabase, |
420 | name: Option<&Name>, | 417 | name: Option<&Name>, |
421 | receiver_ty: Option<&Canonical<Ty>>, | 418 | receiver_ty: Option<&Canonical<Ty>>, |
422 | krate: CrateId, | 419 | krate: CrateId, |
@@ -449,7 +446,7 @@ fn iterate_inherent_methods<T>( | |||
449 | 446 | ||
450 | /// Returns the self type for the index trait call. | 447 | /// Returns the self type for the index trait call. |
451 | pub fn resolve_indexing_op( | 448 | pub fn resolve_indexing_op( |
452 | db: &impl HirDatabase, | 449 | db: &dyn HirDatabase, |
453 | ty: &Canonical<Ty>, | 450 | ty: &Canonical<Ty>, |
454 | env: Arc<TraitEnvironment>, | 451 | env: Arc<TraitEnvironment>, |
455 | krate: CrateId, | 452 | krate: CrateId, |
@@ -467,7 +464,7 @@ pub fn resolve_indexing_op( | |||
467 | } | 464 | } |
468 | 465 | ||
469 | fn is_valid_candidate( | 466 | fn is_valid_candidate( |
470 | db: &impl HirDatabase, | 467 | db: &dyn HirDatabase, |
471 | name: Option<&Name>, | 468 | name: Option<&Name>, |
472 | receiver_ty: Option<&Canonical<Ty>>, | 469 | receiver_ty: Option<&Canonical<Ty>>, |
473 | item: AssocItemId, | 470 | item: AssocItemId, |
@@ -504,7 +501,7 @@ fn is_valid_candidate( | |||
504 | } | 501 | } |
505 | 502 | ||
506 | pub(crate) fn inherent_impl_substs( | 503 | pub(crate) fn inherent_impl_substs( |
507 | db: &impl HirDatabase, | 504 | db: &dyn HirDatabase, |
508 | impl_id: ImplId, | 505 | impl_id: ImplId, |
509 | self_ty: &Canonical<Ty>, | 506 | self_ty: &Canonical<Ty>, |
510 | ) -> Option<Substs> { | 507 | ) -> Option<Substs> { |
@@ -544,11 +541,11 @@ fn fallback_bound_vars(s: Substs, num_vars_to_keep: usize) -> Substs { | |||
544 | } | 541 | } |
545 | 542 | ||
546 | fn transform_receiver_ty( | 543 | fn transform_receiver_ty( |
547 | db: &impl HirDatabase, | 544 | db: &dyn HirDatabase, |
548 | function_id: FunctionId, | 545 | function_id: FunctionId, |
549 | self_ty: &Canonical<Ty>, | 546 | self_ty: &Canonical<Ty>, |
550 | ) -> Option<Ty> { | 547 | ) -> Option<Ty> { |
551 | let substs = match function_id.lookup(db).container { | 548 | let substs = match function_id.lookup(db.upcast()).container { |
552 | AssocContainerId::TraitId(_) => Substs::build_for_def(db, function_id) | 549 | AssocContainerId::TraitId(_) => Substs::build_for_def(db, function_id) |
553 | .push(self_ty.value.clone()) | 550 | .push(self_ty.value.clone()) |
554 | .fill_with_unknown() | 551 | .fill_with_unknown() |
@@ -562,7 +559,7 @@ fn transform_receiver_ty( | |||
562 | 559 | ||
563 | pub fn implements_trait( | 560 | pub fn implements_trait( |
564 | ty: &Canonical<Ty>, | 561 | ty: &Canonical<Ty>, |
565 | db: &impl HirDatabase, | 562 | db: &dyn HirDatabase, |
566 | env: Arc<TraitEnvironment>, | 563 | env: Arc<TraitEnvironment>, |
567 | krate: CrateId, | 564 | krate: CrateId, |
568 | trait_: TraitId, | 565 | trait_: TraitId, |
@@ -581,7 +578,7 @@ pub fn implements_trait( | |||
581 | /// This creates Substs for a trait with the given Self type and type variables | 578 | /// This creates Substs for a trait with the given Self type and type variables |
582 | /// for all other parameters, to query Chalk with it. | 579 | /// for all other parameters, to query Chalk with it. |
583 | fn generic_implements_goal( | 580 | fn generic_implements_goal( |
584 | db: &impl HirDatabase, | 581 | db: &dyn HirDatabase, |
585 | env: Arc<TraitEnvironment>, | 582 | env: Arc<TraitEnvironment>, |
586 | trait_: TraitId, | 583 | trait_: TraitId, |
587 | self_ty: Canonical<Ty>, | 584 | self_ty: Canonical<Ty>, |
@@ -598,7 +595,7 @@ fn generic_implements_goal( | |||
598 | } | 595 | } |
599 | 596 | ||
600 | fn autoderef_method_receiver( | 597 | fn autoderef_method_receiver( |
601 | db: &impl HirDatabase, | 598 | db: &dyn HirDatabase, |
602 | krate: CrateId, | 599 | krate: CrateId, |
603 | ty: InEnvironment<Canonical<Ty>>, | 600 | ty: InEnvironment<Canonical<Ty>>, |
604 | ) -> Vec<Canonical<Ty>> { | 601 | ) -> Vec<Canonical<Ty>> { |
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index 0be2fea4b..5bbeabf51 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs | |||
@@ -6,8 +6,10 @@ use std::{ | |||
6 | }; | 6 | }; |
7 | 7 | ||
8 | use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId, ModuleId}; | 8 | use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId, ModuleId}; |
9 | use hir_expand::diagnostics::DiagnosticSink; | 9 | use hir_expand::{db::AstDatabase, diagnostics::DiagnosticSink}; |
10 | use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase}; | 10 | use ra_db::{ |
11 | salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase, Upcast, | ||
12 | }; | ||
11 | 13 | ||
12 | use crate::{db::HirDatabase, expr::ExprValidator}; | 14 | use crate::{db::HirDatabase, expr::ExprValidator}; |
13 | 15 | ||
@@ -25,6 +27,18 @@ pub struct TestDB { | |||
25 | runtime: salsa::Runtime<TestDB>, | 27 | runtime: salsa::Runtime<TestDB>, |
26 | } | 28 | } |
27 | 29 | ||
30 | impl Upcast<dyn AstDatabase> for TestDB { | ||
31 | fn upcast(&self) -> &(dyn AstDatabase + 'static) { | ||
32 | &*self | ||
33 | } | ||
34 | } | ||
35 | |||
36 | impl Upcast<dyn DefDatabase> for TestDB { | ||
37 | fn upcast(&self) -> &(dyn DefDatabase + 'static) { | ||
38 | &*self | ||
39 | } | ||
40 | } | ||
41 | |||
28 | impl salsa::Database for TestDB { | 42 | impl salsa::Database for TestDB { |
29 | fn salsa_runtime(&self) -> &salsa::Runtime<TestDB> { | 43 | fn salsa_runtime(&self) -> &salsa::Runtime<TestDB> { |
30 | &self.runtime | 44 | &self.runtime |
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 6e1c8e42a..a1ca33c98 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs | |||
@@ -24,8 +24,8 @@ const CHALK_SOLVER_MAX_SIZE: usize = 10; | |||
24 | const CHALK_SOLVER_FUEL: i32 = 100; | 24 | const CHALK_SOLVER_FUEL: i32 = 100; |
25 | 25 | ||
26 | #[derive(Debug, Copy, Clone)] | 26 | #[derive(Debug, Copy, Clone)] |
27 | struct ChalkContext<'a, DB> { | 27 | struct ChalkContext<'a> { |
28 | db: &'a DB, | 28 | db: &'a dyn HirDatabase, |
29 | krate: CrateId, | 29 | krate: CrateId, |
30 | } | 30 | } |
31 | 31 | ||
@@ -37,7 +37,7 @@ fn create_chalk_solver() -> chalk_solve::Solver<Interner> { | |||
37 | 37 | ||
38 | /// Collects impls for the given trait in the whole dependency tree of `krate`. | 38 | /// Collects impls for the given trait in the whole dependency tree of `krate`. |
39 | pub(crate) fn impls_for_trait_query( | 39 | pub(crate) fn impls_for_trait_query( |
40 | db: &impl HirDatabase, | 40 | db: &dyn HirDatabase, |
41 | krate: CrateId, | 41 | krate: CrateId, |
42 | trait_: TraitId, | 42 | trait_: TraitId, |
43 | ) -> Arc<[ImplId]> { | 43 | ) -> Arc<[ImplId]> { |
@@ -136,7 +136,7 @@ impl TypeWalk for ProjectionPredicate { | |||
136 | 136 | ||
137 | /// Solve a trait goal using Chalk. | 137 | /// Solve a trait goal using Chalk. |
138 | pub(crate) fn trait_solve_query( | 138 | pub(crate) fn trait_solve_query( |
139 | db: &impl HirDatabase, | 139 | db: &dyn HirDatabase, |
140 | krate: CrateId, | 140 | krate: CrateId, |
141 | goal: Canonical<InEnvironment<Obligation>>, | 141 | goal: Canonical<InEnvironment<Obligation>>, |
142 | ) -> Option<Solution> { | 142 | ) -> Option<Solution> { |
@@ -163,7 +163,7 @@ pub(crate) fn trait_solve_query( | |||
163 | } | 163 | } |
164 | 164 | ||
165 | fn solve( | 165 | fn solve( |
166 | db: &impl HirDatabase, | 166 | db: &dyn HirDatabase, |
167 | krate: CrateId, | 167 | krate: CrateId, |
168 | goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<Interner>>>, | 168 | goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<Interner>>>, |
169 | ) -> Option<chalk_solve::Solution<Interner>> { | 169 | ) -> Option<chalk_solve::Solution<Interner>> { |
@@ -188,7 +188,7 @@ fn solve( | |||
188 | } | 188 | } |
189 | 189 | ||
190 | fn solution_from_chalk( | 190 | fn solution_from_chalk( |
191 | db: &impl HirDatabase, | 191 | db: &dyn HirDatabase, |
192 | solution: chalk_solve::Solution<Interner>, | 192 | solution: chalk_solve::Solution<Interner>, |
193 | ) -> Solution { | 193 | ) -> Solution { |
194 | let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| { | 194 | let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| { |
diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index 03f9b4e27..73e3c5c78 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs | |||
@@ -26,7 +26,7 @@ pub(super) struct BuiltinImplAssocTyValueData { | |||
26 | } | 26 | } |
27 | 27 | ||
28 | pub(super) fn get_builtin_impls( | 28 | pub(super) fn get_builtin_impls( |
29 | db: &impl HirDatabase, | 29 | db: &dyn HirDatabase, |
30 | krate: CrateId, | 30 | krate: CrateId, |
31 | ty: &Ty, | 31 | ty: &Ty, |
32 | // The first argument for the trait, if present | 32 | // The first argument for the trait, if present |
@@ -59,7 +59,7 @@ pub(super) fn get_builtin_impls( | |||
59 | } | 59 | } |
60 | 60 | ||
61 | fn get_builtin_unsize_impls( | 61 | fn get_builtin_unsize_impls( |
62 | db: &impl HirDatabase, | 62 | db: &dyn HirDatabase, |
63 | krate: CrateId, | 63 | krate: CrateId, |
64 | ty: &Ty, | 64 | ty: &Ty, |
65 | // The first argument for the trait, if present | 65 | // The first argument for the trait, if present |
@@ -79,7 +79,7 @@ fn get_builtin_unsize_impls( | |||
79 | // FIXME what about more complicated dyn tys with marker traits? | 79 | // FIXME what about more complicated dyn tys with marker traits? |
80 | if let Some(trait_ref) = ty.dyn_trait_ref() { | 80 | if let Some(trait_ref) = ty.dyn_trait_ref() { |
81 | if trait_ref.trait_ != target_trait.trait_ { | 81 | if trait_ref.trait_ != target_trait.trait_ { |
82 | let super_traits = all_super_traits(db, trait_ref.trait_); | 82 | let super_traits = all_super_traits(db.upcast(), trait_ref.trait_); |
83 | if super_traits.contains(&target_trait.trait_) { | 83 | if super_traits.contains(&target_trait.trait_) { |
84 | callback(Impl::UnsizeToSuperTraitObject(UnsizeToSuperTraitObjectData { | 84 | callback(Impl::UnsizeToSuperTraitObject(UnsizeToSuperTraitObjectData { |
85 | trait_: trait_ref.trait_, | 85 | trait_: trait_ref.trait_, |
@@ -94,7 +94,7 @@ fn get_builtin_unsize_impls( | |||
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | pub(super) fn impl_datum(db: &impl HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData { | 97 | pub(super) fn impl_datum(db: &dyn HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData { |
98 | match impl_ { | 98 | match impl_ { |
99 | Impl::ImplDef(_) => unreachable!(), | 99 | Impl::ImplDef(_) => unreachable!(), |
100 | Impl::ClosureFnTraitImpl(data) => closure_fn_trait_impl_datum(db, krate, data), | 100 | Impl::ClosureFnTraitImpl(data) => closure_fn_trait_impl_datum(db, krate, data), |
@@ -107,7 +107,7 @@ pub(super) fn impl_datum(db: &impl HirDatabase, krate: CrateId, impl_: Impl) -> | |||
107 | } | 107 | } |
108 | 108 | ||
109 | pub(super) fn associated_ty_value( | 109 | pub(super) fn associated_ty_value( |
110 | db: &impl HirDatabase, | 110 | db: &dyn HirDatabase, |
111 | krate: CrateId, | 111 | krate: CrateId, |
112 | data: AssocTyValue, | 112 | data: AssocTyValue, |
113 | ) -> BuiltinImplAssocTyValueData { | 113 | ) -> BuiltinImplAssocTyValueData { |
@@ -122,7 +122,7 @@ pub(super) fn associated_ty_value( | |||
122 | // Closure Fn trait impls | 122 | // Closure Fn trait impls |
123 | 123 | ||
124 | fn check_closure_fn_trait_impl_prerequisites( | 124 | fn check_closure_fn_trait_impl_prerequisites( |
125 | db: &impl HirDatabase, | 125 | db: &dyn HirDatabase, |
126 | krate: CrateId, | 126 | krate: CrateId, |
127 | data: super::ClosureFnTraitImplData, | 127 | data: super::ClosureFnTraitImplData, |
128 | ) -> bool { | 128 | ) -> bool { |
@@ -143,7 +143,7 @@ fn check_closure_fn_trait_impl_prerequisites( | |||
143 | } | 143 | } |
144 | 144 | ||
145 | fn closure_fn_trait_impl_datum( | 145 | fn closure_fn_trait_impl_datum( |
146 | db: &impl HirDatabase, | 146 | db: &dyn HirDatabase, |
147 | krate: CrateId, | 147 | krate: CrateId, |
148 | data: super::ClosureFnTraitImplData, | 148 | data: super::ClosureFnTraitImplData, |
149 | ) -> BuiltinImplData { | 149 | ) -> BuiltinImplData { |
@@ -189,7 +189,7 @@ fn closure_fn_trait_impl_datum( | |||
189 | } | 189 | } |
190 | 190 | ||
191 | fn closure_fn_trait_output_assoc_ty_value( | 191 | fn closure_fn_trait_output_assoc_ty_value( |
192 | db: &impl HirDatabase, | 192 | db: &dyn HirDatabase, |
193 | krate: CrateId, | 193 | krate: CrateId, |
194 | data: super::ClosureFnTraitImplData, | 194 | data: super::ClosureFnTraitImplData, |
195 | ) -> BuiltinImplAssocTyValueData { | 195 | ) -> BuiltinImplAssocTyValueData { |
@@ -223,17 +223,17 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
223 | 223 | ||
224 | // Array unsizing | 224 | // Array unsizing |
225 | 225 | ||
226 | fn check_unsize_impl_prerequisites(db: &impl HirDatabase, krate: CrateId) -> bool { | 226 | fn check_unsize_impl_prerequisites(db: &dyn HirDatabase, krate: CrateId) -> bool { |
227 | // the Unsize trait needs to exist and have two type parameters (Self and T) | 227 | // the Unsize trait needs to exist and have two type parameters (Self and T) |
228 | let unsize_trait = match get_unsize_trait(db, krate) { | 228 | let unsize_trait = match get_unsize_trait(db, krate) { |
229 | Some(t) => t, | 229 | Some(t) => t, |
230 | None => return false, | 230 | None => return false, |
231 | }; | 231 | }; |
232 | let generic_params = generics(db, unsize_trait.into()); | 232 | let generic_params = generics(db.upcast(), unsize_trait.into()); |
233 | generic_params.len() == 2 | 233 | generic_params.len() == 2 |
234 | } | 234 | } |
235 | 235 | ||
236 | fn array_unsize_impl_datum(db: &impl HirDatabase, krate: CrateId) -> BuiltinImplData { | 236 | fn array_unsize_impl_datum(db: &dyn HirDatabase, krate: CrateId) -> BuiltinImplData { |
237 | // impl<T> Unsize<[T]> for [T; _] | 237 | // impl<T> Unsize<[T]> for [T; _] |
238 | // (this can be a single impl because we don't distinguish array sizes currently) | 238 | // (this can be a single impl because we don't distinguish array sizes currently) |
239 | 239 | ||
@@ -260,7 +260,7 @@ fn array_unsize_impl_datum(db: &impl HirDatabase, krate: CrateId) -> BuiltinImpl | |||
260 | // Trait object unsizing | 260 | // Trait object unsizing |
261 | 261 | ||
262 | fn trait_object_unsize_impl_datum( | 262 | fn trait_object_unsize_impl_datum( |
263 | db: &impl HirDatabase, | 263 | db: &dyn HirDatabase, |
264 | krate: CrateId, | 264 | krate: CrateId, |
265 | trait_: TraitId, | 265 | trait_: TraitId, |
266 | ) -> BuiltinImplData { | 266 | ) -> BuiltinImplData { |
@@ -295,7 +295,7 @@ fn trait_object_unsize_impl_datum( | |||
295 | } | 295 | } |
296 | 296 | ||
297 | fn super_trait_object_unsize_impl_datum( | 297 | fn super_trait_object_unsize_impl_datum( |
298 | db: &impl HirDatabase, | 298 | db: &dyn HirDatabase, |
299 | krate: CrateId, | 299 | krate: CrateId, |
300 | data: UnsizeToSuperTraitObjectData, | 300 | data: UnsizeToSuperTraitObjectData, |
301 | ) -> BuiltinImplData { | 301 | ) -> BuiltinImplData { |
@@ -313,7 +313,7 @@ fn super_trait_object_unsize_impl_datum( | |||
313 | let self_bounds = vec![GenericPredicate::Implemented(self_trait_ref.clone())]; | 313 | let self_bounds = vec![GenericPredicate::Implemented(self_trait_ref.clone())]; |
314 | 314 | ||
315 | // we need to go from our trait to the super trait, substituting type parameters | 315 | // we need to go from our trait to the super trait, substituting type parameters |
316 | let path = crate::utils::find_super_trait_path(db, data.trait_, data.super_trait); | 316 | let path = crate::utils::find_super_trait_path(db.upcast(), data.trait_, data.super_trait); |
317 | 317 | ||
318 | let mut current_trait_ref = self_trait_ref; | 318 | let mut current_trait_ref = self_trait_ref; |
319 | for t in path.into_iter().skip(1) { | 319 | for t in path.into_iter().skip(1) { |
@@ -344,11 +344,7 @@ fn super_trait_object_unsize_impl_datum( | |||
344 | BuiltinImplData { num_vars, trait_ref, where_clauses: Vec::new(), assoc_ty_values: Vec::new() } | 344 | BuiltinImplData { num_vars, trait_ref, where_clauses: Vec::new(), assoc_ty_values: Vec::new() } |
345 | } | 345 | } |
346 | 346 | ||
347 | fn get_fn_trait( | 347 | fn get_fn_trait(db: &dyn HirDatabase, krate: CrateId, fn_trait: super::FnTrait) -> Option<TraitId> { |
348 | db: &impl HirDatabase, | ||
349 | krate: CrateId, | ||
350 | fn_trait: super::FnTrait, | ||
351 | ) -> Option<TraitId> { | ||
352 | let target = db.lang_item(krate, fn_trait.lang_item_name().into())?; | 348 | let target = db.lang_item(krate, fn_trait.lang_item_name().into())?; |
353 | match target { | 349 | match target { |
354 | LangItemTarget::TraitId(t) => Some(t), | 350 | LangItemTarget::TraitId(t) => Some(t), |
@@ -356,7 +352,7 @@ fn get_fn_trait( | |||
356 | } | 352 | } |
357 | } | 353 | } |
358 | 354 | ||
359 | fn get_unsize_trait(db: &impl HirDatabase, krate: CrateId) -> Option<TraitId> { | 355 | fn get_unsize_trait(db: &dyn HirDatabase, krate: CrateId) -> Option<TraitId> { |
360 | let target = db.lang_item(krate, "unsize".into())?; | 356 | let target = db.lang_item(krate, "unsize".into())?; |
361 | match target { | 357 | match target { |
362 | LangItemTarget::TraitId(t) => Some(t), | 358 | LangItemTarget::TraitId(t) => Some(t), |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 62509bc29..943d5f125 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -127,11 +127,11 @@ pub type AssociatedTyValue = chalk_rust_ir::AssociatedTyValue<Interner>; | |||
127 | 127 | ||
128 | pub(super) trait ToChalk { | 128 | pub(super) trait ToChalk { |
129 | type Chalk; | 129 | type Chalk; |
130 | fn to_chalk(self, db: &impl HirDatabase) -> Self::Chalk; | 130 | fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk; |
131 | fn from_chalk(db: &impl HirDatabase, chalk: Self::Chalk) -> Self; | 131 | fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self; |
132 | } | 132 | } |
133 | 133 | ||
134 | pub(super) fn from_chalk<T, ChalkT>(db: &impl HirDatabase, chalk: ChalkT) -> T | 134 | pub(super) fn from_chalk<T, ChalkT>(db: &dyn HirDatabase, chalk: ChalkT) -> T |
135 | where | 135 | where |
136 | T: ToChalk<Chalk = ChalkT>, | 136 | T: ToChalk<Chalk = ChalkT>, |
137 | { | 137 | { |
@@ -140,7 +140,7 @@ where | |||
140 | 140 | ||
141 | impl ToChalk for Ty { | 141 | impl ToChalk for Ty { |
142 | type Chalk = chalk_ir::Ty<Interner>; | 142 | type Chalk = chalk_ir::Ty<Interner>; |
143 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Ty<Interner> { | 143 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty<Interner> { |
144 | match self { | 144 | match self { |
145 | Ty::Apply(apply_ty) => { | 145 | Ty::Apply(apply_ty) => { |
146 | let name = apply_ty.ctor.to_chalk(db); | 146 | let name = apply_ty.ctor.to_chalk(db); |
@@ -179,7 +179,7 @@ impl ToChalk for Ty { | |||
179 | } | 179 | } |
180 | } | 180 | } |
181 | } | 181 | } |
182 | fn from_chalk(db: &impl HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { | 182 | fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self { |
183 | match chalk.data().clone() { | 183 | match chalk.data().clone() { |
184 | chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { | 184 | chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { |
185 | TypeName::Error => Ty::Unknown, | 185 | TypeName::Error => Ty::Unknown, |
@@ -217,11 +217,11 @@ impl ToChalk for Ty { | |||
217 | impl ToChalk for Substs { | 217 | impl ToChalk for Substs { |
218 | type Chalk = chalk_ir::Substitution<Interner>; | 218 | type Chalk = chalk_ir::Substitution<Interner>; |
219 | 219 | ||
220 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Substitution<Interner> { | 220 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { |
221 | chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db))) | 221 | chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db))) |
222 | } | 222 | } |
223 | 223 | ||
224 | fn from_chalk(db: &impl HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs { | 224 | fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs { |
225 | let tys = parameters | 225 | let tys = parameters |
226 | .into_iter() | 226 | .into_iter() |
227 | .map(|p| match p.ty() { | 227 | .map(|p| match p.ty() { |
@@ -236,13 +236,13 @@ impl ToChalk for Substs { | |||
236 | impl ToChalk for TraitRef { | 236 | impl ToChalk for TraitRef { |
237 | type Chalk = chalk_ir::TraitRef<Interner>; | 237 | type Chalk = chalk_ir::TraitRef<Interner>; |
238 | 238 | ||
239 | fn to_chalk(self: TraitRef, db: &impl HirDatabase) -> chalk_ir::TraitRef<Interner> { | 239 | fn to_chalk(self: TraitRef, db: &dyn HirDatabase) -> chalk_ir::TraitRef<Interner> { |
240 | let trait_id = self.trait_.to_chalk(db); | 240 | let trait_id = self.trait_.to_chalk(db); |
241 | let substitution = self.substs.to_chalk(db); | 241 | let substitution = self.substs.to_chalk(db); |
242 | chalk_ir::TraitRef { trait_id, substitution } | 242 | chalk_ir::TraitRef { trait_id, substitution } |
243 | } | 243 | } |
244 | 244 | ||
245 | fn from_chalk(db: &impl HirDatabase, trait_ref: chalk_ir::TraitRef<Interner>) -> Self { | 245 | fn from_chalk(db: &dyn HirDatabase, trait_ref: chalk_ir::TraitRef<Interner>) -> Self { |
246 | let trait_ = from_chalk(db, trait_ref.trait_id); | 246 | let trait_ = from_chalk(db, trait_ref.trait_id); |
247 | let substs = from_chalk(db, trait_ref.substitution); | 247 | let substs = from_chalk(db, trait_ref.substitution); |
248 | TraitRef { trait_, substs } | 248 | TraitRef { trait_, substs } |
@@ -252,11 +252,11 @@ impl ToChalk for TraitRef { | |||
252 | impl ToChalk for hir_def::TraitId { | 252 | impl ToChalk for hir_def::TraitId { |
253 | type Chalk = TraitId; | 253 | type Chalk = TraitId; |
254 | 254 | ||
255 | fn to_chalk(self, _db: &impl HirDatabase) -> TraitId { | 255 | fn to_chalk(self, _db: &dyn HirDatabase) -> TraitId { |
256 | chalk_ir::TraitId(self.as_intern_id()) | 256 | chalk_ir::TraitId(self.as_intern_id()) |
257 | } | 257 | } |
258 | 258 | ||
259 | fn from_chalk(_db: &impl HirDatabase, trait_id: TraitId) -> hir_def::TraitId { | 259 | fn from_chalk(_db: &dyn HirDatabase, trait_id: TraitId) -> hir_def::TraitId { |
260 | InternKey::from_intern_id(trait_id.0) | 260 | InternKey::from_intern_id(trait_id.0) |
261 | } | 261 | } |
262 | } | 262 | } |
@@ -264,7 +264,7 @@ impl ToChalk for hir_def::TraitId { | |||
264 | impl ToChalk for TypeCtor { | 264 | impl ToChalk for TypeCtor { |
265 | type Chalk = TypeName<Interner>; | 265 | type Chalk = TypeName<Interner>; |
266 | 266 | ||
267 | fn to_chalk(self, db: &impl HirDatabase) -> TypeName<Interner> { | 267 | fn to_chalk(self, db: &dyn HirDatabase) -> TypeName<Interner> { |
268 | match self { | 268 | match self { |
269 | TypeCtor::AssociatedType(type_alias) => { | 269 | TypeCtor::AssociatedType(type_alias) => { |
270 | let type_id = type_alias.to_chalk(db); | 270 | let type_id = type_alias.to_chalk(db); |
@@ -278,7 +278,7 @@ impl ToChalk for TypeCtor { | |||
278 | } | 278 | } |
279 | } | 279 | } |
280 | 280 | ||
281 | fn from_chalk(db: &impl HirDatabase, type_name: TypeName<Interner>) -> TypeCtor { | 281 | fn from_chalk(db: &dyn HirDatabase, type_name: TypeName<Interner>) -> TypeCtor { |
282 | match type_name { | 282 | match type_name { |
283 | TypeName::Struct(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), | 283 | TypeName::Struct(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), |
284 | TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), | 284 | TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), |
@@ -293,11 +293,11 @@ impl ToChalk for TypeCtor { | |||
293 | impl ToChalk for Impl { | 293 | impl ToChalk for Impl { |
294 | type Chalk = ImplId; | 294 | type Chalk = ImplId; |
295 | 295 | ||
296 | fn to_chalk(self, db: &impl HirDatabase) -> ImplId { | 296 | fn to_chalk(self, db: &dyn HirDatabase) -> ImplId { |
297 | db.intern_chalk_impl(self).into() | 297 | db.intern_chalk_impl(self).into() |
298 | } | 298 | } |
299 | 299 | ||
300 | fn from_chalk(db: &impl HirDatabase, impl_id: ImplId) -> Impl { | 300 | fn from_chalk(db: &dyn HirDatabase, impl_id: ImplId) -> Impl { |
301 | db.lookup_intern_chalk_impl(impl_id.into()) | 301 | db.lookup_intern_chalk_impl(impl_id.into()) |
302 | } | 302 | } |
303 | } | 303 | } |
@@ -305,11 +305,11 @@ impl ToChalk for Impl { | |||
305 | impl ToChalk for TypeAliasId { | 305 | impl ToChalk for TypeAliasId { |
306 | type Chalk = AssocTypeId; | 306 | type Chalk = AssocTypeId; |
307 | 307 | ||
308 | fn to_chalk(self, _db: &impl HirDatabase) -> AssocTypeId { | 308 | fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId { |
309 | chalk_ir::AssocTypeId(self.as_intern_id()) | 309 | chalk_ir::AssocTypeId(self.as_intern_id()) |
310 | } | 310 | } |
311 | 311 | ||
312 | fn from_chalk(_db: &impl HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId { | 312 | fn from_chalk(_db: &dyn HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId { |
313 | InternKey::from_intern_id(type_alias_id.0) | 313 | InternKey::from_intern_id(type_alias_id.0) |
314 | } | 314 | } |
315 | } | 315 | } |
@@ -317,11 +317,11 @@ impl ToChalk for TypeAliasId { | |||
317 | impl ToChalk for AssocTyValue { | 317 | impl ToChalk for AssocTyValue { |
318 | type Chalk = AssociatedTyValueId; | 318 | type Chalk = AssociatedTyValueId; |
319 | 319 | ||
320 | fn to_chalk(self, db: &impl HirDatabase) -> AssociatedTyValueId { | 320 | fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValueId { |
321 | db.intern_assoc_ty_value(self).into() | 321 | db.intern_assoc_ty_value(self).into() |
322 | } | 322 | } |
323 | 323 | ||
324 | fn from_chalk(db: &impl HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue { | 324 | fn from_chalk(db: &dyn HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue { |
325 | db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) | 325 | db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) |
326 | } | 326 | } |
327 | } | 327 | } |
@@ -329,7 +329,7 @@ impl ToChalk for AssocTyValue { | |||
329 | impl ToChalk for GenericPredicate { | 329 | impl ToChalk for GenericPredicate { |
330 | type Chalk = chalk_ir::QuantifiedWhereClause<Interner>; | 330 | type Chalk = chalk_ir::QuantifiedWhereClause<Interner>; |
331 | 331 | ||
332 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> { | 332 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause<Interner> { |
333 | match self { | 333 | match self { |
334 | GenericPredicate::Implemented(trait_ref) => { | 334 | GenericPredicate::Implemented(trait_ref) => { |
335 | make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0) | 335 | make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0) |
@@ -346,7 +346,7 @@ impl ToChalk for GenericPredicate { | |||
346 | } | 346 | } |
347 | 347 | ||
348 | fn from_chalk( | 348 | fn from_chalk( |
349 | db: &impl HirDatabase, | 349 | db: &dyn HirDatabase, |
350 | where_clause: chalk_ir::QuantifiedWhereClause<Interner>, | 350 | where_clause: chalk_ir::QuantifiedWhereClause<Interner>, |
351 | ) -> GenericPredicate { | 351 | ) -> GenericPredicate { |
352 | match where_clause.value { | 352 | match where_clause.value { |
@@ -365,7 +365,7 @@ impl ToChalk for GenericPredicate { | |||
365 | impl ToChalk for ProjectionTy { | 365 | impl ToChalk for ProjectionTy { |
366 | type Chalk = chalk_ir::AliasTy<Interner>; | 366 | type Chalk = chalk_ir::AliasTy<Interner>; |
367 | 367 | ||
368 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::AliasTy<Interner> { | 368 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::AliasTy<Interner> { |
369 | chalk_ir::AliasTy { | 369 | chalk_ir::AliasTy { |
370 | associated_ty_id: self.associated_ty.to_chalk(db), | 370 | associated_ty_id: self.associated_ty.to_chalk(db), |
371 | substitution: self.parameters.to_chalk(db), | 371 | substitution: self.parameters.to_chalk(db), |
@@ -373,7 +373,7 @@ impl ToChalk for ProjectionTy { | |||
373 | } | 373 | } |
374 | 374 | ||
375 | fn from_chalk( | 375 | fn from_chalk( |
376 | db: &impl HirDatabase, | 376 | db: &dyn HirDatabase, |
377 | projection_ty: chalk_ir::AliasTy<Interner>, | 377 | projection_ty: chalk_ir::AliasTy<Interner>, |
378 | ) -> ProjectionTy { | 378 | ) -> ProjectionTy { |
379 | ProjectionTy { | 379 | ProjectionTy { |
@@ -386,11 +386,11 @@ impl ToChalk for ProjectionTy { | |||
386 | impl ToChalk for super::ProjectionPredicate { | 386 | impl ToChalk for super::ProjectionPredicate { |
387 | type Chalk = chalk_ir::Normalize<Interner>; | 387 | type Chalk = chalk_ir::Normalize<Interner>; |
388 | 388 | ||
389 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Normalize<Interner> { | 389 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Normalize<Interner> { |
390 | chalk_ir::Normalize { alias: self.projection_ty.to_chalk(db), ty: self.ty.to_chalk(db) } | 390 | chalk_ir::Normalize { alias: self.projection_ty.to_chalk(db), ty: self.ty.to_chalk(db) } |
391 | } | 391 | } |
392 | 392 | ||
393 | fn from_chalk(_db: &impl HirDatabase, _normalize: chalk_ir::Normalize<Interner>) -> Self { | 393 | fn from_chalk(_db: &dyn HirDatabase, _normalize: chalk_ir::Normalize<Interner>) -> Self { |
394 | unimplemented!() | 394 | unimplemented!() |
395 | } | 395 | } |
396 | } | 396 | } |
@@ -398,14 +398,14 @@ impl ToChalk for super::ProjectionPredicate { | |||
398 | impl ToChalk for Obligation { | 398 | impl ToChalk for Obligation { |
399 | type Chalk = chalk_ir::DomainGoal<Interner>; | 399 | type Chalk = chalk_ir::DomainGoal<Interner>; |
400 | 400 | ||
401 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::DomainGoal<Interner> { | 401 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> { |
402 | match self { | 402 | match self { |
403 | Obligation::Trait(tr) => tr.to_chalk(db).cast(), | 403 | Obligation::Trait(tr) => tr.to_chalk(db).cast(), |
404 | Obligation::Projection(pr) => pr.to_chalk(db).cast(), | 404 | Obligation::Projection(pr) => pr.to_chalk(db).cast(), |
405 | } | 405 | } |
406 | } | 406 | } |
407 | 407 | ||
408 | fn from_chalk(_db: &impl HirDatabase, _goal: chalk_ir::DomainGoal<Interner>) -> Self { | 408 | fn from_chalk(_db: &dyn HirDatabase, _goal: chalk_ir::DomainGoal<Interner>) -> Self { |
409 | unimplemented!() | 409 | unimplemented!() |
410 | } | 410 | } |
411 | } | 411 | } |
@@ -416,13 +416,13 @@ where | |||
416 | { | 416 | { |
417 | type Chalk = chalk_ir::Canonical<T::Chalk>; | 417 | type Chalk = chalk_ir::Canonical<T::Chalk>; |
418 | 418 | ||
419 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Canonical<T::Chalk> { | 419 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical<T::Chalk> { |
420 | let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); | 420 | let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); |
421 | let value = self.value.to_chalk(db); | 421 | let value = self.value.to_chalk(db); |
422 | chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] } | 422 | chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] } |
423 | } | 423 | } |
424 | 424 | ||
425 | fn from_chalk(db: &impl HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { | 425 | fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { |
426 | Canonical { num_vars: canonical.binders.len(), value: from_chalk(db, canonical.value) } | 426 | Canonical { num_vars: canonical.binders.len(), value: from_chalk(db, canonical.value) } |
427 | } | 427 | } |
428 | } | 428 | } |
@@ -430,7 +430,7 @@ where | |||
430 | impl ToChalk for Arc<super::TraitEnvironment> { | 430 | impl ToChalk for Arc<super::TraitEnvironment> { |
431 | type Chalk = chalk_ir::Environment<Interner>; | 431 | type Chalk = chalk_ir::Environment<Interner>; |
432 | 432 | ||
433 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Environment<Interner> { | 433 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Environment<Interner> { |
434 | let mut clauses = Vec::new(); | 434 | let mut clauses = Vec::new(); |
435 | for pred in &self.predicates { | 435 | for pred in &self.predicates { |
436 | if pred.is_error() { | 436 | if pred.is_error() { |
@@ -445,7 +445,7 @@ impl ToChalk for Arc<super::TraitEnvironment> { | |||
445 | } | 445 | } |
446 | 446 | ||
447 | fn from_chalk( | 447 | fn from_chalk( |
448 | _db: &impl HirDatabase, | 448 | _db: &dyn HirDatabase, |
449 | _env: chalk_ir::Environment<Interner>, | 449 | _env: chalk_ir::Environment<Interner>, |
450 | ) -> Arc<super::TraitEnvironment> { | 450 | ) -> Arc<super::TraitEnvironment> { |
451 | unimplemented!() | 451 | unimplemented!() |
@@ -458,7 +458,7 @@ where | |||
458 | { | 458 | { |
459 | type Chalk = chalk_ir::InEnvironment<T::Chalk>; | 459 | type Chalk = chalk_ir::InEnvironment<T::Chalk>; |
460 | 460 | ||
461 | fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { | 461 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment<T::Chalk> { |
462 | chalk_ir::InEnvironment { | 462 | chalk_ir::InEnvironment { |
463 | environment: self.environment.to_chalk(db), | 463 | environment: self.environment.to_chalk(db), |
464 | goal: self.value.to_chalk(db), | 464 | goal: self.value.to_chalk(db), |
@@ -466,7 +466,7 @@ where | |||
466 | } | 466 | } |
467 | 467 | ||
468 | fn from_chalk( | 468 | fn from_chalk( |
469 | db: &impl HirDatabase, | 469 | db: &dyn HirDatabase, |
470 | in_env: chalk_ir::InEnvironment<T::Chalk>, | 470 | in_env: chalk_ir::InEnvironment<T::Chalk>, |
471 | ) -> super::InEnvironment<T> { | 471 | ) -> super::InEnvironment<T> { |
472 | super::InEnvironment { | 472 | super::InEnvironment { |
@@ -479,7 +479,7 @@ where | |||
479 | impl ToChalk for builtin::BuiltinImplData { | 479 | impl ToChalk for builtin::BuiltinImplData { |
480 | type Chalk = ImplDatum; | 480 | type Chalk = ImplDatum; |
481 | 481 | ||
482 | fn to_chalk(self, db: &impl HirDatabase) -> ImplDatum { | 482 | fn to_chalk(self, db: &dyn HirDatabase) -> ImplDatum { |
483 | let impl_type = chalk_rust_ir::ImplType::External; | 483 | let impl_type = chalk_rust_ir::ImplType::External; |
484 | let where_clauses = self.where_clauses.into_iter().map(|w| w.to_chalk(db)).collect(); | 484 | let where_clauses = self.where_clauses.into_iter().map(|w| w.to_chalk(db)).collect(); |
485 | 485 | ||
@@ -495,7 +495,7 @@ impl ToChalk for builtin::BuiltinImplData { | |||
495 | } | 495 | } |
496 | } | 496 | } |
497 | 497 | ||
498 | fn from_chalk(_db: &impl HirDatabase, _data: ImplDatum) -> Self { | 498 | fn from_chalk(_db: &dyn HirDatabase, _data: ImplDatum) -> Self { |
499 | unimplemented!() | 499 | unimplemented!() |
500 | } | 500 | } |
501 | } | 501 | } |
@@ -503,7 +503,7 @@ impl ToChalk for builtin::BuiltinImplData { | |||
503 | impl ToChalk for builtin::BuiltinImplAssocTyValueData { | 503 | impl ToChalk for builtin::BuiltinImplAssocTyValueData { |
504 | type Chalk = AssociatedTyValue; | 504 | type Chalk = AssociatedTyValue; |
505 | 505 | ||
506 | fn to_chalk(self, db: &impl HirDatabase) -> AssociatedTyValue { | 506 | fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue { |
507 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: self.value.to_chalk(db) }; | 507 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: self.value.to_chalk(db) }; |
508 | 508 | ||
509 | chalk_rust_ir::AssociatedTyValue { | 509 | chalk_rust_ir::AssociatedTyValue { |
@@ -514,7 +514,7 @@ impl ToChalk for builtin::BuiltinImplAssocTyValueData { | |||
514 | } | 514 | } |
515 | 515 | ||
516 | fn from_chalk( | 516 | fn from_chalk( |
517 | _db: &impl HirDatabase, | 517 | _db: &dyn HirDatabase, |
518 | _data: AssociatedTyValue, | 518 | _data: AssociatedTyValue, |
519 | ) -> builtin::BuiltinImplAssocTyValueData { | 519 | ) -> builtin::BuiltinImplAssocTyValueData { |
520 | unimplemented!() | 520 | unimplemented!() |
@@ -529,7 +529,7 @@ fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> { | |||
529 | } | 529 | } |
530 | 530 | ||
531 | fn convert_where_clauses( | 531 | fn convert_where_clauses( |
532 | db: &impl HirDatabase, | 532 | db: &dyn HirDatabase, |
533 | def: GenericDefId, | 533 | def: GenericDefId, |
534 | substs: &Substs, | 534 | substs: &Substs, |
535 | ) -> Vec<chalk_ir::QuantifiedWhereClause<Interner>> { | 535 | ) -> Vec<chalk_ir::QuantifiedWhereClause<Interner>> { |
@@ -545,10 +545,7 @@ fn convert_where_clauses( | |||
545 | result | 545 | result |
546 | } | 546 | } |
547 | 547 | ||
548 | impl<'a, DB> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a, DB> | 548 | impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { |
549 | where | ||
550 | DB: HirDatabase, | ||
551 | { | ||
552 | fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> { | 549 | fn associated_ty_data(&self, id: AssocTypeId) -> Arc<AssociatedTyDatum> { |
553 | self.db.associated_ty_data(id) | 550 | self.db.associated_ty_data(id) |
554 | } | 551 | } |
@@ -618,16 +615,16 @@ where | |||
618 | } | 615 | } |
619 | 616 | ||
620 | pub(crate) fn associated_ty_data_query( | 617 | pub(crate) fn associated_ty_data_query( |
621 | db: &impl HirDatabase, | 618 | db: &dyn HirDatabase, |
622 | id: AssocTypeId, | 619 | id: AssocTypeId, |
623 | ) -> Arc<AssociatedTyDatum> { | 620 | ) -> Arc<AssociatedTyDatum> { |
624 | debug!("associated_ty_data {:?}", id); | 621 | debug!("associated_ty_data {:?}", id); |
625 | let type_alias: TypeAliasId = from_chalk(db, id); | 622 | let type_alias: TypeAliasId = from_chalk(db, id); |
626 | let trait_ = match type_alias.lookup(db).container { | 623 | let trait_ = match type_alias.lookup(db.upcast()).container { |
627 | AssocContainerId::TraitId(t) => t, | 624 | AssocContainerId::TraitId(t) => t, |
628 | _ => panic!("associated type not in trait"), | 625 | _ => panic!("associated type not in trait"), |
629 | }; | 626 | }; |
630 | let generic_params = generics(db, type_alias.into()); | 627 | let generic_params = generics(db.upcast(), type_alias.into()); |
631 | let bound_data = chalk_rust_ir::AssociatedTyDatumBound { | 628 | let bound_data = chalk_rust_ir::AssociatedTyDatumBound { |
632 | // FIXME add bounds and where clauses | 629 | // FIXME add bounds and where clauses |
633 | bounds: vec![], | 630 | bounds: vec![], |
@@ -643,7 +640,7 @@ pub(crate) fn associated_ty_data_query( | |||
643 | } | 640 | } |
644 | 641 | ||
645 | pub(crate) fn trait_datum_query( | 642 | pub(crate) fn trait_datum_query( |
646 | db: &impl HirDatabase, | 643 | db: &dyn HirDatabase, |
647 | krate: CrateId, | 644 | krate: CrateId, |
648 | trait_id: TraitId, | 645 | trait_id: TraitId, |
649 | ) -> Arc<TraitDatum> { | 646 | ) -> Arc<TraitDatum> { |
@@ -651,11 +648,11 @@ pub(crate) fn trait_datum_query( | |||
651 | let trait_: hir_def::TraitId = from_chalk(db, trait_id); | 648 | let trait_: hir_def::TraitId = from_chalk(db, trait_id); |
652 | let trait_data = db.trait_data(trait_); | 649 | let trait_data = db.trait_data(trait_); |
653 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); | 650 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); |
654 | let generic_params = generics(db, trait_.into()); | 651 | let generic_params = generics(db.upcast(), trait_.into()); |
655 | let bound_vars = Substs::bound_vars(&generic_params); | 652 | let bound_vars = Substs::bound_vars(&generic_params); |
656 | let flags = chalk_rust_ir::TraitFlags { | 653 | let flags = chalk_rust_ir::TraitFlags { |
657 | auto: trait_data.auto, | 654 | auto: trait_data.auto, |
658 | upstream: trait_.lookup(db).container.module(db).krate != krate, | 655 | upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate != krate, |
659 | non_enumerable: true, | 656 | non_enumerable: true, |
660 | coinductive: false, // only relevant for Chalk testing | 657 | coinductive: false, // only relevant for Chalk testing |
661 | // FIXME set these flags correctly | 658 | // FIXME set these flags correctly |
@@ -676,7 +673,7 @@ pub(crate) fn trait_datum_query( | |||
676 | } | 673 | } |
677 | 674 | ||
678 | pub(crate) fn struct_datum_query( | 675 | pub(crate) fn struct_datum_query( |
679 | db: &impl HirDatabase, | 676 | db: &dyn HirDatabase, |
680 | krate: CrateId, | 677 | krate: CrateId, |
681 | struct_id: StructId, | 678 | struct_id: StructId, |
682 | ) -> Arc<StructDatum> { | 679 | ) -> Arc<StructDatum> { |
@@ -688,7 +685,7 @@ pub(crate) fn struct_datum_query( | |||
688 | let where_clauses = type_ctor | 685 | let where_clauses = type_ctor |
689 | .as_generic_def() | 686 | .as_generic_def() |
690 | .map(|generic_def| { | 687 | .map(|generic_def| { |
691 | let generic_params = generics(db, generic_def); | 688 | let generic_params = generics(db.upcast(), generic_def); |
692 | let bound_vars = Substs::bound_vars(&generic_params); | 689 | let bound_vars = Substs::bound_vars(&generic_params); |
693 | convert_where_clauses(db, generic_def, &bound_vars) | 690 | convert_where_clauses(db, generic_def, &bound_vars) |
694 | }) | 691 | }) |
@@ -708,7 +705,7 @@ pub(crate) fn struct_datum_query( | |||
708 | } | 705 | } |
709 | 706 | ||
710 | pub(crate) fn impl_datum_query( | 707 | pub(crate) fn impl_datum_query( |
711 | db: &impl HirDatabase, | 708 | db: &dyn HirDatabase, |
712 | krate: CrateId, | 709 | krate: CrateId, |
713 | impl_id: ImplId, | 710 | impl_id: ImplId, |
714 | ) -> Arc<ImplDatum> { | 711 | ) -> Arc<ImplDatum> { |
@@ -722,7 +719,7 @@ pub(crate) fn impl_datum_query( | |||
722 | } | 719 | } |
723 | 720 | ||
724 | fn impl_def_datum( | 721 | fn impl_def_datum( |
725 | db: &impl HirDatabase, | 722 | db: &dyn HirDatabase, |
726 | krate: CrateId, | 723 | krate: CrateId, |
727 | chalk_id: ImplId, | 724 | chalk_id: ImplId, |
728 | impl_id: hir_def::ImplId, | 725 | impl_id: hir_def::ImplId, |
@@ -734,10 +731,10 @@ fn impl_def_datum( | |||
734 | .value; | 731 | .value; |
735 | let impl_data = db.impl_data(impl_id); | 732 | let impl_data = db.impl_data(impl_id); |
736 | 733 | ||
737 | let generic_params = generics(db, impl_id.into()); | 734 | let generic_params = generics(db.upcast(), impl_id.into()); |
738 | let bound_vars = Substs::bound_vars(&generic_params); | 735 | let bound_vars = Substs::bound_vars(&generic_params); |
739 | let trait_ = trait_ref.trait_; | 736 | let trait_ = trait_ref.trait_; |
740 | let impl_type = if impl_id.lookup(db).container.module(db).krate == krate { | 737 | let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate == krate { |
741 | chalk_rust_ir::ImplType::Local | 738 | chalk_rust_ir::ImplType::Local |
742 | } else { | 739 | } else { |
743 | chalk_rust_ir::ImplType::External | 740 | chalk_rust_ir::ImplType::External |
@@ -786,7 +783,7 @@ fn impl_def_datum( | |||
786 | } | 783 | } |
787 | 784 | ||
788 | pub(crate) fn associated_ty_value_query( | 785 | pub(crate) fn associated_ty_value_query( |
789 | db: &impl HirDatabase, | 786 | db: &dyn HirDatabase, |
790 | krate: CrateId, | 787 | krate: CrateId, |
791 | id: AssociatedTyValueId, | 788 | id: AssociatedTyValueId, |
792 | ) -> Arc<AssociatedTyValue> { | 789 | ) -> Arc<AssociatedTyValue> { |
@@ -800,12 +797,12 @@ pub(crate) fn associated_ty_value_query( | |||
800 | } | 797 | } |
801 | 798 | ||
802 | fn type_alias_associated_ty_value( | 799 | fn type_alias_associated_ty_value( |
803 | db: &impl HirDatabase, | 800 | db: &dyn HirDatabase, |
804 | _krate: CrateId, | 801 | _krate: CrateId, |
805 | type_alias: TypeAliasId, | 802 | type_alias: TypeAliasId, |
806 | ) -> Arc<AssociatedTyValue> { | 803 | ) -> Arc<AssociatedTyValue> { |
807 | let type_alias_data = db.type_alias_data(type_alias); | 804 | let type_alias_data = db.type_alias_data(type_alias); |
808 | let impl_id = match type_alias.lookup(db).container { | 805 | let impl_id = match type_alias.lookup(db.upcast()).container { |
809 | AssocContainerId::ImplId(it) => it, | 806 | AssocContainerId::ImplId(it) => it, |
810 | _ => panic!("assoc ty value should be in impl"), | 807 | _ => panic!("assoc ty value should be in impl"), |
811 | }; | 808 | }; |
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index 463fd65b4..b40d4eb73 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs | |||
@@ -14,7 +14,7 @@ use hir_def::{ | |||
14 | }; | 14 | }; |
15 | use hir_expand::name::{name, Name}; | 15 | use hir_expand::name::{name, Name}; |
16 | 16 | ||
17 | fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { | 17 | fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> { |
18 | let resolver = trait_.resolver(db); | 18 | let resolver = trait_.resolver(db); |
19 | // returning the iterator directly doesn't easily work because of | 19 | // returning the iterator directly doesn't easily work because of |
20 | // lifetime problems, but since there usually shouldn't be more than a | 20 | // lifetime problems, but since there usually shouldn't be more than a |
@@ -43,7 +43,7 @@ fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { | |||
43 | 43 | ||
44 | /// Returns an iterator over the whole super trait hierarchy (including the | 44 | /// Returns an iterator over the whole super trait hierarchy (including the |
45 | /// trait itself). | 45 | /// trait itself). |
46 | pub(super) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<TraitId> { | 46 | pub(super) fn all_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> { |
47 | // we need to take care a bit here to avoid infinite loops in case of cycles | 47 | // we need to take care a bit here to avoid infinite loops in case of cycles |
48 | // (i.e. if we have `trait A: B; trait B: A;`) | 48 | // (i.e. if we have `trait A: B; trait B: A;`) |
49 | let mut result = vec![trait_]; | 49 | let mut result = vec![trait_]; |
@@ -65,7 +65,7 @@ pub(super) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<Tr | |||
65 | /// Finds a path from a trait to one of its super traits. Returns an empty | 65 | /// Finds a path from a trait to one of its super traits. Returns an empty |
66 | /// vector if there is no path. | 66 | /// vector if there is no path. |
67 | pub(super) fn find_super_trait_path( | 67 | pub(super) fn find_super_trait_path( |
68 | db: &impl DefDatabase, | 68 | db: &dyn DefDatabase, |
69 | trait_: TraitId, | 69 | trait_: TraitId, |
70 | super_trait: TraitId, | 70 | super_trait: TraitId, |
71 | ) -> Vec<TraitId> { | 71 | ) -> Vec<TraitId> { |
@@ -73,7 +73,7 @@ pub(super) fn find_super_trait_path( | |||
73 | result.push(trait_); | 73 | result.push(trait_); |
74 | return if go(db, super_trait, &mut result) { result } else { Vec::new() }; | 74 | return if go(db, super_trait, &mut result) { result } else { Vec::new() }; |
75 | 75 | ||
76 | fn go(db: &impl DefDatabase, super_trait: TraitId, path: &mut Vec<TraitId>) -> bool { | 76 | fn go(db: &dyn DefDatabase, super_trait: TraitId, path: &mut Vec<TraitId>) -> bool { |
77 | let trait_ = *path.last().unwrap(); | 77 | let trait_ = *path.last().unwrap(); |
78 | if trait_ == super_trait { | 78 | if trait_ == super_trait { |
79 | return true; | 79 | return true; |
@@ -95,7 +95,7 @@ pub(super) fn find_super_trait_path( | |||
95 | } | 95 | } |
96 | 96 | ||
97 | pub(super) fn associated_type_by_name_including_super_traits( | 97 | pub(super) fn associated_type_by_name_including_super_traits( |
98 | db: &impl DefDatabase, | 98 | db: &dyn DefDatabase, |
99 | trait_: TraitId, | 99 | trait_: TraitId, |
100 | name: &Name, | 100 | name: &Name, |
101 | ) -> Option<TypeAliasId> { | 101 | ) -> Option<TypeAliasId> { |
@@ -104,7 +104,7 @@ pub(super) fn associated_type_by_name_including_super_traits( | |||
104 | .find_map(|t| db.trait_data(t).associated_type_by_name(name)) | 104 | .find_map(|t| db.trait_data(t).associated_type_by_name(name)) |
105 | } | 105 | } |
106 | 106 | ||
107 | pub(super) fn variant_data(db: &impl DefDatabase, var: VariantId) -> Arc<VariantData> { | 107 | pub(super) fn variant_data(db: &dyn DefDatabase, var: VariantId) -> Arc<VariantData> { |
108 | match var { | 108 | match var { |
109 | VariantId::StructId(it) => db.struct_data(it).variant_data.clone(), | 109 | VariantId::StructId(it) => db.struct_data(it).variant_data.clone(), |
110 | VariantId::UnionId(it) => db.union_data(it).variant_data.clone(), | 110 | VariantId::UnionId(it) => db.union_data(it).variant_data.clone(), |
@@ -123,7 +123,7 @@ pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] { | |||
123 | Arc::get_mut(a).unwrap() | 123 | Arc::get_mut(a).unwrap() |
124 | } | 124 | } |
125 | 125 | ||
126 | pub(crate) fn generics(db: &impl DefDatabase, def: GenericDefId) -> Generics { | 126 | pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics { |
127 | let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def))); | 127 | let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def))); |
128 | Generics { def, params: db.generic_params(def), parent_generics } | 128 | Generics { def, params: db.generic_params(def), parent_generics } |
129 | } | 129 | } |
@@ -222,7 +222,7 @@ impl Generics { | |||
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option<GenericDefId> { | 225 | fn parent_generic_def(db: &dyn DefDatabase, def: GenericDefId) -> Option<GenericDefId> { |
226 | let container = match def { | 226 | let container = match def { |
227 | GenericDefId::FunctionId(it) => it.lookup(db).container, | 227 | GenericDefId::FunctionId(it) => it.lookup(db).container, |
228 | GenericDefId::TypeAliasId(it) => it.lookup(db).container, | 228 | GenericDefId::TypeAliasId(it) => it.lookup(db).container, |