From 3e01b0a8fd9325928a1df10ee1c5210dacc5a859 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 1 Feb 2022 12:29:22 +0100 Subject: [PATCH 1/2] Fix lifetime elision in type aliases --- src/librustdoc/clean/mod.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 33612c8065477..6a654eebaa2c0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1426,15 +1426,25 @@ fn normalize<'tcx>(cx: &mut DocContext<'tcx>, ty: Ty<'_>) -> Option> { return None; } + use crate::rustc_trait_selection::infer::TyCtxtInferExt; + use crate::rustc_trait_selection::traits::query::normalize::AtExt; + use rustc_middle::traits::ObligationCause; + // Try to normalize `::T` to a type let lifted = ty.lift_to_tcx(cx.tcx).unwrap(); - match cx.tcx.try_normalize_erasing_regions(cx.param_env, lifted) { + let normalized = cx.tcx.infer_ctxt().enter(|infcx| { + infcx + .at(&ObligationCause::dummy(), cx.param_env) + .normalize(lifted) + .map(|resolved| infcx.resolve_vars_if_possible(resolved.value)) + }); + match normalized { Ok(normalized_value) => { - trace!("normalized {:?} to {:?}", ty, normalized_value); + debug!("normalized {:?} to {:?}", ty, normalized_value); Some(normalized_value) } Err(err) => { - info!("failed to normalize {:?}: {:?}", ty, err); + debug!("failed to normalize {:?}: {:?}", ty, err); None } } From 230846433df2acde778b31fb1b3d3e194c29a0af Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 1 Feb 2022 12:29:46 +0100 Subject: [PATCH 2/2] Add test to ensure lifetime is not elided in type alias --- src/test/rustdoc/lifetime-name.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/test/rustdoc/lifetime-name.rs diff --git a/src/test/rustdoc/lifetime-name.rs b/src/test/rustdoc/lifetime-name.rs new file mode 100644 index 0000000000000..5d30a745a61a6 --- /dev/null +++ b/src/test/rustdoc/lifetime-name.rs @@ -0,0 +1,5 @@ +#![crate_name = "foo"] + +// @has 'foo/type.Resolutions.html' +// @has - '//*[@class="rust typedef"]' "pub type Resolutions<'tcx> = &'tcx u8;" +pub type Resolutions<'tcx> = &'tcx u8;