Closed
Description
Given the following code: playground link
struct X {
x: Option<X>,
}
The current output is:
error[E0072]: recursive type `X` has infinite size
--> src/lib.rs:1:1
|
1 | struct X {
| ^^^^^^^^ recursive type has infinite size
2 | x: Option<X>,
| --------- recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `X` representable
|
2 | x: Box<Option<X>>,
| ++++ +
For more information about this error, try `rustc --explain E0072`.
error: could not compile `playground` due to previous error
Ideally the output should look like:
error[E0072]: recursive type `X` has infinite size
--> src/lib.rs:1:1
|
1 | struct X {
| ^^^^^^^^ recursive type has infinite size
2 | x: Option<X>,
| --------- recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `X` representable
|
2 | x: Option<Box<X>>,
| ++++ +
For more information about this error, try `rustc --explain E0072`.
error: could not compile `playground` due to previous error
This allows rustc to use the nullpointer niche optimization, and is also easier to handle, and what the user probably wants in general.