Skip to content

Commit 686d3db

Browse files
authored
Unrolled build for #145134
Rollup merge of #145134 - camsteffen:indirect-assoc-parent, r=cjgillot Reduce indirect assoc parent queries Simplify some code that uses multiple queries to get the parent of an associated item.
2 parents 2de2456 + eec8585 commit 686d3db

File tree

5 files changed

+5
-8
lines changed

5 files changed

+5
-8
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
517517
projection.args == trait_identity_args
518518
// FIXME(return_type_notation): This check should be more robust
519519
&& !tcx.is_impl_trait_in_trait(projection.def_id)
520-
&& tcx.associated_item(projection.def_id).container_id(tcx)
521-
== def_id.to_def_id()
520+
&& tcx.parent(projection.def_id) == def_id.to_def_id()
522521
} else {
523522
false
524523
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
755755
let limit = if candidates.len() == 5 { 5 } else { 4 };
756756

757757
for (index, &item) in candidates.iter().take(limit).enumerate() {
758-
let impl_ = tcx.impl_of_assoc(item).unwrap();
758+
let impl_ = tcx.parent(item);
759759

760760
let note_span = if item.is_local() {
761761
Some(tcx.def_span(item))

compiler/rustc_lint/src/default_could_be_derived.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
6262
// Look for manual implementations of `Default`.
6363
let Some(default_def_id) = cx.tcx.get_diagnostic_item(sym::Default) else { return };
6464
let hir::ImplItemKind::Fn(_sig, body_id) = impl_item.kind else { return };
65-
let assoc = cx.tcx.associated_item(impl_item.owner_id);
66-
let parent = assoc.container_id(cx.tcx);
65+
let parent = cx.tcx.parent(impl_item.owner_id.to_def_id());
6766
if find_attr!(cx.tcx.get_all_attrs(parent), AttributeKind::AutomaticallyDerived(..)) {
6867
// We don't care about what `#[derive(Default)]` produces in this lint.
6968
return;

compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,15 +653,14 @@ impl<T> Trait<T> for X {
653653
)
654654
);
655655
let impl_comparison = matches!(cause_code, ObligationCauseCode::CompareImplItem { .. });
656-
let assoc = tcx.associated_item(proj_ty.def_id);
657656
if impl_comparison {
658657
// We do not want to suggest calling functions when the reason of the
659658
// type error is a comparison of an `impl` with its `trait`.
660659
} else {
661660
let point_at_assoc_fn = if callable_scope
662661
&& self.point_at_methods_that_satisfy_associated_type(
663662
diag,
664-
assoc.container_id(tcx),
663+
tcx.parent(proj_ty.def_id),
665664
current_method_ident,
666665
proj_ty.def_id,
667666
values.expected,

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1662,7 +1662,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
16621662
}
16631663

16641664
let trait_segments = &p.segments[..p.segments.len() - 1];
1665-
let trait_def = cx.tcx.associated_item(p.res.def_id()).container_id(cx.tcx);
1665+
let trait_def = cx.tcx.parent(p.res.def_id());
16661666
let trait_ = self::Path {
16671667
res: Res::Def(DefKind::Trait, trait_def),
16681668
segments: trait_segments.iter().map(|x| clean_path_segment(x, cx)).collect(),

0 commit comments

Comments
 (0)