Skip to content

Commit f580d11

Browse files
committed
[wip] latest
1 parent c7f2c7a commit f580d11

File tree

3 files changed

+194
-103
lines changed

3 files changed

+194
-103
lines changed

src/librustdoc/clean/auto_trait.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ fn clean_param_env<'tcx>(
196196
.map(|pred| (pred, rustc_span::DUMMY_SP))
197197
.collect();
198198

199-
let mut where_predicates = super::modern::clean_predicates(cx, predicates);
199+
let mut where_predicates =
200+
super::modern::clean_predicates(cx, predicates, &mut super::modern::WhereClause::default());
200201
// FIXME: these no longer get "simplif[ied]::where_clauses"
201202
where_predicates.extend(clean_region_outlives_constraints(&region_data, generics));
202203

src/librustdoc/clean/mod.rs

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -777,26 +777,40 @@ fn clean_ty_generics<'tcx>(
777777
// FIXME: does this handle Sized/?Sized properly?
778778
for (index, predicates) in apits {
779779
// FIXME: fix up API of clean_pred instead
780-
let mut where_predicates = modern::clean_predicates(cx, predicates);
781-
let Some(WherePredicate::BoundPredicate { bounds, .. }) = where_predicates.pop() else {
782-
unreachable!()
780+
let mut where_predicates =
781+
modern::clean_predicates(cx, predicates, &mut modern::Apit::default());
782+
let mut bounds = match where_predicates.pop() {
783+
Some(WherePredicate::BoundPredicate { bounds, .. }) => bounds,
784+
Some(_) => unreachable!(),
785+
None => Vec::new(),
783786
};
787+
788+
// Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
789+
if bounds.iter().all(|bound| !bound.is_trait_bound()) {
790+
bounds.insert(0, GenericBound::sized(cx));
791+
}
784792
cx.impl_trait_bounds.insert(index.into(), bounds);
785793
}
786794

787-
let where_predicates = modern::clean_predicates(cx, predicates);
795+
let mut cleaner = modern::WhereClause::default();
796+
let mut where_predicates = modern::clean_predicates(cx, predicates, &mut cleaner);
788797

789-
// FIXME: we no longer have access to `sized: UnordMap`
790-
// for param in &generics.own_params {
791-
// if !sized.contains(&param.index) {
792-
// // FIXME: is this correct if we have parent generics?
793-
// where_predicates.push(WherePredicate::BoundPredicate {
794-
// ty: Type::Generic(param.name),
795-
// bounds: vec![GenericBound::maybe_sized(cx)],
796-
// bound_params: Vec::new(),
797-
// })
798-
// }
799-
// }
798+
// FIXME: This adds extra clauses, instead of modifying existing bounds
799+
// Smh. make clean_preds add those bounds onto existing ones if available
800+
// NOTE: Maybe we should just cave in an add an `Option<ty::Generics>` param to clean_preds
801+
// FIXME: This is so stupid
802+
for param in &generics.own_params {
803+
if let ty::GenericParamDefKind::Type { synthetic: false, .. } = param.kind
804+
&& !cleaner.sized.contains(&param.index)
805+
{
806+
// FIXME: is this correct if we have parent generics?
807+
where_predicates.push(WherePredicate::BoundPredicate {
808+
ty: Type::Generic(param.name),
809+
bounds: vec![GenericBound::maybe_sized(cx)],
810+
bound_params: Vec::new(),
811+
})
812+
}
813+
}
800814

801815
Generics { params, where_predicates }
802816
}
@@ -2165,20 +2179,23 @@ fn clean_middle_opaque_bounds<'tcx>(
21652179
// FIXME: we currentyl elide `Sized` bc it looks for bounded_ty=`ty::Param` but we don't
21662180
// care about that here bc we want to look for bounded_ty=Alias(Opaque) (which we can
21672181
// actually assume / don't need to check)
2168-
let mut where_predicates = modern::clean_predicates(cx, predicates);
2169-
let Some(WherePredicate::BoundPredicate { mut bounds, .. }) = where_predicates.pop() else {
2170-
unreachable!()
2182+
// FIXME: Make it so clean_pred inserts `Sized` before any outlives bounds
2183+
let mut where_predicates =
2184+
modern::clean_predicates(cx, predicates, &mut modern::OpaqueTy::default());
2185+
let mut bounds = match where_predicates.pop() {
2186+
Some(WherePredicate::BoundPredicate { bounds, .. }) => bounds,
2187+
Some(_) => unreachable!(),
2188+
None => Vec::new(),
21712189
};
21722190

21732191
// FIXME: rewrite this, too
21742192
// <LEGACY>
21752193

2176-
// Move trait bounds to the front.
2177-
bounds.sort_by_key(|b| !b.is_trait_bound());
2194+
// // Move trait bounds to the front.
2195+
// bounds.sort_by_key(|b| !b.is_trait_bound());
21782196

21792197
// Add back a `Sized` bound if there are no *trait* bounds remaining (incl. `?Sized`).
2180-
// Since all potential trait bounds are at the front we can just check the first bound.
2181-
if bounds.first().map_or(true, |b| !b.is_trait_bound()) {
2198+
if bounds.iter().all(|bound| !bound.is_trait_bound()) {
21822199
bounds.insert(0, GenericBound::sized(cx));
21832200
}
21842201

0 commit comments

Comments
 (0)