Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False/Irrelevant Error E0277 #50333

Closed
isaacg1 opened this issue Apr 30, 2018 · 0 comments
Closed

False/Irrelevant Error E0277 #50333

isaacg1 opened this issue Apr 30, 2018 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@isaacg1
Copy link

isaacg1 commented Apr 30, 2018

On type mismatchses when using trait objects, rust emits error E0277, saying that the trait does not have a constant size known at compile-time, and that all local variables must have a statically known type. In fact, the problem lies elsewhere, and the program can be fixed without addressing the E0277 error at all.

I wrote this code:

trait T {}

struct A;
impl T for A {}
impl A {
    fn new() -> Self {
        Self {}
    }
}

fn main() {
    let (a, b, c) = (A::new(), A::new()); // This tuple is 2 elements, should be three
    let ts: Vec<&T> = vec![&a, &b, &c];
    println!("{}", ts.len());
}

The marked tuple has 2 A::new() copies, when it should have 3. If this is fixed, the code compiles. I would expect to see a single error pointing out this fact. Instead, four errors are returned:

   Compiling bug v0.1.0 (file:///home/isaac/prog/rust/bug)
error[E0308]: mismatched types
  --> src/main.rs:12:9
   |
12 |     let (a, b, c) = (A::new(), A::new());
   |         ^^^^^^^^^ expected a tuple with 2 elements, found one with 3 elements
   |
   = note: expected type `(A, A)`
              found type `(_, _, _)`

error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
  --> src/main.rs:12:10
   |
12 |     let (a, b, c) = (A::new(), A::new());
   |          ^ `T` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `T`
   = note: all local variables must have a statically known size

error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
  --> src/main.rs:12:13
   |
12 |     let (a, b, c) = (A::new(), A::new());
   |             ^ `T` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `T`
   = note: all local variables must have a statically known size

error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
  --> src/main.rs:12:16
   |
12 |     let (a, b, c) = (A::new(), A::new());
   |                ^ `T` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `T`
   = note: all local variables must have a statically known size

error: aborting due to 4 previous errors

error: Could not compile `bug`.

Only the first of these errors is related to the bug - the other three are all false and/or irrelevant.

Meta

rustc --version --verbose:

rustc 1.25.0 (84203ca 2018-03-25)
binary: rustc
commit-hash: 84203ca
commit-date: 2018-03-25
host: x86_64-unknown-linux-gnu
release: 1.25.0
LLVM version: 6.0

Also produced on nightly 1.27.0

@pnkfelix pnkfelix added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-diagnostics Area: Messages for errors, warnings, and lints labels Apr 30, 2018
kennytm added a commit to kennytm/rust that referenced this issue Sep 13, 2018
Do not emit E0277 on incorrect tuple destructured binding

Fix rust-lang#50333.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants