diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-03-31 17:29:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-31 17:29:52 +0200 |
| commit | 521c590c9f780227f3f6284cbecb727f121a9cb4 (patch) | |
| tree | 473ac3060d7cfec82f7b8ca505e6962afb651630 /src/test | |
| parent | 03314912f1361af6b39383958b5aa1b4aed61c26 (diff) | |
| parent | c74f7a310fe8fcf9a2edf927cee0bc15a3abe399 (diff) | |
| download | rust-521c590c9f780227f3f6284cbecb727f121a9cb4.tar.gz rust-521c590c9f780227f3f6284cbecb727f121a9cb4.zip | |
Rollup merge of #91416 - compiler-errors:infinite-ty-option-box, r=estebank
Specialize infinite-type "insert some indirection" suggestion for Option Suggest `Option<Box<_>>` instead of `Box<Option<_>>` for infinitely-recursive members of a struct. Not sure if I can get the span of the generic subty of the Option so I can make this a `+++`-style suggestion. The current output is a tiny bit less fancy looking than the original suggestion. Should I limit the specialization to just `Option<Box<TheOuterStruct>>`? Because right now it applies to all `Option` members in the struct that are returned by `Representability::SelfRecursive`. Fixes #91402 r? `@estebank` (since you wrote the original suggestion and are definitely most familiar with it!)
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/issues/issue-17431-1.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-17431-2.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-17431-4.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-17431-7.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-3779.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/sized-cycle-note.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/span/E0072.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/span/multiline-span-E0072.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr | 8 | ||||
| -rw-r--r-- | src/test/ui/type/type-recursive-box-shadowed.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/type/type-recursive-box-shadowed.stderr | 17 | ||||
| -rw-r--r-- | src/test/ui/type/type-recursive.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/type/type-recursive.stderr | 85 |
13 files changed, 160 insertions, 28 deletions
diff --git a/src/test/ui/issues/issue-17431-1.stderr b/src/test/ui/issues/issue-17431-1.stderr index 4d739a3823b..db32eb952ba 100644 --- a/src/test/ui/issues/issue-17431-1.stderr +++ b/src/test/ui/issues/issue-17431-1.stderr @@ -8,8 +8,8 @@ LL | struct Foo { foo: Option<Option<Foo>> } | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable | -LL | struct Foo { foo: Box<Option<Option<Foo>>> } - | ++++ + +LL | struct Foo { foo: Option<Box<Option<Foo>>> } + | ++++ + error: aborting due to previous error diff --git a/src/test/ui/issues/issue-17431-2.stderr b/src/test/ui/issues/issue-17431-2.stderr index e53134c5238..d23fd1474ac 100644 --- a/src/test/ui/issues/issue-17431-2.stderr +++ b/src/test/ui/issues/issue-17431-2.stderr @@ -8,8 +8,8 @@ LL | struct Baz { q: Option<Foo> } | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Baz` representable | -LL | struct Baz { q: Box<Option<Foo>> } - | ++++ + +LL | struct Baz { q: Option<Box<Foo>> } + | ++++ + error[E0072]: recursive type `Foo` has infinite size --> $DIR/issue-17431-2.rs:4:1 @@ -21,8 +21,8 @@ LL | struct Foo { q: Option<Baz> } | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable | -LL | struct Foo { q: Box<Option<Baz>> } - | ++++ + +LL | struct Foo { q: Option<Box<Baz>> } + | ++++ + error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-17431-4.stderr b/src/test/ui/issues/issue-17431-4.stderr index f5aeeec7337..ddf669b8fd1 100644 --- a/src/test/ui/issues/issue-17431-4.stderr +++ b/src/test/ui/issues/issue-17431-4.stderr @@ -8,8 +8,8 @@ LL | struct Foo<T> { foo: Option<Option<Foo<T>>>, marker: marker::PhantomData<T> | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable | -LL | struct Foo<T> { foo: Box<Option<Option<Foo<T>>>>, marker: marker::PhantomData<T> } - | ++++ + +LL | struct Foo<T> { foo: Option<Box<Option<Foo<T>>>>, marker: marker::PhantomData<T> } + | ++++ + error: aborting due to previous error diff --git a/src/test/ui/issues/issue-17431-7.stderr b/src/test/ui/issues/issue-17431-7.stderr index aeaadaa6917..6f8a7e3867b 100644 --- a/src/test/ui/issues/issue-17431-7.stderr +++ b/src/test/ui/issues/issue-17431-7.stderr @@ -8,8 +8,8 @@ LL | enum Foo { Voo(Option<Option<Foo>>) } | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable | -LL | enum Foo { Voo(Box<Option<Option<Foo>>>) } - | ++++ + +LL | enum Foo { Voo(Option<Box<Option<Foo>>>) } + | ++++ + error: aborting due to previous error diff --git a/src/test/ui/issues/issue-3779.stderr b/src/test/ui/issues/issue-3779.stderr index 6a21472848a..e853d0f8c89 100644 --- a/src/test/ui/issues/issue-3779.stderr +++ b/src/test/ui/issues/issue-3779.stderr @@ -9,8 +9,8 @@ LL | element: Option<S> | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `S` representable | -LL | element: Box<Option<S>> - | ++++ + +LL | element: Option<Box<S>> + | ++++ + error: aborting due to previous error diff --git a/src/test/ui/sized-cycle-note.stderr b/src/test/ui/sized-cycle-note.stderr index 0726b16a919..536510814c5 100644 --- a/src/test/ui/sized-cycle-note.stderr +++ b/src/test/ui/sized-cycle-note.stderr @@ -8,8 +8,8 @@ LL | struct Baz { q: Option<Foo> } | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Baz` representable | -LL | struct Baz { q: Box<Option<Foo>> } - | ++++ + +LL | struct Baz { q: Option<Box<Foo>> } + | ++++ + error[E0072]: recursive type `Foo` has infinite size --> $DIR/sized-cycle-note.rs:11:1 @@ -21,8 +21,8 @@ LL | struct Foo { q: Option<Baz> } | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable | -LL | struct Foo { q: Box<Option<Baz>> } - | ++++ + +LL | struct Foo { q: Option<Box<Baz>> } + | ++++ + error: aborting due to 2 previous errors diff --git a/src/test/ui/span/E0072.stderr b/src/test/ui/span/E0072.stderr index 98e92751360..882ed577cf3 100644 --- a/src/test/ui/span/E0072.stderr +++ b/src/test/ui/span/E0072.stderr @@ -9,8 +9,8 @@ LL | tail: Option<ListNode>, | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ListNode` representable | -LL | tail: Box<Option<ListNode>>, - | ++++ + +LL | tail: Option<Box<ListNode>>, + | ++++ + error: aborting due to previous error diff --git a/src/test/ui/span/multiline-span-E0072.stderr b/src/test/ui/span/multiline-span-E0072.stderr index cb71a55b09e..acfc60b51f3 100644 --- a/src/test/ui/span/multiline-span-E0072.stderr +++ b/src/test/ui/span/multiline-span-E0072.stderr @@ -12,8 +12,8 @@ LL | | } | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `ListNode` representable | -LL | tail: Box<Option<ListNode>>, - | ++++ + +LL | tail: Option<Box<ListNode>>, + | ++++ + error: aborting due to previous error diff --git a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr index c6d2434e424..80a494f3f65 100644 --- a/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr +++ b/src/test/ui/structs-enums/struct-rec/mutual-struct-recursion.stderr @@ -37,8 +37,8 @@ LL | y: Option<Option<D<T>>>, | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `C` representable | -LL | y: Box<Option<Option<D<T>>>>, - | ++++ + +LL | y: Option<Box<Option<D<T>>>>, + | ++++ + error[E0072]: recursive type `D` has infinite size --> $DIR/mutual-struct-recursion.rs:18:1 @@ -51,8 +51,8 @@ LL | z: Option<Option<C<T>>>, | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `D` representable | -LL | z: Box<Option<Option<C<T>>>>, - | ++++ + +LL | z: Option<Box<Option<C<T>>>>, + | ++++ + error: aborting due to 4 previous errors diff --git a/src/test/ui/type/type-recursive-box-shadowed.rs b/src/test/ui/type/type-recursive-box-shadowed.rs new file mode 100644 index 00000000000..e141c2149ff --- /dev/null +++ b/src/test/ui/type/type-recursive-box-shadowed.rs @@ -0,0 +1,12 @@ +//FIXME(compiler-errors): This fixup should suggest the full box path, not just `Box` + +struct Box<T> { + t: T, +} + +struct Foo { + //~^ ERROR recursive type `Foo` has infinite size + inner: Foo, +} + +fn main() {} diff --git a/src/test/ui/type/type-recursive-box-shadowed.stderr b/src/test/ui/type/type-recursive-box-shadowed.stderr new file mode 100644 index 00000000000..c22d848f379 --- /dev/null +++ b/src/test/ui/type/type-recursive-box-shadowed.stderr @@ -0,0 +1,17 @@ +error[E0072]: recursive type `Foo` has infinite size + --> $DIR/type-recursive-box-shadowed.rs:7:1 + | +LL | struct Foo { + | ^^^^^^^^^^ recursive type has infinite size +LL | +LL | inner: Foo, + | --- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Foo` representable + | +LL | inner: Box<Foo>, + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`. diff --git a/src/test/ui/type/type-recursive.rs b/src/test/ui/type/type-recursive.rs index 8558f761ee8..e8084f0d082 100644 --- a/src/test/ui/type/type-recursive.rs +++ b/src/test/ui/type/type-recursive.rs @@ -1,6 +1,30 @@ struct T1 { //~ ERROR E0072 foo: isize, - foolish: T1 + foolish: T1, +} + +struct T2 { //~ ERROR E0072 + inner: Option<T2>, +} + +type OptionT3 = Option<T3>; + +struct T3 { //~ ERROR E0072 + inner: OptionT3, +} + +struct T4(Option<T4>); //~ ERROR E0072 + +enum T5 { //~ ERROR E0072 + Variant(Option<T5>), +} + +enum T6 { //~ ERROR E0072 + Variant{ field: Option<T6> }, +} + +struct T7 { //~ ERROR E0072 + foo: std::cell::Cell<Option<T7>>, } fn main() { } diff --git a/src/test/ui/type/type-recursive.stderr b/src/test/ui/type/type-recursive.stderr index 5a94a0fd683..04392f7390d 100644 --- a/src/test/ui/type/type-recursive.stderr +++ b/src/test/ui/type/type-recursive.stderr @@ -4,14 +4,93 @@ error[E0072]: recursive type `T1` has infinite size LL | struct T1 { | ^^^^^^^^^ recursive type has infinite size LL | foo: isize, -LL | foolish: T1 +LL | foolish: T1, | -- recursive without indirection | help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T1` representable | -LL | foolish: Box<T1> +LL | foolish: Box<T1>, | ++++ + -error: aborting due to previous error +error[E0072]: recursive type `T2` has infinite size + --> $DIR/type-recursive.rs:6:1 + | +LL | struct T2 { + | ^^^^^^^^^ recursive type has infinite size +LL | inner: Option<T2>, + | ---------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T2` representable + | +LL | inner: Option<Box<T2>>, + | ++++ + + +error[E0072]: recursive type `T3` has infinite size + --> $DIR/type-recursive.rs:12:1 + | +LL | struct T3 { + | ^^^^^^^^^ recursive type has infinite size +LL | inner: OptionT3, + | -------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T3` representable + | +LL | inner: Box<OptionT3>, + | ++++ + + +error[E0072]: recursive type `T4` has infinite size + --> $DIR/type-recursive.rs:16:1 + | +LL | struct T4(Option<T4>); + | ^^^^^^^^^^----------^^ + | | | + | | recursive without indirection + | recursive type has infinite size + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T4` representable + | +LL | struct T4(Option<Box<T4>>); + | ++++ + + +error[E0072]: recursive type `T5` has infinite size + --> $DIR/type-recursive.rs:18:1 + | +LL | enum T5 { + | ^^^^^^^ recursive type has infinite size +LL | Variant(Option<T5>), + | ---------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T5` representable + | +LL | Variant(Option<Box<T5>>), + | ++++ + + +error[E0072]: recursive type `T6` has infinite size + --> $DIR/type-recursive.rs:22:1 + | +LL | enum T6 { + | ^^^^^^^ recursive type has infinite size +LL | Variant{ field: Option<T6> }, + | ---------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T6` representable + | +LL | Variant{ field: Option<Box<T6>> }, + | ++++ + + +error[E0072]: recursive type `T7` has infinite size + --> $DIR/type-recursive.rs:26:1 + | +LL | struct T7 { + | ^^^^^^^^^ recursive type has infinite size +LL | foo: std::cell::Cell<Option<T7>>, + | --------------------------- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `T7` representable + | +LL | foo: Box<std::cell::Cell<Option<T7>>>, + | ++++ + + +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0072`. |
