Skip to content

Commit a616210

Browse files
committed
(temporarily) skip normalization in rustdoc
1 parent ef96c03 commit a616210

14 files changed

Lines changed: 114 additions & 51 deletions

File tree

src/librustdoc/clean/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn synthesize_auto_trait_impls<'tcx>(
2222
) -> Vec<clean::Item> {
2323
let tcx = cx.tcx;
2424
let typing_env = ty::TypingEnv::non_body_analysis(tcx, item_def_id);
25-
let ty = tcx.type_of(item_def_id).instantiate_identity();
25+
let ty = tcx.type_of(item_def_id).instantiate_identity().skip_normalization();
2626

2727
let finder = auto_trait::AutoTraitFinder::new(tcx);
2828
let mut auto_trait_impls: Vec<_> = cx

src/librustdoc/clean/blanket_impl.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ pub(crate) fn synthesize_blanket_impls(
4040
}
4141
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
4242
let args = infcx.fresh_args_for_item(DUMMY_SP, item_def_id);
43-
let impl_ty = ty.instantiate(tcx, args);
43+
let impl_ty = ty.instantiate(tcx, args).skip_normalization();
4444
let param_env = ty::ParamEnv::empty();
4545

4646
let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id);
47-
let impl_trait_ref = trait_ref.instantiate(tcx, impl_args);
47+
let impl_trait_ref = trait_ref.instantiate(tcx, impl_args).skip_normalization();
4848

4949
// Require the type the impl is implemented on to match
5050
// our type, and ignore the impl if there was a mismatch.
@@ -62,6 +62,7 @@ pub(crate) fn synthesize_blanket_impls(
6262
let predicates = tcx
6363
.predicates_of(impl_def_id)
6464
.instantiate(tcx, impl_args)
65+
.skip_normalization()
6566
.predicates
6667
.into_iter()
6768
.chain(Some(impl_trait_ref.upcast(tcx)));
@@ -95,11 +96,13 @@ pub(crate) fn synthesize_blanket_impls(
9596
// the post-inference `trait_ref`, as it's more accurate.
9697
trait_: Some(clean_trait_ref_with_constraints(
9798
cx,
98-
ty::Binder::dummy(trait_ref.instantiate_identity()),
99+
ty::Binder::dummy(
100+
trait_ref.instantiate_identity().skip_normalization(),
101+
),
99102
ThinVec::new(),
100103
)),
101104
for_: clean_middle_ty(
102-
ty::Binder::dummy(ty.instantiate_identity()),
105+
ty::Binder::dummy(ty.instantiate_identity().skip_normalization()),
103106
cx,
104107
None,
105108
None,
@@ -112,7 +115,9 @@ pub(crate) fn synthesize_blanket_impls(
112115
.collect(),
113116
polarity: ty::ImplPolarity::Positive,
114117
kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty(
115-
ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()),
118+
ty::Binder::dummy(
119+
trait_ref.instantiate_identity().skip_normalization().self_ty(),
120+
),
116121
cx,
117122
None,
118123
None,

src/librustdoc/clean/inline.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fn build_trait_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::TraitAlias {
309309
}
310310

311311
pub(super) fn build_function(cx: &mut DocContext<'_>, def_id: DefId) -> Box<clean::Function> {
312-
let sig = cx.tcx.fn_sig(def_id).instantiate_identity();
312+
let sig = cx.tcx.fn_sig(def_id).instantiate_identity().skip_normalization();
313313
// The generics need to be cleaned before the signature.
314314
let mut generics = clean_ty_generics(cx, def_id);
315315
let bound_vars = clean_bound_vars(sig.bound_vars(), cx.tcx);
@@ -369,7 +369,7 @@ fn build_type_alias(
369369
did: DefId,
370370
ret: &mut Vec<Item>,
371371
) -> Box<clean::TypeAlias> {
372-
let ty = cx.tcx.type_of(did).instantiate_identity();
372+
let ty = cx.tcx.type_of(did).instantiate_identity().skip_normalization();
373373
let type_ = clean_middle_ty(ty::Binder::dummy(ty), cx, Some(did), None);
374374
let inner_type = clean_ty_alias_inner_type(ty, cx, ret);
375375

@@ -488,7 +488,7 @@ pub(crate) fn build_impl(
488488
let for_ = match &impl_item {
489489
Some(impl_) => clean_ty(impl_.self_ty, cx),
490490
None => clean_middle_ty(
491-
ty::Binder::dummy(tcx.type_of(did).instantiate_identity()),
491+
ty::Binder::dummy(tcx.type_of(did).instantiate_identity().skip_normalization()),
492492
cx,
493493
Some(did),
494494
None,
@@ -749,7 +749,7 @@ fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
749749
let mut generics = clean_ty_generics(cx, def_id);
750750
clean::simplify::move_bounds_to_generic_parameters(&mut generics);
751751
let ty = clean_middle_ty(
752-
ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()),
752+
ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity().skip_normalization()),
753753
cx,
754754
None,
755755
None,
@@ -760,7 +760,7 @@ fn build_const_item(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
760760
fn build_static(cx: &mut DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
761761
clean::Static {
762762
type_: Box::new(clean_middle_ty(
763-
ty::Binder::dummy(cx.tcx.type_of(did).instantiate_identity()),
763+
ty::Binder::dummy(cx.tcx.type_of(did).instantiate_identity().skip_normalization()),
764764
cx,
765765
Some(did),
766766
None,

src/librustdoc/clean/mod.rs

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ use rustc_hir::{LangItem, PredicateOrigin, find_attr};
4646
use rustc_hir_analysis::{lower_const_arg_for_rustdoc, lower_ty};
4747
use rustc_middle::metadata::Reexport;
4848
use rustc_middle::middle::resolve_bound_vars as rbv;
49-
use rustc_middle::ty::{self, AdtKind, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, TypingMode};
49+
use rustc_middle::ty::{
50+
self, AdtKind, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, TypingMode, Unnormalized,
51+
};
5052
use rustc_middle::{bug, span_bug};
5153
use rustc_span::ExpnKind;
5254
use rustc_span::hygiene::{AstPass, MacroKind};
@@ -507,7 +509,8 @@ fn clean_hir_term<'tcx>(
507509
hir::Term::Ty(ty) => Term::Type(clean_ty(ty, cx)),
508510
hir::Term::Const(c) => {
509511
// FIXME(generic_const_items): this should instantiate with the alias item's args
510-
let ty = cx.tcx.type_of(assoc_item.unwrap()).instantiate_identity();
512+
let ty =
513+
cx.tcx.type_of(assoc_item.unwrap()).instantiate_identity().skip_normalization();
511514
let ct = lower_const_arg_for_rustdoc(cx.tcx, c, ty);
512515
Term::Constant(clean_middle_const(ty::Binder::dummy(ct)))
513516
}
@@ -590,7 +593,9 @@ fn clean_generic_param_def(
590593
&& has_default
591594
{
592595
Some(clean_middle_ty(
593-
ty::Binder::dummy(cx.tcx.type_of(def.def_id).instantiate_identity()),
596+
ty::Binder::dummy(
597+
cx.tcx.type_of(def.def_id).instantiate_identity().skip_normalization(),
598+
),
594599
cx,
595600
Some(def.def_id),
596601
None,
@@ -611,7 +616,9 @@ fn clean_generic_param_def(
611616
def.name,
612617
GenericParamDefKind::Const {
613618
ty: Box::new(clean_middle_ty(
614-
ty::Binder::dummy(cx.tcx.type_of(def.def_id).instantiate_identity()),
619+
ty::Binder::dummy(
620+
cx.tcx.type_of(def.def_id).instantiate_identity().skip_normalization(),
621+
),
615622
cx,
616623
Some(def.def_id),
617624
None,
@@ -620,7 +627,11 @@ fn clean_generic_param_def(
620627
&& has_default
621628
{
622629
Some(Box::new(
623-
cx.tcx.const_param_default(def.def_id).instantiate_identity().to_string(),
630+
cx.tcx
631+
.const_param_default(def.def_id)
632+
.instantiate_identity()
633+
.skip_normalization()
634+
.to_string(),
624635
))
625636
} else {
626637
None
@@ -1328,7 +1339,9 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
13281339
let kind = match assoc_item.kind {
13291340
ty::AssocKind::Const { .. } => {
13301341
let ty = clean_middle_ty(
1331-
ty::Binder::dummy(tcx.type_of(assoc_item.def_id).instantiate_identity()),
1342+
ty::Binder::dummy(
1343+
tcx.type_of(assoc_item.def_id).instantiate_identity().skip_normalization(),
1344+
),
13321345
cx,
13331346
Some(assoc_item.def_id),
13341347
None,
@@ -1363,13 +1376,18 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
13631376

13641377
if has_self {
13651378
let self_ty = match assoc_item.container {
1366-
ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => {
1367-
tcx.type_of(assoc_item.container_id(tcx)).instantiate_identity()
1368-
}
1379+
ty::AssocContainer::InherentImpl | ty::AssocContainer::TraitImpl(_) => tcx
1380+
.type_of(assoc_item.container_id(tcx))
1381+
.instantiate_identity()
1382+
.skip_normalization(),
13691383
ty::AssocContainer::Trait => tcx.types.self_param,
13701384
};
1371-
let self_param_ty =
1372-
tcx.fn_sig(assoc_item.def_id).instantiate_identity().input(0).skip_binder();
1385+
let self_param_ty = tcx
1386+
.fn_sig(assoc_item.def_id)
1387+
.instantiate_identity()
1388+
.skip_normalization()
1389+
.input(0)
1390+
.skip_binder();
13731391
if self_param_ty == self_ty {
13741392
item.decl.inputs[0].type_ = SelfTy;
13751393
} else if let ty::Ref(_, ty, _) = *self_param_ty.kind()
@@ -1423,7 +1441,10 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14231441

14241442
let mut predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates;
14251443
if let ty::AssocContainer::Trait = assoc_item.container {
1426-
let bounds = tcx.explicit_item_bounds(assoc_item.def_id).iter_identity_copied();
1444+
let bounds = tcx
1445+
.explicit_item_bounds(assoc_item.def_id)
1446+
.iter_identity_copied()
1447+
.map(Unnormalized::skip_normalization);
14271448
predicates = tcx.arena.alloc_from_iter(bounds.chain(predicates.iter().copied()));
14281449
}
14291450
let mut generics = clean_ty_generics_inner(
@@ -1509,7 +1530,9 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
15091530
Box::new(TypeAlias {
15101531
type_: clean_middle_ty(
15111532
ty::Binder::dummy(
1512-
tcx.type_of(assoc_item.def_id).instantiate_identity(),
1533+
tcx.type_of(assoc_item.def_id)
1534+
.instantiate_identity()
1535+
.skip_normalization(),
15131536
),
15141537
cx,
15151538
Some(assoc_item.def_id),
@@ -1529,7 +1552,9 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
15291552
Box::new(TypeAlias {
15301553
type_: clean_middle_ty(
15311554
ty::Binder::dummy(
1532-
tcx.type_of(assoc_item.def_id).instantiate_identity(),
1555+
tcx.type_of(assoc_item.def_id)
1556+
.instantiate_identity()
1557+
.skip_normalization(),
15331558
),
15341559
cx,
15351560
Some(assoc_item.def_id),
@@ -2267,7 +2292,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22672292
clean_middle_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
22682293
Type::Path { path }
22692294
} else {
2270-
let ty = cx.tcx.type_of(def_id).instantiate(cx.tcx, args);
2295+
let ty = cx.tcx.type_of(def_id).instantiate(cx.tcx, args).skip_normalization();
22712296
clean_middle_ty(bound_ty.rebind(ty), cx, None, None)
22722297
}
22732298
}
@@ -2330,6 +2355,7 @@ fn clean_middle_opaque_bounds<'tcx>(
23302355
.tcx
23312356
.explicit_item_bounds(impl_trait_def_id)
23322357
.iter_instantiated_copied(cx.tcx, args)
2358+
.map(Unnormalized::skip_normalization)
23332359
.collect();
23342360

23352361
let mut bounds = bounds
@@ -2427,7 +2453,9 @@ pub(crate) fn clean_middle_field(field: &ty::FieldDef, cx: &mut DocContext<'_>)
24272453
field.did,
24282454
field.name,
24292455
clean_middle_ty(
2430-
ty::Binder::dummy(cx.tcx.type_of(field.did).instantiate_identity()),
2456+
ty::Binder::dummy(
2457+
cx.tcx.type_of(field.did).instantiate_identity().skip_normalization(),
2458+
),
24312459
cx,
24322460
Some(field.did),
24332461
None,
@@ -2491,7 +2519,8 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
24912519
.fields
24922520
.iter()
24932521
.map(|field| {
2494-
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
2522+
let ty =
2523+
cx.tcx.type_of(field.did).instantiate(cx.tcx, args).skip_normalization();
24952524

24962525
// normalize the type to only show concrete types
24972526
// note: we do not use try_normalize_erasing_regions since we
@@ -2516,7 +2545,8 @@ pub(crate) fn clean_variant_def_with_args<'tcx>(
25162545
.fields
25172546
.iter()
25182547
.map(|field| {
2519-
let ty = cx.tcx.type_of(field.did).instantiate(cx.tcx, args);
2548+
let ty =
2549+
cx.tcx.type_of(field.did).instantiate(cx.tcx, args).skip_normalization();
25202550

25212551
// normalize the type to only show concrete types
25222552
// note: we do not use try_normalize_erasing_regions since we
@@ -2860,7 +2890,7 @@ fn clean_maybe_renamed_item<'tcx>(
28602890
}
28612891
}
28622892

2863-
let ty = cx.tcx.type_of(def_id).instantiate_identity();
2893+
let ty = cx.tcx.type_of(def_id).instantiate_identity().skip_normalization();
28642894

28652895
let mut ret = Vec::new();
28662896
let inner_type = clean_ty_alias_inner_type(ty, cx, &mut ret);
@@ -2992,7 +3022,7 @@ fn clean_impl<'tcx>(
29923022
let type_alias =
29933023
for_.def_id(&cx.cache).and_then(|alias_def_id: DefId| match tcx.def_kind(alias_def_id) {
29943024
DefKind::TyAlias => Some(clean_middle_ty(
2995-
ty::Binder::dummy(tcx.type_of(def_id).instantiate_identity()),
3025+
ty::Binder::dummy(tcx.type_of(def_id).instantiate_identity().skip_normalization()),
29963026
cx,
29973027
Some(def_id.to_def_id()),
29983028
None,

src/librustdoc/clean/simplify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxIndexMap;
1515
use rustc_data_structures::thin_vec::ThinVec;
1616
use rustc_data_structures::unord::UnordSet;
1717
use rustc_hir::def_id::DefId;
18-
use rustc_middle::ty::TyCtxt;
18+
use rustc_middle::ty::{TyCtxt, Unnormalized};
1919

2020
use crate::clean;
2121
use crate::clean::{GenericArgs as PP, WherePredicate as WP};
@@ -116,6 +116,7 @@ fn trait_is_same_or_supertrait(tcx: TyCtxt<'_>, child: DefId, trait_: DefId) ->
116116
let predicates = tcx.explicit_super_predicates_of(child);
117117
predicates
118118
.iter_identity_copied()
119+
.map(Unnormalized::skip_normalization)
119120
.filter_map(|(pred, _)| Some(pred.as_trait_clause()?.def_id()))
120121
.any(|did| trait_is_same_or_supertrait(tcx, did, trait_))
121122
}

src/librustdoc/clean/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
126126

127127
// Elide arguments that coincide with their default.
128128
if !elision_has_failed_once_before && let Some(default) = param.default_value(cx.tcx) {
129-
let default = default.instantiate(cx.tcx, args.as_ref());
129+
let default = default.instantiate(cx.tcx, args.as_ref()).skip_normalization();
130130
if can_elide_generic_arg(arg, arg.rebind(default)) {
131131
return None;
132132
}
@@ -371,7 +371,7 @@ pub(crate) fn print_evaluated_const(
371371
with_type: bool,
372372
) -> Option<String> {
373373
tcx.const_eval_poly(def_id).ok().and_then(|val| {
374-
let ty = tcx.type_of(def_id).instantiate_identity();
374+
let ty = tcx.type_of(def_id).instantiate_identity().skip_normalization();
375375
match (val, ty.kind()) {
376376
(_, &ty::Ref(..)) => None,
377377
(mir::ConstValue::Scalar(_), &ty::Adt(_, _)) => None,

src/librustdoc/formats/cache.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,12 @@ impl DocFolder for CacheBuilder<'_, '_> {
424424
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {
425425
dids.insert(path.def_id());
426426
if let Some(generics) = path.generics()
427-
&& let ty::Adt(adt, _) =
428-
self.tcx.type_of(path.def_id()).instantiate_identity().kind()
427+
&& let ty::Adt(adt, _) = self
428+
.tcx
429+
.type_of(path.def_id())
430+
.instantiate_identity()
431+
.skip_normalization()
432+
.kind()
429433
&& adt.is_fundamental()
430434
{
431435
for ty in generics {

src/librustdoc/html/format.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ fn generate_item_def_id_path(
441441
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
442442
def_id = infcx
443443
.at(&ObligationCause::dummy(), tcx.param_env(def_id))
444-
.query_normalize(ty::Binder::dummy(tcx.type_of(def_id).instantiate_identity()))
444+
.query_normalize(ty::Binder::dummy(
445+
tcx.type_of(def_id).instantiate_identity().skip_normalization(),
446+
))
445447
.map(|resolved| infcx.resolve_vars_if_possible(resolved.value))
446448
.ok()
447449
.and_then(|normalized| normalized.skip_binder().ty_adt_def())

src/librustdoc/html/render/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,8 +2994,9 @@ fn repr_attribute<'tcx>(
29942994

29952995
// Side note: There can only ever be one or zero non-1-ZST fields.
29962996
let non_1zst_field = var.fields.iter().find(|field| {
2997-
let ty = ty::TypingEnv::post_analysis(tcx, field.did)
2998-
.as_query_input(tcx.type_of(field.did).instantiate_identity());
2997+
let ty = ty::TypingEnv::post_analysis(tcx, field.did).as_query_input(
2998+
tcx.type_of(field.did).instantiate_identity().skip_normalization(),
2999+
);
29993000
tcx.layout_of(ty).is_ok_and(|layout| !layout.is_1zst())
30003001
});
30013002

0 commit comments

Comments
 (0)