Skip to content

Commit ca70ed8

Browse files
remove Clean trait implementation for hir::GenericBound
1 parent 46d17d6 commit ca70ed8

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

src/librustdoc/clean/mod.rs

+41-41
Original file line numberDiff line numberDiff line change
@@ -126,40 +126,40 @@ impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
126126
}
127127
}
128128

129-
impl<'tcx> Clean<'tcx, Option<GenericBound>> for hir::GenericBound<'tcx> {
130-
fn clean(&self, cx: &mut DocContext<'tcx>) -> Option<GenericBound> {
131-
Some(match *self {
132-
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(clean_lifetime(lt, cx)),
133-
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => {
134-
let def_id = cx.tcx.require_lang_item(lang_item, Some(span));
135-
136-
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder();
137-
138-
let generic_args = generic_args.clean(cx);
139-
let GenericArgs::AngleBracketed { bindings, .. } = generic_args
140-
else {
141-
bug!("clean: parenthesized `GenericBound::LangItemTrait`");
142-
};
129+
fn clean_generic_bound<'tcx>(
130+
bound: &hir::GenericBound<'tcx>,
131+
cx: &mut DocContext<'tcx>,
132+
) -> Option<GenericBound> {
133+
Some(match *bound {
134+
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(clean_lifetime(lt, cx)),
135+
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => {
136+
let def_id = cx.tcx.require_lang_item(lang_item, Some(span));
137+
138+
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder();
139+
140+
let generic_args = generic_args.clean(cx);
141+
let GenericArgs::AngleBracketed { bindings, .. } = generic_args
142+
else {
143+
bug!("clean: parenthesized `GenericBound::LangItemTrait`");
144+
};
143145

144-
let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings);
145-
GenericBound::TraitBound(
146-
PolyTrait { trait_, generic_params: vec![] },
147-
hir::TraitBoundModifier::None,
148-
)
146+
let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings);
147+
GenericBound::TraitBound(
148+
PolyTrait { trait_, generic_params: vec![] },
149+
hir::TraitBoundModifier::None,
150+
)
151+
}
152+
hir::GenericBound::Trait(ref t, modifier) => {
153+
// `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
154+
if modifier == hir::TraitBoundModifier::MaybeConst
155+
&& cx.tcx.lang_items().destruct_trait() == Some(t.trait_ref.trait_def_id().unwrap())
156+
{
157+
return None;
149158
}
150-
hir::GenericBound::Trait(ref t, modifier) => {
151-
// `T: ~const Destruct` is hidden because `T: Destruct` is a no-op.
152-
if modifier == hir::TraitBoundModifier::MaybeConst
153-
&& cx.tcx.lang_items().destruct_trait()
154-
== Some(t.trait_ref.trait_def_id().unwrap())
155-
{
156-
return None;
157-
}
158159

159-
GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier)
160-
}
161-
})
162-
}
160+
GenericBound::TraitBound(clean_poly_trait_ref(t, cx), modifier)
161+
}
162+
})
163163
}
164164

165165
pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
@@ -294,14 +294,14 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for hir::WherePredicate<'tcx> {
294294
.collect();
295295
WherePredicate::BoundPredicate {
296296
ty: clean_ty(wbp.bounded_ty, cx),
297-
bounds: wbp.bounds.iter().filter_map(|x| x.clean(cx)).collect(),
297+
bounds: wbp.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
298298
bound_params,
299299
}
300300
}
301301

302302
hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate {
303303
lifetime: clean_lifetime(wrp.lifetime, cx),
304-
bounds: wrp.bounds.iter().filter_map(|x| x.clean(cx)).collect(),
304+
bounds: wrp.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
305305
},
306306

307307
hir::WherePredicate::EqPredicate(ref wrp) => WherePredicate::EqPredicate {
@@ -531,7 +531,7 @@ fn clean_generic_param<'tcx>(
531531
.bounds_for_param(did)
532532
.filter(|bp| bp.origin != PredicateOrigin::WhereClause)
533533
.flat_map(|bp| bp.bounds)
534-
.filter_map(|x| x.clean(cx))
534+
.filter_map(|x| clean_generic_bound(x, cx))
535535
.collect()
536536
} else {
537537
Vec::new()
@@ -1041,7 +1041,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10411041
}
10421042
hir::TraitItemKind::Type(bounds, Some(default)) => {
10431043
let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx));
1044-
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1044+
let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect();
10451045
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None);
10461046
AssocTypeItem(
10471047
Box::new(Typedef {
@@ -1054,7 +1054,7 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
10541054
}
10551055
hir::TraitItemKind::Type(bounds, None) => {
10561056
let generics = enter_impl_trait(cx, |cx| trait_item.generics.clean(cx));
1057-
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
1057+
let bounds = bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect();
10581058
TyAssocTypeItem(Box::new(generics), bounds)
10591059
}
10601060
};
@@ -1507,7 +1507,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
15071507
TyKind::OpaqueDef(item_id, _) => {
15081508
let item = cx.tcx.hir().item(item_id);
15091509
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind {
1510-
ImplTrait(ty.bounds.iter().filter_map(|x| x.clean(cx)).collect())
1510+
ImplTrait(ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect())
15111511
} else {
15121512
unreachable!()
15131513
}
@@ -1911,7 +1911,7 @@ fn clean_maybe_renamed_item<'tcx>(
19111911
kind: ConstantKind::Local { body: body_id, def_id },
19121912
}),
19131913
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {
1914-
bounds: ty.bounds.iter().filter_map(|x| x.clean(cx)).collect(),
1914+
bounds: ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
19151915
generics: ty.generics.clean(cx),
19161916
}),
19171917
ItemKind::TyAlias(hir_ty, generics) => {
@@ -1929,7 +1929,7 @@ fn clean_maybe_renamed_item<'tcx>(
19291929
}),
19301930
ItemKind::TraitAlias(generics, bounds) => TraitAliasItem(TraitAlias {
19311931
generics: generics.clean(cx),
1932-
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(),
1932+
bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
19331933
}),
19341934
ItemKind::Union(ref variant_data, generics) => UnionItem(Union {
19351935
generics: generics.clean(cx),
@@ -1961,7 +1961,7 @@ fn clean_maybe_renamed_item<'tcx>(
19611961
def_id,
19621962
items,
19631963
generics: generics.clean(cx),
1964-
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(),
1964+
bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
19651965
})
19661966
}
19671967
ItemKind::ExternCrate(orig_name) => {
@@ -2241,7 +2241,7 @@ fn clean_type_binding<'tcx>(
22412241
TypeBindingKind::Equality { term: clean_hir_term(term, cx) }
22422242
}
22432243
hir::TypeBindingKind::Constraint { bounds } => TypeBindingKind::Constraint {
2244-
bounds: bounds.iter().filter_map(|b| b.clean(cx)).collect(),
2244+
bounds: bounds.iter().filter_map(|b| clean_generic_bound(b, cx)).collect(),
22452245
},
22462246
},
22472247
}

0 commit comments

Comments
 (0)