Skip to content

Commit 0ed9f77

Browse files
Auto merge of #144377 - camsteffen:simplify-impl-of-method, r=<try>
Rename impl_of_method and trait_of_item
2 parents b56aaec + 448868a commit 0ed9f77

File tree

67 files changed

+106
-110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+106
-110
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23322332
if let Some(body_expr) = finder.body_expr
23332333
&& let Some(loop_span) = finder.loop_span
23342334
&& let Some(def_id) = typeck_results.type_dependent_def_id(body_expr.hir_id)
2335-
&& let Some(trait_did) = tcx.trait_of_item(def_id)
2335+
&& let Some(trait_did) = tcx.trait_of_assoc(def_id)
23362336
&& tcx.is_diagnostic_item(sym::Iterator, trait_did)
23372337
{
23382338
if let Some(loop_bind) = finder.loop_bind {

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ impl<'tcx> BorrowedContentSource<'tcx> {
942942
fn from_call(func: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option<Self> {
943943
match *func.kind() {
944944
ty::FnDef(def_id, args) => {
945-
let trait_id = tcx.trait_of_item(def_id)?;
945+
let trait_id = tcx.trait_of_assoc(def_id)?;
946946

947947
if tcx.is_lang_item(trait_id, LangItem::Deref)
948948
|| tcx.is_lang_item(trait_id, LangItem::DerefMut)

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
682682
}
683683
let my_def = self.body.source.def_id();
684684
let Some(td) =
685-
self.infcx.tcx.impl_of_method(my_def).and_then(|x| self.infcx.tcx.trait_id_of_impl(x))
685+
self.infcx.tcx.impl_of_assoc(my_def).and_then(|x| self.infcx.tcx.trait_id_of_impl(x))
686686
else {
687687
return (false, false, None);
688688
};
@@ -880,7 +880,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
880880
let opt_suggestions = tcx
881881
.typeck(path_segment.hir_id.owner.def_id)
882882
.type_dependent_def_id(expr.hir_id)
883-
.and_then(|def_id| tcx.impl_of_method(def_id))
883+
.and_then(|def_id| tcx.impl_of_assoc(def_id))
884884
.map(|def_id| tcx.associated_items(def_id))
885885
.map(|assoc_items| {
886886
assoc_items
@@ -1056,7 +1056,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10561056
.tcx
10571057
.typeck(path_segment.hir_id.owner.def_id)
10581058
.type_dependent_def_id(cur_expr.hir_id)
1059-
.and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
1059+
.and_then(|def_id| self.infcx.tcx.impl_of_assoc(def_id))
10601060
.map(|def_id| self.infcx.tcx.associated_items(def_id))
10611061
.map(|assoc_items| {
10621062
assoc_items.filter_by_name_unhygienic(sym::iter_mut).peekable()

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
17611761
);
17621762

17631763
assert!(!matches!(
1764-
tcx.impl_of_method(def_id).map(|imp| tcx.def_kind(imp)),
1764+
tcx.impl_of_assoc(def_id).map(|imp| tcx.def_kind(imp)),
17651765
Some(DefKind::Impl { of_trait: true })
17661766
));
17671767
self.prove_predicates(

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
533533
// First, let's see if this is a method within an inherent impl. Because
534534
// if yes, we want to make the result subroutine DIE a child of the
535535
// subroutine's self-type.
536-
if let Some(impl_def_id) = cx.tcx.impl_of_method(instance.def_id()) {
536+
if let Some(impl_def_id) = cx.tcx.impl_of_assoc(instance.def_id()) {
537537
// If the method does *not* belong to a trait, proceed
538538
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
539539
let impl_self_ty = cx.tcx.instantiate_and_normalize_erasing_regions(

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> DefIdMap<S
8686
// Only consider nodes that actually have exported symbols.
8787
match tcx.def_kind(def_id) {
8888
DefKind::Fn | DefKind::Static { .. } => {}
89-
DefKind::AssocFn if tcx.impl_of_method(def_id.to_def_id()).is_some() => {}
89+
DefKind::AssocFn if tcx.impl_of_assoc(def_id.to_def_id()).is_some() => {}
9090
_ => return None,
9191
};
9292

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
784784
self.revalidate_conditional_constness(callee, fn_args, *fn_span);
785785

786786
// Attempting to call a trait method?
787-
if let Some(trait_did) = tcx.trait_of_item(callee) {
787+
if let Some(trait_did) = tcx.trait_of_assoc(callee) {
788788
// We can't determine the actual callee here, so we have to do different checks
789789
// than usual.
790790

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ where
369369
assert!(promoted.is_none() || Q::ALLOW_PROMOTED);
370370

371371
// Don't peek inside trait associated constants.
372-
if promoted.is_none() && cx.tcx.trait_of_item(def).is_none() {
372+
if promoted.is_none() && cx.tcx.trait_of_assoc(def).is_none() {
373373
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def);
374374

375375
if !Q::in_qualifs(&qualifs) {

compiler/rustc_const_eval/src/interpret/call.rs

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

724-
let trait_def_id = tcx.trait_of_item(def_id).unwrap();
724+
let trait_def_id = tcx.trait_of_assoc(def_id).unwrap();
725725
let virtual_trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, virtual_instance.args);
726726
let existential_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
727727
let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);

compiler/rustc_hir/src/def.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ impl DefKind {
295295
}
296296
}
297297

298+
pub fn is_assoc(self) -> bool {
299+
matches!(self, DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy)
300+
}
301+
298302
/// This is a "module" in name resolution sense.
299303
#[inline]
300304
pub fn is_module_like(self) -> bool {

0 commit comments

Comments
 (0)