Skip to content

rename TraitRef::from_method to from_assoc #145147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/ty/generic_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down
Loading