aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer/path.rs2
-rw-r--r--crates/ra_hir/src/ty/lower.rs32
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs2
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs2
4 files changed, 20 insertions, 18 deletions
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs
index ee54d8217..6165eba4f 100644
--- a/crates/ra_hir/src/ty/infer/path.rs
+++ b/crates/ra_hir/src/ty/infer/path.rs
@@ -203,7 +203,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
203 Container::ImplBlock(_) => self.find_self_types(&def, ty.clone()), 203 Container::ImplBlock(_) => self.find_self_types(&def, ty.clone()),
204 Container::Trait(t) => { 204 Container::Trait(t) => {
205 // we're picking this method 205 // we're picking this method
206 let trait_substs = Substs::build_for_def(self.db, t) 206 let trait_substs = Substs::build_for_def(self.db, t.id)
207 .push(ty.clone()) 207 .push(ty.clone())
208 .fill(std::iter::repeat_with(|| self.new_type_var())) 208 .fill(std::iter::repeat_with(|| self.new_type_var()))
209 .build(); 209 .build();
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index da3c8e94a..1ceafd9b1 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -29,8 +29,8 @@ use crate::{
29 Adt, 29 Adt,
30 }, 30 },
31 util::make_mut_slice, 31 util::make_mut_slice,
32 Const, Enum, EnumVariant, Function, GenericDef, ImplBlock, ModuleDef, Path, Static, Struct, 32 Const, Enum, EnumVariant, Function, ImplBlock, ModuleDef, Path, Static, Struct, Trait,
33 Trait, TypeAlias, Union, 33 TypeAlias, Union,
34}; 34};
35 35
36// FIXME: this is only really used in `type_for_def`, which contains a bunch of 36// FIXME: this is only really used in `type_for_def`, which contains a bunch of
@@ -261,8 +261,10 @@ impl Ty {
261 let traits = traits_from_env.flat_map(|t| t.all_super_traits(db)); 261 let traits = traits_from_env.flat_map(|t| t.all_super_traits(db));
262 for t in traits { 262 for t in traits {
263 if let Some(associated_ty) = t.associated_type_by_name(db, &segment.name) { 263 if let Some(associated_ty) = t.associated_type_by_name(db, &segment.name) {
264 let substs = 264 let substs = Substs::build_for_def(db, t.id)
265 Substs::build_for_def(db, t).push(self_ty.clone()).fill_with_unknown().build(); 265 .push(self_ty.clone())
266 .fill_with_unknown()
267 .build();
266 // FIXME handle type parameters on the segment 268 // FIXME handle type parameters on the segment
267 return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); 269 return Ty::Projection(ProjectionTy { associated_ty, parameters: substs });
268 } 270 }
@@ -287,11 +289,11 @@ impl Ty {
287 segment: &PathSegment, 289 segment: &PathSegment,
288 resolved: TypableDef, 290 resolved: TypableDef,
289 ) -> Substs { 291 ) -> Substs {
290 let def_generic: Option<GenericDef> = match resolved { 292 let def_generic: Option<GenericDefId> = match resolved {
291 TypableDef::Function(func) => Some(func.into()), 293 TypableDef::Function(func) => Some(func.id.into()),
292 TypableDef::Adt(adt) => Some(adt.into()), 294 TypableDef::Adt(adt) => Some(adt.into()),
293 TypableDef::EnumVariant(var) => Some(var.parent_enum(db).into()), 295 TypableDef::EnumVariant(var) => Some(var.parent_enum(db).id.into()),
294 TypableDef::TypeAlias(t) => Some(t.into()), 296 TypableDef::TypeAlias(t) => Some(t.id.into()),
295 TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None, 297 TypableDef::Const(_) | TypableDef::Static(_) | TypableDef::BuiltinType(_) => None,
296 }; 298 };
297 substs_from_path_segment(db, resolver, segment, def_generic, false) 299 substs_from_path_segment(db, resolver, segment, def_generic, false)
@@ -338,7 +340,7 @@ pub(super) fn substs_from_path_segment(
338 db: &impl HirDatabase, 340 db: &impl HirDatabase,
339 resolver: &Resolver, 341 resolver: &Resolver,
340 segment: &PathSegment, 342 segment: &PathSegment,
341 def_generic: Option<GenericDef>, 343 def_generic: Option<GenericDefId>,
342 add_self_param: bool, 344 add_self_param: bool,
343) -> Substs { 345) -> Substs {
344 let mut substs = Vec::new(); 346 let mut substs = Vec::new();
@@ -376,7 +378,7 @@ pub(super) fn substs_from_path_segment(
376 378
377 // handle defaults 379 // handle defaults
378 if let Some(def_generic) = def_generic { 380 if let Some(def_generic) = def_generic {
379 let default_substs = db.generic_defaults(def_generic); 381 let default_substs = db.generic_defaults(def_generic.into());
380 assert_eq!(substs.len(), default_substs.len()); 382 assert_eq!(substs.len(), default_substs.len());
381 383
382 for (i, default_ty) in default_substs.iter().enumerate() { 384 for (i, default_ty) in default_substs.iter().enumerate() {
@@ -439,7 +441,7 @@ impl TraitRef {
439 ) -> Substs { 441 ) -> Substs {
440 let has_self_param = 442 let has_self_param =
441 segment.args_and_bindings.as_ref().map(|a| a.has_self_type).unwrap_or(false); 443 segment.args_and_bindings.as_ref().map(|a| a.has_self_type).unwrap_or(false);
442 substs_from_path_segment(db, resolver, segment, Some(resolved.into()), !has_self_param) 444 substs_from_path_segment(db, resolver, segment, Some(resolved.id.into()), !has_self_param)
443 } 445 }
444 446
445 pub(crate) fn for_trait(db: &impl HirDatabase, trait_: Trait) -> TraitRef { 447 pub(crate) fn for_trait(db: &impl HirDatabase, trait_: Trait) -> TraitRef {
@@ -579,10 +581,10 @@ pub(crate) fn field_types_query(
579/// these are fine: `T: Foo<U::Item>, U: Foo<()>`. 581/// these are fine: `T: Foo<U::Item>, U: Foo<()>`.
580pub(crate) fn generic_predicates_for_param_query( 582pub(crate) fn generic_predicates_for_param_query(
581 db: &impl HirDatabase, 583 db: &impl HirDatabase,
582 def: GenericDef, 584 def: GenericDefId,
583 param_idx: u32, 585 param_idx: u32,
584) -> Arc<[GenericPredicate]> { 586) -> Arc<[GenericPredicate]> {
585 let resolver = GenericDefId::from(def).resolver(db); 587 let resolver = def.resolver(db);
586 resolver 588 resolver
587 .where_predicates_in_scope() 589 .where_predicates_in_scope()
588 // we have to filter out all other predicates *first*, before attempting to lower them 590 // we have to filter out all other predicates *first*, before attempting to lower them
@@ -615,8 +617,8 @@ pub(crate) fn generic_predicates_query(
615} 617}
616 618
617/// Resolve the default type params from generics 619/// Resolve the default type params from generics
618pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) -> Substs { 620pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs {
619 let resolver = GenericDefId::from(def).resolver(db); 621 let resolver = def.resolver(db);
620 let generic_params = db.generic_params(def.into()); 622 let generic_params = db.generic_params(def.into());
621 623
622 let defaults = generic_params 624 let defaults = generic_params
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index f7905b5ff..c5ab690eb 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -365,7 +365,7 @@ fn generic_implements_goal(
365 self_ty: Canonical<Ty>, 365 self_ty: Canonical<Ty>,
366) -> Canonical<InEnvironment<super::Obligation>> { 366) -> Canonical<InEnvironment<super::Obligation>> {
367 let num_vars = self_ty.num_vars; 367 let num_vars = self_ty.num_vars;
368 let substs = super::Substs::build_for_def(db, trait_) 368 let substs = super::Substs::build_for_def(db, trait_.id)
369 .push(self_ty.value) 369 .push(self_ty.value)
370 .fill_with_bound_vars(num_vars as u32) 370 .fill_with_bound_vars(num_vars as u32)
371 .build(); 371 .build();
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index a0dbf6305..0272dd9ae 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -736,7 +736,7 @@ fn closure_fn_trait_impl_datum(
736 736
737 let trait_ref = TraitRef { 737 let trait_ref = TraitRef {
738 trait_, 738 trait_,
739 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), 739 substs: Substs::build_for_def(db, trait_.id).push(self_ty).push(arg_ty).build(),
740 }; 740 };
741 741
742 let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()).to_chalk(db); 742 let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()).to_chalk(db);