-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.