-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Add long diagnostics for E0152, E0158, E0161, E0170, E0306, E0307 #24455
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
In Rust, you can only move a value when its size is known at compile time. | ||
|
||
To work around this restriction, you can "hide" the value behind a pointer: | ||
either a reference (`&x`) or owned box (`box x`). Since a pointer has a fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The box
syntax is still experimental, so this should suggest using Box::new(x)
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't call Box::new()
with an unsized value.
For example, the following doesn't compile:
enum A {
B(char),
C([i32])
}
fn main() {
Box::new(A::B('a'));
}
I chose not to add a note about feature gates, because:
- It's quite a rare error -- most code shouldn't construct unsized values directly, and when they do, they tend to trigger E0277 ("trait Sized is not implemented") not this one
- I don't want to add more churn when the syntax is stabilizing soon anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, whoops, I didn’t even look at what the error was. But the box
syntax doesn’t work on unsized values either:
#![feature(box_syntax)]
enum A {
B(char),
C([i32])
}
fn main() {
box A::B('a');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's also probably fine to only mention references here, it's pretty rare to see Box<str>
or Box<[T]>
in the wild.
I've pushed a revised version -- thanks for the feedback! @alexcrichton re-r? |
This was merged in #24512 , sorry, I rebased and forgot that'd screw it up :( |
cc #24407