Skip to content

Commit 3075451

Browse files
committed
Avoid trying to normalize unnormalizable types
1 parent 21917b0 commit 3075451

File tree

2 files changed

+10
-3
lines changed
  • compiler/rustc_middle/src/ty
  • src/librustdoc/clean

2 files changed

+10
-3
lines changed

compiler/rustc_middle/src/ty/sty.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,10 @@ where
982982
/// different binding level.
983983
#[track_caller]
984984
pub fn dummy(value: T) -> Binder<'tcx, T> {
985-
assert!(!value.has_escaping_bound_vars());
985+
assert!(
986+
!value.has_escaping_bound_vars(),
987+
"`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
988+
);
986989
Binder(value, ty::List::empty())
987990
}
988991

src/librustdoc/clean/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
2222
use rustc_middle::middle::resolve_lifetime as rl;
2323
use rustc_middle::ty::fold::TypeFolder;
2424
use rustc_middle::ty::InternalSubsts;
25+
use rustc_middle::ty::TypeVisitable;
2526
use rustc_middle::ty::{self, AdtKind, DefIdTree, EarlyBinder, Ty, TyCtxt};
2627
use rustc_middle::{bug, span_bug};
2728
use rustc_span::hygiene::{AstPass, MacroKind};
@@ -1459,8 +1460,11 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
14591460
hir::QPath::Resolved(Some(qself), p) => {
14601461
// Try to normalize `<X as Y>::T` to a type
14611462
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
1462-
if let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty)) {
1463-
return clean_middle_ty(normalized_value, cx, None);
1463+
// `hir_to_ty` can return projection types with escaping vars for GATs, e.g. `<() as Trait>::Gat<'_>`
1464+
if !ty.has_escaping_bound_vars() {
1465+
if let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty)) {
1466+
return clean_middle_ty(normalized_value, cx, None);
1467+
}
14641468
}
14651469

14661470
let trait_segments = &p.segments[..p.segments.len() - 1];

0 commit comments

Comments
 (0)