Skip to content

Commit

Permalink
Avoid trying to normalize unnormalizable types
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Dec 12, 2022
1 parent 21917b0 commit 3075451
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,10 @@ where
/// different binding level.
#[track_caller]
pub fn dummy(value: T) -> Binder<'tcx, T> {
assert!(!value.has_escaping_bound_vars());
assert!(
!value.has_escaping_bound_vars(),
"`{value:?}` has escaping bound vars, so it cannot be wrapped in a dummy binder."
);
Binder(value, ty::List::empty())
}

Expand Down
8 changes: 6 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
use rustc_middle::middle::resolve_lifetime as rl;
use rustc_middle::ty::fold::TypeFolder;
use rustc_middle::ty::InternalSubsts;
use rustc_middle::ty::TypeVisitable;
use rustc_middle::ty::{self, AdtKind, DefIdTree, EarlyBinder, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_span::hygiene::{AstPass, MacroKind};
Expand Down Expand Up @@ -1459,8 +1460,11 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
hir::QPath::Resolved(Some(qself), p) => {
// Try to normalize `<X as Y>::T` to a type
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
if let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty)) {
return clean_middle_ty(normalized_value, cx, None);
// `hir_to_ty` can return projection types with escaping vars for GATs, e.g. `<() as Trait>::Gat<'_>`
if !ty.has_escaping_bound_vars() {
if let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty)) {
return clean_middle_ty(normalized_value, cx, None);
}
}

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

0 comments on commit 3075451

Please sign in to comment.