aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/ty.rs6
-rw-r--r--crates/ra_hir/src/ty/lower.rs32
-rw-r--r--crates/ra_hir/src/ty/traits.rs2
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs3
4 files changed, 18 insertions, 25 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index fc4909d11..bf7445ea3 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -329,8 +329,7 @@ impl Substs {
329 .params_including_parent() 329 .params_including_parent()
330 .into_iter() 330 .into_iter()
331 .map(|p| Ty::Param { idx: p.idx, name: p.name.clone() }) 331 .map(|p| Ty::Param { idx: p.idx, name: p.name.clone() })
332 .collect::<Vec<_>>() 332 .collect(),
333 .into(),
334 ) 333 )
335 } 334 }
336 335
@@ -341,8 +340,7 @@ impl Substs {
341 .params_including_parent() 340 .params_including_parent()
342 .into_iter() 341 .into_iter()
343 .map(|p| Ty::Bound(p.idx)) 342 .map(|p| Ty::Bound(p.idx))
344 .collect::<Vec<_>>() 343 .collect(),
345 .into(),
346 ) 344 )
347 } 345 }
348 346
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 003aa9bab..2f9a2ee05 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -31,11 +31,11 @@ impl Ty {
31 match type_ref { 31 match type_ref {
32 TypeRef::Never => Ty::simple(TypeCtor::Never), 32 TypeRef::Never => Ty::simple(TypeCtor::Never),
33 TypeRef::Tuple(inner) => { 33 TypeRef::Tuple(inner) => {
34 let inner_tys = 34 let inner_tys: Arc<[Ty]> =
35 inner.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::<Vec<_>>(); 35 inner.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect();
36 Ty::apply( 36 Ty::apply(
37 TypeCtor::Tuple { cardinality: inner_tys.len() as u16 }, 37 TypeCtor::Tuple { cardinality: inner_tys.len() as u16 },
38 Substs(inner_tys.into()), 38 Substs(inner_tys),
39 ) 39 )
40 } 40 }
41 TypeRef::Path(path) => Ty::from_hir_path(db, resolver, path), 41 TypeRef::Path(path) => Ty::from_hir_path(db, resolver, path),
@@ -57,9 +57,7 @@ impl Ty {
57 } 57 }
58 TypeRef::Placeholder => Ty::Unknown, 58 TypeRef::Placeholder => Ty::Unknown,
59 TypeRef::Fn(params) => { 59 TypeRef::Fn(params) => {
60 let inner_tys = 60 let sig = Substs(params.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect());
61 params.iter().map(|tr| Ty::from_hir(db, resolver, tr)).collect::<Vec<_>>();
62 let sig = Substs(inner_tys.into());
63 Ty::apply(TypeCtor::FnPtr { num_args: sig.len() as u16 - 1 }, sig) 61 Ty::apply(TypeCtor::FnPtr { num_args: sig.len() as u16 - 1 }, sig)
64 } 62 }
65 TypeRef::DynTrait(bounds) => { 63 TypeRef::DynTrait(bounds) => {
@@ -69,8 +67,8 @@ impl Ty {
69 .flat_map(|b| { 67 .flat_map(|b| {
70 GenericPredicate::from_type_bound(db, resolver, b, self_ty.clone()) 68 GenericPredicate::from_type_bound(db, resolver, b, self_ty.clone())
71 }) 69 })
72 .collect::<Vec<_>>(); 70 .collect();
73 Ty::Dyn(predicates.into()) 71 Ty::Dyn(predicates)
74 } 72 }
75 TypeRef::ImplTrait(bounds) => { 73 TypeRef::ImplTrait(bounds) => {
76 let self_ty = Ty::Bound(0); 74 let self_ty = Ty::Bound(0);
@@ -79,8 +77,8 @@ impl Ty {
79 .flat_map(|b| { 77 .flat_map(|b| {
80 GenericPredicate::from_type_bound(db, resolver, b, self_ty.clone()) 78 GenericPredicate::from_type_bound(db, resolver, b, self_ty.clone())
81 }) 79 })
82 .collect::<Vec<_>>(); 80 .collect();
83 Ty::Opaque(predicates.into()) 81 Ty::Opaque(predicates)
84 } 82 }
85 TypeRef::Error => Ty::Unknown, 83 TypeRef::Error => Ty::Unknown,
86 } 84 }
@@ -557,13 +555,12 @@ pub(crate) fn generic_predicates_for_param_query(
557 param_idx: u32, 555 param_idx: u32,
558) -> Arc<[GenericPredicate]> { 556) -> Arc<[GenericPredicate]> {
559 let resolver = def.resolver(db); 557 let resolver = def.resolver(db);
560 let predicates = resolver 558 resolver
561 .where_predicates_in_scope() 559 .where_predicates_in_scope()
562 // we have to filter out all other predicates *first*, before attempting to lower them 560 // we have to filter out all other predicates *first*, before attempting to lower them
563 .filter(|pred| Ty::from_hir_only_param(db, &resolver, &pred.type_ref) == Some(param_idx)) 561 .filter(|pred| Ty::from_hir_only_param(db, &resolver, &pred.type_ref) == Some(param_idx))
564 .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred)) 562 .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred))
565 .collect::<Vec<_>>(); 563 .collect()
566 predicates.into()
567} 564}
568 565
569pub(crate) fn trait_env( 566pub(crate) fn trait_env(
@@ -584,11 +581,10 @@ pub(crate) fn generic_predicates_query(
584 def: GenericDef, 581 def: GenericDef,
585) -> Arc<[GenericPredicate]> { 582) -> Arc<[GenericPredicate]> {
586 let resolver = def.resolver(db); 583 let resolver = def.resolver(db);
587 let predicates = resolver 584 resolver
588 .where_predicates_in_scope() 585 .where_predicates_in_scope()
589 .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred)) 586 .flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred))
590 .collect::<Vec<_>>(); 587 .collect()
591 predicates.into()
592} 588}
593 589
594/// Resolve the default type params from generics 590/// Resolve the default type params from generics
@@ -602,9 +598,9 @@ pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDef) ->
602 .map(|p| { 598 .map(|p| {
603 p.default.as_ref().map_or(Ty::Unknown, |path| Ty::from_hir_path(db, &resolver, path)) 599 p.default.as_ref().map_or(Ty::Unknown, |path| Ty::from_hir_path(db, &resolver, path))
604 }) 600 })
605 .collect::<Vec<_>>(); 601 .collect();
606 602
607 Substs(defaults.into()) 603 Substs(defaults)
608} 604}
609 605
610fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { 606fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig {
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs
index b0f67ae50..0cb5c3798 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -89,7 +89,7 @@ pub(crate) fn impls_for_trait_query(
89 } 89 }
90 let crate_impl_blocks = db.impls_in_crate(krate); 90 let crate_impl_blocks = db.impls_in_crate(krate);
91 impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_)); 91 impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_));
92 impls.into_iter().collect::<Vec<_>>().into() 92 impls.into_iter().collect()
93} 93}
94 94
95/// A set of clauses that we assume to be true. E.g. if we are inside this function: 95/// A set of clauses that we assume to be true. E.g. if we are inside this function:
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index 9168de709..00aaf65d9 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -126,8 +126,7 @@ impl ToChalk for Substs {
126 chalk_ir::Parameter(chalk_ir::ParameterKind::Ty(ty)) => from_chalk(db, ty), 126 chalk_ir::Parameter(chalk_ir::ParameterKind::Ty(ty)) => from_chalk(db, ty),
127 chalk_ir::Parameter(chalk_ir::ParameterKind::Lifetime(_)) => unimplemented!(), 127 chalk_ir::Parameter(chalk_ir::ParameterKind::Lifetime(_)) => unimplemented!(),
128 }) 128 })
129 .collect::<Vec<_>>() 129 .collect();
130 .into();
131 Substs(tys) 130 Substs(tys)
132 } 131 }
133} 132}