summaryrefslogtreecommitdiff
path: root/tests/rustdoc-ui
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2023-04-20 18:08:06 -0700
committerMichael Howell <michael@notriddle.com>2023-04-29 16:53:02 -0700
commitb1d08275a9914b59bbad3cf5f80073b8365e9e67 (patch)
tree7faaffc6f6692b47ab7d49d3d655cb34f34750b3 /tests/rustdoc-ui
parent87b1f891ea76713462cfc5a15137a8fe2b24ecc2 (diff)
downloadrust-b1d08275a9914b59bbad3cf5f80073b8365e9e67.tar.gz
rustdoc: catch and don't blow up on impl Trait cycles
An odd feature of Rust is that `Foo` is invalid, but `Bar` is okay: type Foo<'a, 'b> = Box<dyn PartialEq<Foo<'a, 'b>>>; type Bar<'a, 'b> = impl PartialEq<Bar<'a, 'b>>; To get it right, track every time rustdoc descends into a type alias, so if it shows up twice, it can be write the path instead of infinitely expanding it.
Diffstat (limited to 'tests/rustdoc-ui')
-rw-r--r--tests/rustdoc-ui/issue-110629-private-type-cycle-dyn.rs12
-rw-r--r--tests/rustdoc-ui/issue-110629-private-type-cycle-dyn.stderr25
-rw-r--r--tests/rustdoc-ui/issue-110629-private-type-cycle.rs15
3 files changed, 52 insertions, 0 deletions
diff --git a/tests/rustdoc-ui/issue-110629-private-type-cycle-dyn.rs b/tests/rustdoc-ui/issue-110629-private-type-cycle-dyn.rs
new file mode 100644
index 00000000000..c920a815fda
--- /dev/null
+++ b/tests/rustdoc-ui/issue-110629-private-type-cycle-dyn.rs
@@ -0,0 +1,12 @@
+type Bar<'a, 'b> = Box<dyn PartialEq<Bar<'a, 'b>>>;
+//~^ ERROR cycle detected when expanding type alias
+
+fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
+ Box::new(i)
+}
+
+fn main() {
+ let meh = 42;
+ let muh = 42;
+ assert!(bar(&meh) == bar(&muh));
+}
diff --git a/tests/rustdoc-ui/issue-110629-private-type-cycle-dyn.stderr b/tests/rustdoc-ui/issue-110629-private-type-cycle-dyn.stderr
new file mode 100644
index 00000000000..79e1b753112
--- /dev/null
+++ b/tests/rustdoc-ui/issue-110629-private-type-cycle-dyn.stderr
@@ -0,0 +1,25 @@
+error[E0391]: cycle detected when expanding type alias `Bar`
+ --> $DIR/issue-110629-private-type-cycle-dyn.rs:1:38
+ |
+LL | type Bar<'a, 'b> = Box<dyn PartialEq<Bar<'a, 'b>>>;
+ | ^^^^^^^^^^^
+ |
+ = note: ...which immediately requires expanding type alias `Bar` again
+ = note: type aliases cannot be recursive
+ = help: consider using a struct, enum, or union instead to break the cycle
+ = help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
+note: cycle used when collecting item types in top-level module
+ --> $DIR/issue-110629-private-type-cycle-dyn.rs:1:1
+ |
+LL | / type Bar<'a, 'b> = Box<dyn PartialEq<Bar<'a, 'b>>>;
+LL | |
+LL | |
+LL | | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
+... |
+LL | | assert!(bar(&meh) == bar(&muh));
+LL | | }
+ | |_^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/tests/rustdoc-ui/issue-110629-private-type-cycle.rs b/tests/rustdoc-ui/issue-110629-private-type-cycle.rs
new file mode 100644
index 00000000000..2d46ddbfa6e
--- /dev/null
+++ b/tests/rustdoc-ui/issue-110629-private-type-cycle.rs
@@ -0,0 +1,15 @@
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+
+type Bar<'a, 'b> = impl PartialEq<Bar<'a, 'b>> + std::fmt::Debug;
+
+fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> {
+ i
+}
+
+fn main() {
+ let meh = 42;
+ let muh = 42;
+ assert_eq!(bar(&meh), bar(&muh));
+}