Skip to content

Commit b30be8f

Browse files
committed
Remove impl_trait_in_trait_parent
1 parent c4dd9a2 commit b30be8f

File tree

5 files changed

+12
-19
lines changed

5 files changed

+12
-19
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,8 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
15891589
if let ty::GenericArgKind::Type(ty) = arg.unpack()
15901590
&& let ty::Projection(proj) = ty.kind()
15911591
&& tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder
1592-
&& tcx.impl_trait_in_trait_parent(proj.item_def_id) == fn_def_id.to_def_id()
1592+
&& let (trait_fn_def_id, _) = tcx.def_path(proj.item_def_id).get_impl_trait_in_trait_data().unwrap()
1593+
&& trait_fn_def_id == fn_def_id.to_def_id()
15931594
{
15941595
let bounds = wfcx.tcx().explicit_item_bounds(proj.item_def_id);
15951596
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {

compiler/rustc_middle/src/ty/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2628,14 +2628,6 @@ impl<'tcx> TyCtxt<'tcx> {
26282628
pub fn is_const_default_method(self, def_id: DefId) -> bool {
26292629
matches!(self.trait_of_item(def_id), Some(trait_id) if self.has_attr(trait_id, sym::const_trait))
26302630
}
2631-
2632-
pub fn impl_trait_in_trait_parent(self, mut def_id: DefId) -> DefId {
2633-
while let def_kind = self.def_kind(def_id) && def_kind != DefKind::AssocFn {
2634-
debug_assert_eq!(def_kind, DefKind::ImplTraitPlaceholder);
2635-
def_id = self.parent(def_id);
2636-
}
2637-
def_id
2638-
}
26392631
}
26402632

26412633
/// Yields the parent function's `LocalDefId` if `def_id` is an `impl Trait` definition.

compiler/rustc_middle/src/ty/sty.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,10 @@ impl<'tcx> ProjectionTy<'tcx> {
11481148
match tcx.def_kind(self.item_def_id) {
11491149
DefKind::AssocTy | DefKind::AssocConst => tcx.parent(self.item_def_id),
11501150
DefKind::ImplTraitPlaceholder => {
1151-
tcx.parent(tcx.impl_trait_in_trait_parent(self.item_def_id))
1151+
let (fn_def_id, _) =
1152+
tcx.def_path(self.item_def_id).get_impl_trait_in_trait_data().unwrap();
1153+
1154+
tcx.parent(fn_def_id)
11521155
}
11531156
kind => bug!("unexpected DefKind in ProjectionTy: {kind:?}"),
11541157
}

compiler/rustc_privacy/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ where
129129
projection.trait_ref_and_own_substs(tcx)
130130
} else {
131131
// HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys
132-
let def_id = tcx.impl_trait_in_trait_parent(projection.item_def_id);
132+
let (def_id, _) =
133+
tcx.def_path(projection.item_def_id).get_impl_trait_in_trait_data().unwrap();
133134
let trait_generics = tcx.generics_of(def_id);
134135
(
135136
ty::TraitRef { def_id, substs: projection.substs.truncate_to(tcx, trait_generics) },

compiler/rustc_trait_selection/src/traits/project.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1324,13 +1324,8 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>(
13241324
) {
13251325
let tcx = selcx.tcx();
13261326
if tcx.def_kind(obligation.predicate.item_def_id) == DefKind::ImplTraitPlaceholder {
1327-
let trait_fn_def_id = if let Some((fn_def_id, _)) =
1328-
tcx.def_path(obligation.predicate.item_def_id).get_impl_trait_in_trait_data()
1329-
{
1330-
fn_def_id
1331-
} else {
1332-
tcx.impl_trait_in_trait_parent(obligation.predicate.item_def_id)
1333-
};
1327+
let (trait_fn_def_id, _) =
1328+
tcx.def_path(obligation.predicate.item_def_id).get_impl_trait_in_trait_data().unwrap();
13341329
// If we are trying to project an RPITIT with trait's default `Self` parameter,
13351330
// then we must be within a default trait body.
13361331
if obligation.predicate.self_ty()
@@ -2238,7 +2233,8 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
22382233
let tcx = selcx.tcx();
22392234
let mut obligations = data.nested;
22402235

2241-
let trait_fn_def_id = tcx.impl_trait_in_trait_parent(obligation.predicate.item_def_id);
2236+
let (trait_fn_def_id, _) =
2237+
tcx.def_path(obligation.predicate.item_def_id).get_impl_trait_in_trait_data().unwrap();
22422238
let Ok(leaf_def) = assoc_def(selcx, data.impl_def_id, trait_fn_def_id) else {
22432239
return Progress { term: tcx.ty_error().into(), obligations };
22442240
};

0 commit comments

Comments
 (0)