Skip to content

Commit 87475a9

Browse files
authored
Rollup merge of rust-lang#145147 - fee1-dead-contrib:push-mxxpmlpmzmsz, r=compiler-errors
rename `TraitRef::from_method` to `from_assoc` also add a note to `GenericArgs::truncate_to`
2 parents 6c09c40 + 2736d66 commit 87475a9

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
142142
|err, self_ty, trait_id| {
143143
// FIXME(const_trait_impl): Do we need any of this on the non-const codepath?
144144

145-
let trait_ref = TraitRef::from_method(tcx, trait_id, self.args);
145+
let trait_ref = TraitRef::from_assoc(tcx, trait_id, self.args);
146146

147147
match self_ty.kind() {
148148
Param(param_ty) => {

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
732732
let tcx = *self.tcx;
733733

734734
let trait_def_id = tcx.trait_of_assoc(def_id).unwrap();
735-
let virtual_trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, virtual_instance.args);
735+
let virtual_trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, virtual_instance.args);
736736
let existential_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
737737
let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);
738738

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
290290
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
291291
let trait_def_id = self.parent(def_id);
292292
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
293-
let trait_generics = self.generics_of(trait_def_id);
294-
(
295-
ty::TraitRef::new_from_args(self, trait_def_id, args.truncate_to(self, trait_generics)),
296-
&args[trait_generics.count()..],
297-
)
293+
let trait_ref = ty::TraitRef::from_assoc(self, trait_def_id, args);
294+
(trait_ref, &args[trait_ref.args.len()..])
298295
}
299296

300297
fn mk_args(self, args: &[Self::GenericArg]) -> ty::GenericArgsRef<'tcx> {

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ impl<'tcx> GenericArgs<'tcx> {
585585
tcx.mk_args_from_iter(target_args.iter().chain(self.iter().skip(defs.count())))
586586
}
587587

588+
/// Truncates this list of generic args to have at most the number of args in `generics`.
589+
///
590+
/// You might be looking for [`TraitRef::from_assoc`](super::TraitRef::from_assoc).
588591
pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> {
589592
tcx.mk_args(&self[..generics.count()])
590593
}

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ pub(crate) fn transform_instance<'tcx>(
342342
let upcast_ty = match tcx.trait_of_assoc(def_id) {
343343
Some(trait_id) => trait_object_ty(
344344
tcx,
345-
ty::Binder::dummy(ty::TraitRef::from_method(tcx, trait_id, instance.args)),
345+
ty::Binder::dummy(ty::TraitRef::from_assoc(tcx, trait_id, instance.args)),
346346
),
347347
// drop_in_place won't have a defining trait, skip the upcast
348348
None => instance.args.type_at(0),
@@ -481,7 +481,7 @@ fn implemented_method<'tcx>(
481481
trait_method = trait_method_bound;
482482
method_id = instance.def_id();
483483
trait_id = tcx.trait_of_assoc(method_id)?;
484-
trait_ref = ty::EarlyBinder::bind(TraitRef::from_method(tcx, trait_id, instance.args));
484+
trait_ref = ty::EarlyBinder::bind(TraitRef::from_assoc(tcx, trait_id, instance.args));
485485
trait_id
486486
} else {
487487
return None;

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ fn instantiate_and_check_impossible_predicates<'tcx>(
763763
// Specifically check trait fulfillment to avoid an error when trying to resolve
764764
// associated items.
765765
if let Some(trait_def_id) = tcx.trait_of_assoc(key.0) {
766-
let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1);
766+
let trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, key.1);
767767
predicates.push(trait_ref.upcast(tcx));
768768
}
769769

compiler/rustc_ty_utils/src/instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn resolve_associated_item<'tcx>(
109109
) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> {
110110
debug!(?trait_item_id, ?typing_env, ?trait_id, ?rcvr_args, "resolve_associated_item");
111111

112-
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_args);
112+
let trait_ref = ty::TraitRef::from_assoc(tcx, trait_id, rcvr_args);
113113

114114
let input = typing_env.as_query_input(trait_ref);
115115
let vtbl = match tcx.codegen_select_candidate(input) {
@@ -238,7 +238,7 @@ fn resolve_associated_item<'tcx>(
238238
Some(ty::Instance::new_raw(leaf_def.item.def_id, args))
239239
}
240240
traits::ImplSource::Builtin(BuiltinImplSource::Object(_), _) => {
241-
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_args);
241+
let trait_ref = ty::TraitRef::from_assoc(tcx, trait_id, rcvr_args);
242242
if trait_ref.has_non_region_infer() || trait_ref.has_non_region_param() {
243243
// We only resolve totally substituted vtable entries.
244244
None

compiler/rustc_type_ir/src/predicate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<I: Interner> TraitRef<I> {
8282
Self::new_from_args(interner, trait_def_id, args)
8383
}
8484

85-
pub fn from_method(interner: I, trait_id: I::DefId, args: I::GenericArgs) -> TraitRef<I> {
85+
pub fn from_assoc(interner: I, trait_id: I::DefId, args: I::GenericArgs) -> TraitRef<I> {
8686
let generics = interner.generics_of(trait_id);
8787
TraitRef::new(interner, trait_id, args.iter().take(generics.count()))
8888
}

0 commit comments

Comments
 (0)