From a192e5d9c2e90798ffcd0bc79527cdc4ad52d949 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 2 Oct 2020 16:21:43 -0400 Subject: Normalize `::T` for rustdoc - Only run for `QPath::Resolved` with `Some` self parameter (`::T`) - Fall back to the previous behavior if the path can't be resolved - Show what the behavior is if the type can't be normalized - Run `resolve_vars_if_possible` It's not clear whether or not this is necessary. See https://github.com/rust-lang/rust/pull/77616 for more context. - Add a test for cross-crate re-exports - Use the same code for both `hir::Ty` and `Ty` --- src/test/rustdoc/auxiliary/normalize-assoc-item.rs | 12 +++++ src/test/rustdoc/normalize-assoc-item.rs | 63 ++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/test/rustdoc/auxiliary/normalize-assoc-item.rs create mode 100644 src/test/rustdoc/normalize-assoc-item.rs (limited to 'src/test/rustdoc') diff --git a/src/test/rustdoc/auxiliary/normalize-assoc-item.rs b/src/test/rustdoc/auxiliary/normalize-assoc-item.rs new file mode 100644 index 00000000000..fbd111c3035 --- /dev/null +++ b/src/test/rustdoc/auxiliary/normalize-assoc-item.rs @@ -0,0 +1,12 @@ +#![crate_name = "inner"] +pub trait MyTrait { + type Y; +} + +impl MyTrait for u32 { + type Y = i32; +} + +pub fn foo() -> ::Y { + 0 +} diff --git a/src/test/rustdoc/normalize-assoc-item.rs b/src/test/rustdoc/normalize-assoc-item.rs new file mode 100644 index 00000000000..829f446b7cc --- /dev/null +++ b/src/test/rustdoc/normalize-assoc-item.rs @@ -0,0 +1,63 @@ +// ignore-tidy-linelength +// aux-build:normalize-assoc-item.rs +// build-aux-docs + +pub trait Trait { + type X; +} + +impl Trait for usize { + type X = isize; +} + +// @has 'normalize_assoc_item/fn.f.html' '//pre[@class="rust fn"]' 'pub fn f() -> isize' +pub fn f() -> ::X { + 0 +} + +pub struct S { + // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.box_me_up"]' 'box_me_up: Box' + pub box_me_up: ::X, + // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.generic"]' 'generic: (usize, isize)' + pub generic: as Trait>::X, +} + +impl Trait for S { + type X = Box; +} + +pub struct Generic(Inner); + +impl Trait for Generic { + type X = (Inner, Inner::X); +} + +// These can't be normalized because they depend on a generic parameter. +// However the user can choose whether the text should be displayed as `Inner::X` or `::X`. + +// @has 'normalize_assoc_item/struct.Unknown.html' '//pre[@class="rust struct"]' 'pub struct Unknown(pub ::X);' +pub struct Unknown(pub ::X); + +// @has 'normalize_assoc_item/struct.Unknown2.html' '//pre[@class="rust struct"]' 'pub struct Unknown2(pub Inner::X);' +pub struct Unknown2(pub Inner::X); + +trait Lifetimes<'a> { + type Y; +} + +impl<'a> Lifetimes<'a> for usize { + type Y = &'a isize; +} + +// @has 'normalize_assoc_item/fn.g.html' '//pre[@class="rust fn"]' "pub fn g() -> &isize" +pub fn g() -> >::Y { + &0 +} + +// @has 'normalize_assoc_item/constant.A.html' '//pre[@class="rust const"]' "pub const A: &isize" +pub const A: >::Y = &0; + +// test cross-crate re-exports +extern crate inner; +// @has 'normalize_assoc_item/fn.foo.html' '//pre[@class="rust fn"]' "pub fn foo() -> i32" +pub use inner::foo; -- cgit 1.4.1-3-g733a5