Skip to content

Commit 2964f15

Browse files
Don't use QueryNormalizer to normalize in rustdoc
1 parent f382c27 commit 2964f15

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

src/librustdoc/clean/mod.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +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::{self, AdtKind, DefIdTree, EarlyBinder, Lift, Ty, TyCtxt};
25+
use rustc_middle::ty::{self, AdtKind, DefIdTree, EarlyBinder, Lift, Ty, TyCtxt, TypeFoldable};
2626
use rustc_middle::{bug, span_bug};
2727
use rustc_span::hygiene::{AstPass, MacroKind};
2828
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -983,6 +983,8 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
983983
) -> FnDecl {
984984
let mut names = did.map_or(&[] as &[_], |did| cx.tcx.fn_arg_names(did)).iter();
985985

986+
let sig = normalize(cx, sig).unwrap_or(sig);
987+
986988
// We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
987989
// but shouldn't change any code meaning.
988990
let output = match clean_middle_ty(sig.skip_binder().output(), cx, None) {
@@ -1552,33 +1554,22 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
15521554
}
15531555

15541556
/// Returns `None` if the type could not be normalized
1555-
fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'_>) -> Option<Ty<'tcx>> {
1557+
fn normalize<'tcx, T: TypeFoldable<'tcx>>(cx: &mut DocContext<'tcx>, value: T) -> Option<T> {
15561558
// HACK: low-churn fix for #79459 while we wait for a trait normalization fix
15571559
if !cx.tcx.sess.opts.unstable_opts.normalize_docs {
15581560
return None;
15591561
}
15601562

1561-
use crate::rustc_trait_selection::infer::TyCtxtInferExt;
1562-
use crate::rustc_trait_selection::traits::query::normalize::AtExt;
1563-
use rustc_middle::traits::ObligationCause;
1563+
if value.has_escaping_bound_vars() {
1564+
return None;
1565+
}
1566+
1567+
use rustc_trait_selection::infer::TyCtxtInferExt;
1568+
use rustc_trait_selection::traits;
15641569

15651570
// Try to normalize `<X as Y>::T` to a type
1566-
let lifted = ty.lift_to_tcx(cx.tcx).unwrap();
15671571
let infcx = cx.tcx.infer_ctxt().build();
1568-
let normalized = infcx
1569-
.at(&ObligationCause::dummy(), cx.param_env)
1570-
.normalize(lifted)
1571-
.map(|resolved| infcx.resolve_vars_if_possible(resolved.value));
1572-
match normalized {
1573-
Ok(normalized_value) => {
1574-
debug!("normalized {:?} to {:?}", ty, normalized_value);
1575-
Some(normalized_value)
1576-
}
1577-
Err(err) => {
1578-
debug!("failed to normalize {:?}: {:?}", ty, err);
1579-
None
1580-
}
1581-
}
1572+
traits::fully_normalize(&infcx, traits::ObligationCause::dummy(), cx.param_env, value).ok()
15821573
}
15831574

15841575
pub(crate) fn clean_middle_ty<'tcx>(

src/test/rustdoc/issue-102835.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// compile-flags: -Znormalize-docs
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
trait Allocator {
6+
type Buffer;
7+
}
8+
9+
struct DefaultAllocator;
10+
11+
impl<T> Allocator for DefaultAllocator {
12+
type Buffer = ();
13+
}
14+
15+
type A = impl Fn(<DefaultAllocator as Allocator>::Buffer);
16+
17+
fn foo() -> A {
18+
|_| ()
19+
}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)