mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Binders::subst -> substitute
This commit is contained in:
parent
ad20f00844
commit
05eba0db3d
@ -235,7 +235,7 @@ impl HirDisplay for TypeParam {
|
||||
write!(f, "{}", self.name(f.db))?;
|
||||
let bounds = f.db.generic_predicates_for_param(self.id);
|
||||
let substs = TyBuilder::type_params_subst(f.db, self.id.parent);
|
||||
let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>();
|
||||
let predicates = bounds.iter().cloned().map(|b| b.substitute(&substs)).collect::<Vec<_>>();
|
||||
if !(predicates.is_empty() || f.omit_verbose_types()) {
|
||||
write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?;
|
||||
}
|
||||
|
@ -516,7 +516,7 @@ impl Field {
|
||||
VariantDef::Variant(it) => it.parent.id.into(),
|
||||
};
|
||||
let substs = TyBuilder::type_params_subst(db, generic_def_id);
|
||||
let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
|
||||
let ty = db.field_types(var_id)[self.id].clone().substitute(&substs);
|
||||
Type::new(db, self.parent.module(db).id.krate(), var_id, ty)
|
||||
}
|
||||
|
||||
@ -1503,7 +1503,7 @@ impl TypeParam {
|
||||
let krate = self.id.parent.module(db.upcast()).krate();
|
||||
let ty = params.get(local_idx)?.clone();
|
||||
let subst = TyBuilder::type_params_subst(db, self.id.parent);
|
||||
let ty = ty.subst(&subst.prefix(local_idx));
|
||||
let ty = ty.substitute(&subst.prefix(local_idx));
|
||||
Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
|
||||
}
|
||||
}
|
||||
@ -1916,7 +1916,7 @@ impl Type {
|
||||
.iter()
|
||||
.map(|(local_id, ty)| {
|
||||
let def = Field { parent: variant_id.into(), id: local_id };
|
||||
let ty = ty.clone().subst(substs);
|
||||
let ty = ty.clone().substitute(substs);
|
||||
(def, self.derived(ty))
|
||||
})
|
||||
.collect()
|
||||
|
@ -339,7 +339,7 @@ impl SourceAnalyzer {
|
||||
.into_iter()
|
||||
.map(|local_id| {
|
||||
let field = FieldId { parent: variant, local_id };
|
||||
let ty = field_types[local_id].clone().subst(substs);
|
||||
let ty = field_types[local_id].clone().substitute(substs);
|
||||
(field.into(), Type::new_with_resolver_inner(db, krate, &self.resolver, ty))
|
||||
})
|
||||
.collect()
|
||||
|
@ -139,7 +139,7 @@ impl TyBuilder<hir_def::AdtId> {
|
||||
} else {
|
||||
// each default can depend on the previous parameters
|
||||
let subst_so_far = Substitution::intern(self.vec.clone());
|
||||
self.vec.push(default_ty.clone().subst(&subst_so_far).cast(&Interner));
|
||||
self.vec.push(default_ty.clone().substitute(&subst_so_far).cast(&Interner));
|
||||
}
|
||||
}
|
||||
self
|
||||
@ -200,7 +200,7 @@ impl<T: TypeWalk + HasInterner<Interner = Interner>> TyBuilder<Binders<T>> {
|
||||
|
||||
pub fn build(self) -> T {
|
||||
let (b, subst) = self.build_internal();
|
||||
b.subst(&subst)
|
||||
b.substitute(&subst)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,7 @@ impl HirDisplay for Ty {
|
||||
let data = (*datas)
|
||||
.as_ref()
|
||||
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
|
||||
let bounds = data.subst(parameters);
|
||||
let bounds = data.substitute(parameters);
|
||||
bounds.into_value_and_skipped_binders().0
|
||||
} else {
|
||||
Vec::new()
|
||||
@ -397,7 +397,7 @@ impl HirDisplay for Ty {
|
||||
}
|
||||
TyKind::FnDef(def, parameters) => {
|
||||
let def = from_chalk(f.db, *def);
|
||||
let sig = f.db.callable_item_signature(def).subst(parameters);
|
||||
let sig = f.db.callable_item_signature(def).substitute(parameters);
|
||||
match def {
|
||||
CallableDefId::FunctionId(ff) => {
|
||||
write!(f, "fn {}", f.db.function_data(ff).name)?
|
||||
@ -482,7 +482,7 @@ impl HirDisplay for Ty {
|
||||
(_, Some(default_parameter)) => {
|
||||
let actual_default = default_parameter
|
||||
.clone()
|
||||
.subst(¶meters.prefix(i));
|
||||
.substitute(¶meters.prefix(i));
|
||||
if parameter.assert_ty_ref(&Interner) != &actual_default
|
||||
{
|
||||
default_from = i + 1;
|
||||
@ -542,7 +542,7 @@ impl HirDisplay for Ty {
|
||||
let data = (*datas)
|
||||
.as_ref()
|
||||
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
|
||||
let bounds = data.subst(¶meters);
|
||||
let bounds = data.substitute(¶meters);
|
||||
write_bounds_like_dyn_trait_with_prefix("impl", bounds.skip_binders(), f)?;
|
||||
// FIXME: it would maybe be good to distinguish this from the alias type (when debug printing), and to show the substitution
|
||||
}
|
||||
@ -595,7 +595,7 @@ impl HirDisplay for Ty {
|
||||
let bounds =
|
||||
f.db.generic_predicates(id.parent)
|
||||
.into_iter()
|
||||
.map(|pred| pred.clone().subst(&substs))
|
||||
.map(|pred| pred.clone().substitute(&substs))
|
||||
.filter(|wc| match &wc.skip_binders() {
|
||||
WhereClause::Implemented(tr) => {
|
||||
tr.self_type_parameter(&Interner) == self
|
||||
@ -629,7 +629,7 @@ impl HirDisplay for Ty {
|
||||
let data = (*datas)
|
||||
.as_ref()
|
||||
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
|
||||
let bounds = data.subst(&opaque_ty.substitution);
|
||||
let bounds = data.substitute(&opaque_ty.substitution);
|
||||
write_bounds_like_dyn_trait_with_prefix("impl", bounds.skip_binders(), f)?;
|
||||
}
|
||||
ImplTraitId::AsyncBlockTypeImplTrait(..) => {
|
||||
|
@ -470,25 +470,25 @@ impl<'a> InferenceContext<'a> {
|
||||
TypeNs::AdtId(AdtId::StructId(strukt)) => {
|
||||
let substs = ctx.substs_from_path(path, strukt.into(), true);
|
||||
let ty = self.db.ty(strukt.into());
|
||||
let ty = self.insert_type_vars(ty.subst(&substs));
|
||||
let ty = self.insert_type_vars(ty.substitute(&substs));
|
||||
forbid_unresolved_segments((ty, Some(strukt.into())), unresolved)
|
||||
}
|
||||
TypeNs::AdtId(AdtId::UnionId(u)) => {
|
||||
let substs = ctx.substs_from_path(path, u.into(), true);
|
||||
let ty = self.db.ty(u.into());
|
||||
let ty = self.insert_type_vars(ty.subst(&substs));
|
||||
let ty = self.insert_type_vars(ty.substitute(&substs));
|
||||
forbid_unresolved_segments((ty, Some(u.into())), unresolved)
|
||||
}
|
||||
TypeNs::EnumVariantId(var) => {
|
||||
let substs = ctx.substs_from_path(path, var.into(), true);
|
||||
let ty = self.db.ty(var.parent.into());
|
||||
let ty = self.insert_type_vars(ty.subst(&substs));
|
||||
let ty = self.insert_type_vars(ty.substitute(&substs));
|
||||
forbid_unresolved_segments((ty, Some(var.into())), unresolved)
|
||||
}
|
||||
TypeNs::SelfType(impl_id) => {
|
||||
let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
|
||||
let substs = generics.type_params_subst(self.db);
|
||||
let ty = self.db.impl_self_ty(impl_id).subst(&substs);
|
||||
let ty = self.db.impl_self_ty(impl_id).substitute(&substs);
|
||||
match unresolved {
|
||||
None => {
|
||||
let variant = ty_variant(&ty);
|
||||
|
@ -419,7 +419,7 @@ impl<'a> InferenceContext<'a> {
|
||||
self.result.record_field_resolutions.insert(field.expr, field_def);
|
||||
}
|
||||
let field_ty = field_def.map_or(self.err_ty(), |it| {
|
||||
field_types[it.local_id].clone().subst(&substs)
|
||||
field_types[it.local_id].clone().substitute(&substs)
|
||||
});
|
||||
self.infer_expr_coerce(field.expr, &Expectation::has_type(field_ty));
|
||||
}
|
||||
@ -462,7 +462,7 @@ impl<'a> InferenceContext<'a> {
|
||||
Some(
|
||||
self.db.field_types((*s).into())[field.local_id]
|
||||
.clone()
|
||||
.subst(¶meters),
|
||||
.substitute(¶meters),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
@ -476,7 +476,7 @@ impl<'a> InferenceContext<'a> {
|
||||
Some(
|
||||
self.db.field_types((*u).into())[field.local_id]
|
||||
.clone()
|
||||
.subst(¶meters),
|
||||
.substitute(¶meters),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
@ -852,7 +852,7 @@ impl<'a> InferenceContext<'a> {
|
||||
None => (receiver_ty, Binders::empty(&Interner, self.err_ty()), None),
|
||||
};
|
||||
let substs = self.substs_for_method_call(def_generics, generic_args, &derefed_receiver_ty);
|
||||
let method_ty = method_ty.subst(&substs);
|
||||
let method_ty = method_ty.substitute(&substs);
|
||||
let method_ty = self.insert_type_vars(method_ty);
|
||||
self.register_obligations_for_call(&method_ty);
|
||||
let (expected_receiver_ty, param_tys, ret_ty) = match method_ty.callable_sig(self.db) {
|
||||
@ -950,7 +950,7 @@ impl<'a> InferenceContext<'a> {
|
||||
let generic_predicates = self.db.generic_predicates(def.into());
|
||||
for predicate in generic_predicates.iter() {
|
||||
let (predicate, binders) =
|
||||
predicate.clone().subst(parameters).into_value_and_skipped_binders();
|
||||
predicate.clone().substitute(parameters).into_value_and_skipped_binders();
|
||||
always!(binders.len(&Interner) == 0); // quantified where clauses not yet handled
|
||||
self.push_obligation(predicate.cast(&Interner));
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl<'a> InferenceContext<'a> {
|
||||
let expected_ty = var_data
|
||||
.as_ref()
|
||||
.and_then(|d| d.field(&Name::new_tuple_field(i)))
|
||||
.map_or(self.err_ty(), |field| field_tys[field].clone().subst(&substs));
|
||||
.map_or(self.err_ty(), |field| field_tys[field].clone().substitute(&substs));
|
||||
let expected_ty = self.normalize_associated_types_in(expected_ty);
|
||||
self.infer_pat(subpat, &expected_ty, default_bm);
|
||||
}
|
||||
@ -84,7 +84,7 @@ impl<'a> InferenceContext<'a> {
|
||||
}
|
||||
|
||||
let expected_ty = matching_field
|
||||
.map_or(self.err_ty(), |field| field_tys[field].clone().subst(&substs));
|
||||
.map_or(self.err_ty(), |field| field_tys[field].clone().substitute(&substs));
|
||||
let expected_ty = self.normalize_associated_types_in(expected_ty);
|
||||
self.infer_pat(subpat.pat, &expected_ty, default_bm);
|
||||
}
|
||||
|
@ -81,9 +81,9 @@ impl<'a> InferenceContext<'a> {
|
||||
ValueNs::ImplSelf(impl_id) => {
|
||||
let generics = crate::utils::generics(self.db.upcast(), impl_id.into());
|
||||
let substs = generics.type_params_subst(self.db);
|
||||
let ty = self.db.impl_self_ty(impl_id).subst(&substs);
|
||||
let ty = self.db.impl_self_ty(impl_id).substitute(&substs);
|
||||
if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() {
|
||||
let ty = self.db.value_ty(struct_id.into()).subst(&substs);
|
||||
let ty = self.db.value_ty(struct_id.into()).substitute(&substs);
|
||||
return Some(ty);
|
||||
} else {
|
||||
// FIXME: diagnostic, invalid Self reference
|
||||
@ -243,7 +243,7 @@ impl<'a> InferenceContext<'a> {
|
||||
let impl_substs = TyBuilder::subst_for_def(self.db, impl_id)
|
||||
.fill(iter::repeat_with(|| self.table.new_type_var()))
|
||||
.build();
|
||||
let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs);
|
||||
let impl_self_ty = self.db.impl_self_ty(impl_id).substitute(&impl_substs);
|
||||
self.unify(&impl_self_ty, &ty);
|
||||
Some(impl_substs)
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ impl<T> Binders<T> {
|
||||
|
||||
impl<T: TypeWalk> Binders<T> {
|
||||
/// Substitutes all variables.
|
||||
pub fn subst(self, subst: &Substitution) -> T {
|
||||
pub fn substitute(self, subst: &Substitution) -> T {
|
||||
let (value, binders) = self.into_value_and_skipped_binders();
|
||||
assert_eq!(subst.len(&Interner), binders.len(&Interner));
|
||||
value.subst_bound_vars(subst)
|
||||
@ -362,7 +362,7 @@ impl Ty {
|
||||
TyKind::FnDef(def, parameters) => {
|
||||
let callable_def = db.lookup_intern_callable_def((*def).into());
|
||||
let sig = db.callable_item_signature(callable_def);
|
||||
Some(sig.subst(¶meters))
|
||||
Some(sig.substitute(¶meters))
|
||||
}
|
||||
TyKind::Closure(.., substs) => {
|
||||
let sig_param = substs.at(&Interner, 0).assert_ty_ref(&Interner);
|
||||
@ -436,7 +436,7 @@ impl Ty {
|
||||
let data = (*it)
|
||||
.as_ref()
|
||||
.map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
|
||||
data.subst(&opaque_ty.substitution)
|
||||
data.substitute(&opaque_ty.substitution)
|
||||
})
|
||||
}
|
||||
// It always has an parameter for Future::Output type.
|
||||
@ -455,7 +455,7 @@ impl Ty {
|
||||
let predicates = db
|
||||
.generic_predicates(id.parent)
|
||||
.into_iter()
|
||||
.map(|pred| pred.clone().subst(&substs))
|
||||
.map(|pred| pred.clone().substitute(&substs))
|
||||
.filter(|wc| match &wc.skip_binders() {
|
||||
WhereClause::Implemented(tr) => {
|
||||
tr.self_type_parameter(&Interner) == self
|
||||
|
@ -414,7 +414,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||
TypeParamLoweringMode::Placeholder => generics.type_params_subst(self.db),
|
||||
TypeParamLoweringMode::Variable => generics.bound_vars_subst(self.in_binders),
|
||||
};
|
||||
self.db.impl_self_ty(impl_id).subst(&substs)
|
||||
self.db.impl_self_ty(impl_id).substitute(&substs)
|
||||
}
|
||||
TypeNs::AdtSelfType(adt) => {
|
||||
let generics = generics(self.db.upcast(), adt.into());
|
||||
@ -422,7 +422,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||
TypeParamLoweringMode::Placeholder => generics.type_params_subst(self.db),
|
||||
TypeParamLoweringMode::Variable => generics.bound_vars_subst(self.in_binders),
|
||||
};
|
||||
self.db.ty(adt.into()).subst(&substs)
|
||||
self.db.ty(adt.into()).substitute(&substs)
|
||||
}
|
||||
|
||||
TypeNs::AdtId(it) => self.lower_path_inner(resolved_segment, it.into(), infer_args),
|
||||
@ -516,7 +516,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||
TyDefId::TypeAliasId(it) => Some(it.into()),
|
||||
};
|
||||
let substs = self.substs_from_path_segment(segment, generic_def, infer_args, None);
|
||||
self.db.ty(typeable).subst(&substs)
|
||||
self.db.ty(typeable).substitute(&substs)
|
||||
}
|
||||
|
||||
/// Collect generic arguments from a path into a `Substs`. See also
|
||||
@ -620,7 +620,7 @@ impl<'a> TyLoweringContext<'a> {
|
||||
for default_ty in defaults.iter().skip(substs.len()) {
|
||||
// each default can depend on the previous parameters
|
||||
let substs_so_far = Substitution::from_iter(&Interner, substs.clone());
|
||||
substs.push(default_ty.clone().subst(&substs_so_far));
|
||||
substs.push(default_ty.clone().substitute(&substs_so_far));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -712,7 +712,7 @@ pub(crate) fn inherent_impl_substs(
|
||||
let vars = TyBuilder::subst_for_def(db, impl_id)
|
||||
.fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.binders.len(&Interner))
|
||||
.build();
|
||||
let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars);
|
||||
let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(&vars);
|
||||
let mut kinds = self_ty.binders.interned().to_vec();
|
||||
kinds.extend(
|
||||
iter::repeat(chalk_ir::WithKind::new(
|
||||
@ -774,7 +774,7 @@ fn transform_receiver_ty(
|
||||
AssocContainerId::ModuleId(_) => unreachable!(),
|
||||
};
|
||||
let sig = db.callable_item_signature(function_id.into());
|
||||
Some(sig.map(|s| s.params()[0].clone()).subst(&substs))
|
||||
Some(sig.map(|s| s.params()[0].clone()).substitute(&substs))
|
||||
}
|
||||
|
||||
pub fn implements_trait(
|
||||
|
@ -519,7 +519,7 @@ pub(super) fn convert_where_clauses(
|
||||
let generic_predicates = db.generic_predicates(def);
|
||||
let mut result = Vec::with_capacity(generic_predicates.len());
|
||||
for pred in generic_predicates.iter() {
|
||||
result.push(pred.clone().subst(substs).to_chalk(db));
|
||||
result.push(pred.clone().substitute(substs).to_chalk(db));
|
||||
}
|
||||
result
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ fn direct_super_trait_refs(db: &dyn HirDatabase, trait_ref: &TraitRef) -> Vec<Tr
|
||||
_ => None,
|
||||
})
|
||||
})
|
||||
.map(|pred| pred.subst(&trait_ref.substitution))
|
||||
.map(|pred| pred.substitute(&trait_ref.substitution))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user