about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-11-26 16:31:12 +0000
committerbors <bors@rust-lang.org>2020-11-26 16:31:12 +0000
commit65ecc481fac7ceced57d973a580d0a7ccbdcb192 (patch)
treeaacd240feea9dd3a35c7c5cc3dfee2bceab76dbe /src/test
parent0beba9333754ead8febc5101fc5c35f7dcdfaadf (diff)
parent277bdbc0ed0f1f87e8d340233d7f485fbbe8cc66 (diff)
downloadrust-65ecc481fac7ceced57d973a580d0a7ccbdcb192.tar.gz
rust-65ecc481fac7ceced57d973a580d0a7ccbdcb192.zip
Auto merge of #77467 - jyn514:query-docs, r=oli-obk
Normalize `<X as Y>::T` for rustdoc

- Only run for `QPath::Resolved` with `Some` self parameter (`<X as Y>::T`)
- Fall back to the previous behavior if the path can't be resolved

The first commit is a pure refactor and should probably be reviewed by `@GuillaumeGomez.` I recommend reviewing the second commit on its own.

Fixes https://github.com/rust-lang/rust/issues/77459.

r? `@eddyb`
cc `@danielhenrymantilla` , `@lcnr`
Diffstat (limited to 'src/test')
-rw-r--r--src/test/rustdoc/auxiliary/normalize-assoc-item.rs12
-rw-r--r--src/test/rustdoc/normalize-assoc-item.rs68
2 files changed, 80 insertions, 0 deletions
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() -> <u32 as MyTrait>::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..137fd354a87
--- /dev/null
+++ b/src/test/rustdoc/normalize-assoc-item.rs
@@ -0,0 +1,68 @@
+// 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() -> <usize as Trait>::X {
+    0
+}
+
+pub struct S {
+    // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.box_me_up"]' 'box_me_up: Box<S, Global>'
+    pub box_me_up: <S as Trait>::X,
+    // @has 'normalize_assoc_item/struct.S.html' '//span[@id="structfield.generic"]' 'generic: (usize, isize)'
+    pub generic: <Generic<usize> as Trait>::X,
+}
+
+impl Trait for S {
+    type X = Box<S>;
+}
+
+pub struct Generic<Inner>(Inner);
+
+impl<Inner: Trait> Trait for Generic<Inner> {
+    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 `<Inner as Trait>::X`.
+
+// @has 'normalize_assoc_item/struct.Unknown.html' '//pre[@class="rust struct"]' 'pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);'
+pub struct Unknown<Inner: Trait>(pub <Inner as Trait>::X);
+
+// @has 'normalize_assoc_item/struct.Unknown2.html' '//pre[@class="rust struct"]' 'pub struct Unknown2<Inner: Trait>(pub Inner::X);'
+pub struct Unknown2<Inner: Trait>(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() -> <usize as Lifetimes<'static>>::Y {
+    &0
+}
+
+// @has 'normalize_assoc_item/constant.A.html' '//pre[@class="rust const"]' "pub const A: &isize"
+pub const A: <usize as Lifetimes<'static>>::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;
+
+// @has 'normalize_assoc_item/fn.h.html' '//pre[@class="rust fn"]' "pub fn h<T>() -> IntoIter<T, Global>"
+pub fn h<T>() -> <Vec<T> as IntoIterator>::IntoIter {
+    vec![].into_iter()
+}