Skip to content

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

Closed
wants to merge 5 commits into from
Closed

Add long diagnostics for E0152, E0158, E0161, E0170, E0306, E0307 #24455

wants to merge 5 commits into from

Conversation

lambda-fairy
Copy link
Contributor

cc #24407

@rust-highfive
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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:

  1. 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
  2. I don't want to add more churn when the syntax is stabilizing soon anyway

Copy link
Contributor

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');
}

Copy link
Member

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.

@lambda-fairy
Copy link
Contributor Author

I've pushed a revised version -- thanks for the feedback!

@alexcrichton re-r?

@alexcrichton
Copy link
Member

@bors: r+ 98faf54 rollup

Thanks!

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Apr 16, 2015
bors added a commit that referenced this pull request Apr 16, 2015
bors added a commit that referenced this pull request Apr 17, 2015
bors added a commit that referenced this pull request Apr 17, 2015
@steveklabnik
Copy link
Member

This was merged in #24512 , sorry, I rebased and forgot that'd screw it up :(

@lambda-fairy lambda-fairy deleted the explainify branch June 2, 2016 03:39
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants