Skip to content

Commit dbf4b8a

Browse files
committed
Round 1: add some binders (fails due to losing bound vars and then rebinding them with Binder::dummy)
1 parent 2176e3a commit dbf4b8a

File tree

5 files changed

+33
-26
lines changed

5 files changed

+33
-26
lines changed

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,13 @@ impl<'tcx, T> Binder<'tcx, Option<T>> {
11281128
}
11291129
}
11301130

1131+
impl<'tcx, T: IntoIterator> Binder<'tcx, T> {
1132+
pub fn iter(self) -> impl Iterator<Item = ty::Binder<'tcx, T::Item>> {
1133+
let bound_vars = self.1;
1134+
self.0.into_iter().map(|v| Binder(v, bound_vars))
1135+
}
1136+
}
1137+
11311138
/// Represents the projection of an associated type. In explicit UFCS
11321139
/// form this would be written `<T as Trait<..>>::N`.
11331140
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]

src/librustdoc/clean/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ where
4444
discard_positive_impl: bool,
4545
) -> Option<Item> {
4646
let tcx = self.cx.tcx;
47-
let trait_ref = tcx.mk_trait_ref(trait_def_id, [ty]);
47+
let trait_ref = ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, [ty]));
4848
if !self.cx.generated_synthetics.insert((ty, trait_def_id)) {
4949
debug!("get_auto_trait_impl_for({:?}): already generated, aborting", trait_ref);
5050
return None;

src/librustdoc/clean/blanket_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
105105
// the post-inference `trait_ref`, as it's more accurate.
106106
trait_: Some(clean_trait_ref_with_bindings(
107107
cx,
108-
trait_ref.0,
108+
ty::Binder::dummy(trait_ref.0),
109109
ThinVec::new(),
110110
)),
111111
for_: clean_middle_ty(ty.0, cx, None),

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ pub(crate) fn build_impl(
496496
),
497497
};
498498
let polarity = tcx.impl_polarity(did);
499-
let trait_ = associated_trait.map(|t| clean_trait_ref_with_bindings(cx, t, ThinVec::new()));
499+
let trait_ = associated_trait
500+
.map(|t| clean_trait_ref_with_bindings(cx, ty::Binder::dummy(t), ThinVec::new()));
500501
if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() {
501502
super::build_deref_target_impls(cx, &trait_items, ret);
502503
}

src/librustdoc/clean/mod.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn clean_generic_bound<'tcx>(
127127
hir::GenericBound::LangItemTrait(lang_item, span, _, generic_args) => {
128128
let def_id = cx.tcx.require_lang_item(lang_item, Some(span));
129129

130-
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder();
130+
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id);
131131

132132
let generic_args = clean_generic_args(generic_args, cx);
133133
let GenericArgs::AngleBracketed { bindings, .. } = generic_args
@@ -156,17 +156,18 @@ fn clean_generic_bound<'tcx>(
156156

157157
pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
158158
cx: &mut DocContext<'tcx>,
159-
trait_ref: ty::TraitRef<'tcx>,
159+
trait_ref: ty::PolyTraitRef<'tcx>,
160160
bindings: ThinVec<TypeBinding>,
161161
) -> Path {
162-
let kind = cx.tcx.def_kind(trait_ref.def_id).into();
162+
let kind = cx.tcx.def_kind(trait_ref.def_id()).into();
163163
if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) {
164-
span_bug!(cx.tcx.def_span(trait_ref.def_id), "`TraitRef` had unexpected kind {:?}", kind);
164+
span_bug!(cx.tcx.def_span(trait_ref.def_id()), "`TraitRef` had unexpected kind {:?}", kind);
165165
}
166-
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
167-
let path = external_path(cx, trait_ref.def_id, true, bindings, trait_ref.substs);
166+
inline::record_extern_fqn(cx, trait_ref.def_id(), kind);
167+
let path =
168+
external_path(cx, trait_ref.def_id(), true, bindings, trait_ref.skip_binder().substs);
168169

169-
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
170+
debug!(?trait_ref);
170171

171172
path
172173
}
@@ -187,7 +188,7 @@ fn clean_poly_trait_ref_with_bindings<'tcx>(
187188
})
188189
.collect();
189190

190-
let trait_ = clean_trait_ref_with_bindings(cx, poly_trait_ref.skip_binder(), bindings);
191+
let trait_ = clean_trait_ref_with_bindings(cx, poly_trait_ref, bindings);
191192
GenericBound::TraitBound(
192193
PolyTrait { trait_, generic_params: late_bound_regions },
193194
hir::TraitBoundModifier::None,
@@ -398,40 +399,39 @@ fn clean_projection_predicate<'tcx>(
398399
})
399400
.collect();
400401

401-
let ty::ProjectionPredicate { projection_ty, term } = pred.skip_binder();
402-
403402
WherePredicate::EqPredicate {
404-
lhs: Box::new(clean_projection(projection_ty, cx, None)),
405-
rhs: Box::new(clean_middle_term(term, cx)),
403+
lhs: Box::new(clean_projection(pred.map_bound(|p| p.projection_ty), cx, None)),
404+
rhs: Box::new(clean_middle_term(pred.skip_binder().term, cx)),
406405
bound_params: late_bound_regions,
407406
}
408407
}
409408

410409
fn clean_projection<'tcx>(
411-
ty: ty::ProjectionTy<'tcx>,
410+
ty: ty::Binder<'tcx, ty::ProjectionTy<'tcx>>,
412411
cx: &mut DocContext<'tcx>,
413412
def_id: Option<DefId>,
414413
) -> Type {
415-
if cx.tcx.def_kind(ty.item_def_id) == DefKind::ImplTraitPlaceholder {
414+
if cx.tcx.def_kind(ty.skip_binder().item_def_id) == DefKind::ImplTraitPlaceholder {
416415
let bounds = cx
417416
.tcx
418-
.explicit_item_bounds(ty.item_def_id)
417+
.explicit_item_bounds(ty.skip_binder().item_def_id)
419418
.iter()
420-
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, ty.substs))
419+
.map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, ty.skip_binder().substs))
421420
.collect::<Vec<_>>();
422421
return clean_middle_opaque_bounds(cx, bounds);
423422
}
424423

425-
let trait_ = clean_trait_ref_with_bindings(cx, ty.trait_ref(cx.tcx), ThinVec::new());
426-
let self_type = clean_middle_ty(ty.self_ty(), cx, None);
424+
let trait_ =
425+
clean_trait_ref_with_bindings(cx, ty.map_bound(|ty| ty.trait_ref(cx.tcx)), ThinVec::new());
426+
let self_type = clean_middle_ty(ty.skip_binder().self_ty(), cx, None);
427427
let self_def_id = if let Some(def_id) = def_id {
428428
cx.tcx.opt_parent(def_id).or(Some(def_id))
429429
} else {
430430
self_type.def_id(&cx.cache)
431431
};
432432
let should_show_cast = compute_should_show_cast(self_def_id, &trait_, &self_type);
433433
Type::QPath(Box::new(QPathData {
434-
assoc: projection_to_path_segment(ty, cx),
434+
assoc: projection_to_path_segment(ty.skip_binder(), cx),
435435
should_show_cast,
436436
self_type,
437437
trait_,
@@ -783,7 +783,7 @@ fn clean_ty_generics<'tcx>(
783783

784784
let proj = projection.map(|p| {
785785
(
786-
clean_projection(p.skip_binder().projection_ty, cx, None),
786+
clean_projection(p.map_bound(|p| p.projection_ty), cx, None),
787787
p.skip_binder().term,
788788
)
789789
});
@@ -1076,11 +1076,10 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
10761076
c_variadic: sig.skip_binder().c_variadic,
10771077
inputs: Arguments {
10781078
values: sig
1079-
.skip_binder()
10801079
.inputs()
10811080
.iter()
10821081
.map(|t| Argument {
1083-
type_: clean_middle_ty(*t, cx, None),
1082+
type_: clean_middle_ty(*t.skip_binder(), cx, None),
10841083
name: names
10851084
.next()
10861085
.map(|i| i.name)
@@ -1781,7 +1780,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
17811780
}
17821781
ty::Tuple(t) => Tuple(t.iter().map(|t| clean_middle_ty(t, cx, None)).collect()),
17831782

1784-
ty::Projection(ref data) => clean_projection(*data, cx, def_id),
1783+
ty::Projection(ref data) => clean_projection(ty::Binder::dummy(*data), cx, def_id),
17851784

17861785
ty::Param(ref p) => {
17871786
if let Some(bounds) = cx.impl_trait_bounds.remove(&p.index.into()) {

0 commit comments

Comments
 (0)