rename TraitRef::from_method to from_assoc
also add a note to `GenericArgs::truncate_to`
This commit is contained in:
@@ -142,7 +142,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
||||
|err, self_ty, trait_id| {
|
||||
// FIXME(const_trait_impl): Do we need any of this on the non-const codepath?
|
||||
|
||||
let trait_ref = TraitRef::from_method(tcx, trait_id, self.args);
|
||||
let trait_ref = TraitRef::from_assoc(tcx, trait_id, self.args);
|
||||
|
||||
match self_ty.kind() {
|
||||
Param(param_ty) => {
|
||||
|
||||
@@ -732,7 +732,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||
let tcx = *self.tcx;
|
||||
|
||||
let trait_def_id = tcx.trait_of_assoc(def_id).unwrap();
|
||||
let virtual_trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, virtual_instance.args);
|
||||
let virtual_trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, virtual_instance.args);
|
||||
let existential_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
|
||||
let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);
|
||||
|
||||
|
||||
@@ -290,11 +290,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
||||
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
|
||||
let trait_def_id = self.parent(def_id);
|
||||
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
|
||||
let trait_generics = self.generics_of(trait_def_id);
|
||||
(
|
||||
ty::TraitRef::new_from_args(self, trait_def_id, args.truncate_to(self, trait_generics)),
|
||||
&args[trait_generics.count()..],
|
||||
)
|
||||
let trait_ref = ty::TraitRef::from_assoc(self, trait_def_id, args);
|
||||
(trait_ref, &args[trait_ref.args.len()..])
|
||||
}
|
||||
|
||||
fn mk_args(self, args: &[Self::GenericArg]) -> ty::GenericArgsRef<'tcx> {
|
||||
|
||||
@@ -585,6 +585,9 @@ impl<'tcx> GenericArgs<'tcx> {
|
||||
tcx.mk_args_from_iter(target_args.iter().chain(self.iter().skip(defs.count())))
|
||||
}
|
||||
|
||||
/// Truncates this list of generic args to have at most the number of args in `generics`.
|
||||
///
|
||||
/// You might be looking for [`TraitRef::from_assoc`](super::TraitRef::from_assoc).
|
||||
pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> {
|
||||
tcx.mk_args(&self[..generics.count()])
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ pub(crate) fn transform_instance<'tcx>(
|
||||
let upcast_ty = match tcx.trait_of_assoc(def_id) {
|
||||
Some(trait_id) => trait_object_ty(
|
||||
tcx,
|
||||
ty::Binder::dummy(ty::TraitRef::from_method(tcx, trait_id, instance.args)),
|
||||
ty::Binder::dummy(ty::TraitRef::from_assoc(tcx, trait_id, instance.args)),
|
||||
),
|
||||
// drop_in_place won't have a defining trait, skip the upcast
|
||||
None => instance.args.type_at(0),
|
||||
@@ -481,7 +481,7 @@ fn implemented_method<'tcx>(
|
||||
trait_method = trait_method_bound;
|
||||
method_id = instance.def_id();
|
||||
trait_id = tcx.trait_of_assoc(method_id)?;
|
||||
trait_ref = ty::EarlyBinder::bind(TraitRef::from_method(tcx, trait_id, instance.args));
|
||||
trait_ref = ty::EarlyBinder::bind(TraitRef::from_assoc(tcx, trait_id, instance.args));
|
||||
trait_id
|
||||
} else {
|
||||
return None;
|
||||
|
||||
@@ -763,7 +763,7 @@ fn instantiate_and_check_impossible_predicates<'tcx>(
|
||||
// Specifically check trait fulfillment to avoid an error when trying to resolve
|
||||
// associated items.
|
||||
if let Some(trait_def_id) = tcx.trait_of_assoc(key.0) {
|
||||
let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1);
|
||||
let trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, key.1);
|
||||
predicates.push(trait_ref.upcast(tcx));
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ fn resolve_associated_item<'tcx>(
|
||||
) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
|
||||
debug!(?trait_item_id, ?typing_env, ?trait_id, ?rcvr_args, "resolve_associated_item");
|
||||
|
||||
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_args);
|
||||
let trait_ref = ty::TraitRef::from_assoc(tcx, trait_id, rcvr_args);
|
||||
|
||||
let input = typing_env.as_query_input(trait_ref);
|
||||
let vtbl = match tcx.codegen_select_candidate(input) {
|
||||
@@ -238,7 +238,7 @@ fn resolve_associated_item<'tcx>(
|
||||
Some(ty::Instance::new_raw(leaf_def.item.def_id, args))
|
||||
}
|
||||
traits::ImplSource::Builtin(BuiltinImplSource::Object(_), _) => {
|
||||
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_args);
|
||||
let trait_ref = ty::TraitRef::from_assoc(tcx, trait_id, rcvr_args);
|
||||
if trait_ref.has_non_region_infer() || trait_ref.has_non_region_param() {
|
||||
// We only resolve totally substituted vtable entries.
|
||||
None
|
||||
|
||||
@@ -82,7 +82,7 @@ impl<I: Interner> TraitRef<I> {
|
||||
Self::new_from_args(interner, trait_def_id, args)
|
||||
}
|
||||
|
||||
pub fn from_method(interner: I, trait_id: I::DefId, args: I::GenericArgs) -> TraitRef<I> {
|
||||
pub fn from_assoc(interner: I, trait_id: I::DefId, args: I::GenericArgs) -> TraitRef<I> {
|
||||
let generics = interner.generics_of(trait_id);
|
||||
TraitRef::new(interner, trait_id, args.iter().take(generics.count()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user