aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-08 13:21:22 +0100
committerFlorian Diebold <[email protected]>2021-04-08 13:23:17 +0100
commit8040f4a5e3792f95b3194e21b3f6d375fb7499c5 (patch)
treebaf287e6d05568319662cd32d56ded5354edecd6 /crates/hir_ty/src/traits
parent8ce6fea325c001deeed2857da560fa5cfbc6eea3 (diff)
Replace `make_binders` by the now equivalent `make_only_type_binders`
Diffstat (limited to 'crates/hir_ty/src/traits')
-rw-r--r--crates/hir_ty/src/traits/chalk.rs43
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs14
2 files changed, 22 insertions, 35 deletions
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index fcdcc2b4d..e2a54fd92 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -17,16 +17,14 @@ use super::ChalkContext;
17use crate::{ 17use crate::{
18 db::HirDatabase, 18 db::HirDatabase,
19 display::HirDisplay, 19 display::HirDisplay,
20 from_assoc_type_id, 20 from_assoc_type_id, make_only_type_binders,
21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS}, 21 method_resolution::{TyFingerprint, ALL_FLOAT_FPS, ALL_INT_FPS},
22 to_assoc_type_id, to_chalk_trait_id, 22 to_assoc_type_id, to_chalk_trait_id,
23 utils::generics, 23 utils::generics,
24 AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution, 24 AliasEq, AliasTy, BoundVar, CallableDefId, DebruijnIndex, FnDefId, ProjectionTy, Substitution,
25 TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause, 25 TraitRef, TraitRefExt, Ty, TyBuilder, TyExt, TyKind, WhereClause,
26}; 26};
27use mapping::{ 27use mapping::{convert_where_clauses, generic_predicate_to_inline_bound, TypeAliasAsValue};
28 convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue,
29};
30 28
31pub use self::interner::Interner; 29pub use self::interner::Interner;
32pub(crate) use self::interner::*; 30pub(crate) use self::interner::*;
@@ -187,8 +185,11 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
187 let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders(); 185 let (datas, binders) = (*datas).as_ref().into_value_and_skipped_binders();
188 let data = &datas.impl_traits[idx as usize]; 186 let data = &datas.impl_traits[idx as usize];
189 let bound = OpaqueTyDatumBound { 187 let bound = OpaqueTyDatumBound {
190 bounds: make_binders(data.bounds.skip_binders().iter().cloned().collect(), 1), 188 bounds: make_only_type_binders(
191 where_clauses: make_binders(vec![], 0), 189 1,
190 data.bounds.skip_binders().iter().cloned().collect(),
191 ),
192 where_clauses: make_only_type_binders(0, vec![]),
192 }; 193 };
193 chalk_ir::Binders::new(binders, bound) 194 chalk_ir::Binders::new(binders, bound)
194 } 195 }
@@ -236,25 +237,25 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
236 .intern(&Interner), 237 .intern(&Interner),
237 }); 238 });
238 let bound = OpaqueTyDatumBound { 239 let bound = OpaqueTyDatumBound {
239 bounds: make_binders( 240 bounds: make_only_type_binders(
241 1,
240 vec![ 242 vec![
241 crate::wrap_empty_binders(impl_bound), 243 crate::wrap_empty_binders(impl_bound),
242 crate::wrap_empty_binders(proj_bound), 244 crate::wrap_empty_binders(proj_bound),
243 ], 245 ],
244 1,
245 ), 246 ),
246 where_clauses: make_binders(vec![], 0), 247 where_clauses: make_only_type_binders(0, vec![]),
247 }; 248 };
248 // The opaque type has 1 parameter. 249 // The opaque type has 1 parameter.
249 make_binders(bound, 1) 250 make_only_type_binders(1, bound)
250 } else { 251 } else {
251 // If failed to find Symbol’s value as variable is void: Future::Output, return empty bounds as fallback. 252 // If failed to find Symbol’s value as variable is void: Future::Output, return empty bounds as fallback.
252 let bound = OpaqueTyDatumBound { 253 let bound = OpaqueTyDatumBound {
253 bounds: make_binders(vec![], 0), 254 bounds: make_only_type_binders(0, vec![]),
254 where_clauses: make_binders(vec![], 0), 255 where_clauses: make_only_type_binders(0, vec![]),
255 }; 256 };
256 // The opaque type has 1 parameter. 257 // The opaque type has 1 parameter.
257 make_binders(bound, 1) 258 make_only_type_binders(1, bound)
258 } 259 }
259 } 260 }
260 }; 261 };
@@ -291,7 +292,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
291 argument_types: sig.params().iter().cloned().collect(), 292 argument_types: sig.params().iter().cloned().collect(),
292 return_type: sig.ret().clone(), 293 return_type: sig.ret().clone(),
293 }; 294 };
294 make_binders(io.shifted_in(&Interner), 0) 295 make_only_type_binders(0, io.shifted_in(&Interner))
295 } 296 }
296 fn closure_upvars( 297 fn closure_upvars(
297 &self, 298 &self,
@@ -299,7 +300,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
299 _substs: &chalk_ir::Substitution<Interner>, 300 _substs: &chalk_ir::Substitution<Interner>,
300 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> { 301 ) -> chalk_ir::Binders<chalk_ir::Ty<Interner>> {
301 let ty = TyBuilder::unit(); 302 let ty = TyBuilder::unit();
302 make_binders(ty, 0) 303 make_only_type_binders(0, ty)
303 } 304 }
304 fn closure_fn_substitution( 305 fn closure_fn_substitution(
305 &self, 306 &self,
@@ -404,7 +405,7 @@ pub(crate) fn associated_ty_data_query(
404 trait_id: to_chalk_trait_id(trait_), 405 trait_id: to_chalk_trait_id(trait_),
405 id, 406 id,
406 name: type_alias, 407 name: type_alias,
407 binders: make_binders(bound_data, generic_params.len()), 408 binders: make_only_type_binders(generic_params.len(), bound_data),
408 }; 409 };
409 Arc::new(datum) 410 Arc::new(datum)
410} 411}
@@ -437,7 +438,7 @@ pub(crate) fn trait_datum_query(
437 lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name)); 438 lang_attr(db.upcast(), trait_).and_then(|name| well_known_trait_from_lang_attr(&name));
438 let trait_datum = TraitDatum { 439 let trait_datum = TraitDatum {
439 id: trait_id, 440 id: trait_id,
440 binders: make_binders(trait_datum_bound, bound_vars.len(&Interner)), 441 binders: make_only_type_binders(bound_vars.len(&Interner), trait_datum_bound),
441 flags, 442 flags,
442 associated_ty_ids, 443 associated_ty_ids,
443 well_known, 444 well_known,
@@ -506,7 +507,7 @@ pub(crate) fn struct_datum_query(
506 // FIXME set ADT kind 507 // FIXME set ADT kind
507 kind: rust_ir::AdtKind::Struct, 508 kind: rust_ir::AdtKind::Struct,
508 id: struct_id, 509 id: struct_id,
509 binders: make_binders(struct_datum_bound, num_params), 510 binders: make_only_type_binders(num_params, struct_datum_bound),
510 flags, 511 flags,
511 }; 512 };
512 Arc::new(struct_datum) 513 Arc::new(struct_datum)
@@ -575,7 +576,7 @@ fn impl_def_datum(
575 .collect(); 576 .collect();
576 debug!("impl_datum: {:?}", impl_datum_bound); 577 debug!("impl_datum: {:?}", impl_datum_bound);
577 let impl_datum = ImplDatum { 578 let impl_datum = ImplDatum {
578 binders: make_binders(impl_datum_bound, bound_vars.len(&Interner)), 579 binders: make_only_type_binders(bound_vars.len(&Interner), impl_datum_bound),
579 impl_type, 580 impl_type,
580 polarity, 581 polarity,
581 associated_ty_value_ids, 582 associated_ty_value_ids,
@@ -635,13 +636,13 @@ pub(crate) fn fn_def_datum_query(
635 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); 636 let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars);
636 let bound = rust_ir::FnDefDatumBound { 637 let bound = rust_ir::FnDefDatumBound {
637 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway 638 // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway
638 inputs_and_output: make_binders( 639 inputs_and_output: make_only_type_binders(
640 0,
639 rust_ir::FnDefInputsAndOutputDatum { 641 rust_ir::FnDefInputsAndOutputDatum {
640 argument_types: sig.params().iter().cloned().collect(), 642 argument_types: sig.params().iter().cloned().collect(),
641 return_type: sig.ret().clone(), 643 return_type: sig.ret().clone(),
642 } 644 }
643 .shifted_in(&Interner), 645 .shifted_in(&Interner),
644 0,
645 ), 646 ),
646 where_clauses, 647 where_clauses,
647 }; 648 };
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 54783b58c..4abc0fbf2 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -71,20 +71,6 @@ impl ToChalk for TypeAliasAsValue {
71 } 71 }
72} 72}
73 73
74pub(super) fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T>
75where
76 T: HasInterner<Interner = Interner>,
77{
78 chalk_ir::Binders::new(
79 chalk_ir::VariableKinds::from_iter(
80 &Interner,
81 std::iter::repeat(chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General))
82 .take(num_vars),
83 ),
84 value,
85 )
86}
87
88pub(super) fn convert_where_clauses( 74pub(super) fn convert_where_clauses(
89 db: &dyn HirDatabase, 75 db: &dyn HirDatabase,
90 def: GenericDefId, 76 def: GenericDefId,