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

incorrect error message for duplicate Send impl #69938

Closed
ultrasaurus opened this issue Mar 11, 2020 · 4 comments
Closed

incorrect error message for duplicate Send impl #69938

ultrasaurus opened this issue Mar 11, 2020 · 4 comments
Labels
A-async-await A-diagnostics AsyncAwait-Triaged C-bug D-incorrect P-medium T-compiler

Comments

@ultrasaurus
Copy link

@ultrasaurus ultrasaurus commented Mar 11, 2020

For a specific case, the compiler reports an incorrect error message when there is a duplicate error

I tried this code:

pub struct Foo(*const ());

unsafe impl Send for Foo {}
unsafe impl Send for Foo {}

impl Foo {
    fn bar(&self) {}
}

fn assert_send<T: Send>(_: T) {}

fn main() {
    let foo = Foo(&());
    assert_send(async move {
         foo.bar();
    })
}

it reports this error:

  |
10 | fn assert_send<T: Send>(_: T) {}
   |    -----------    ---- required by this bound in `assert_send`
...
13 |     let foo = Foo(&());
   |         --- consider giving `foo` a type
14 |     assert_send(async move {
   |     ^^^^^^^^^^^ cannot infer type for struct `Foo`
   |
   = note: cannot resolve `Foo: std::marker::Send`
   = note: required because it appears within the type `[static generator@src/main.rs:14:28: 16:6 foo:Foo {}]`
   = note: required because it appears within the type `std::future::GenFuture<[static generator@src/main.rs:14:28: 16:6 foo:Foo {}]>`
   = note: required because it appears within the type `impl std::future::Future

If I comment out the line that calls foo.bar() I get the expected error:

 |
3 | unsafe impl Send for Foo {}
  | ------------------------ first implementation here
4 | unsafe impl Send for Foo {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Foo`

Here's a playground

Meta

Reproduced in 1.14.1, It also happens in nightly

originally found in
rustc --version --verbose:

rustc --version --verbose
rustc 1.41.0 (5e1a79984 2020-01-27)
binary: rustc
commit-hash: 5e1a799842ba6ed4a57e91f7ab9435947482f7d8
commit-date: 2020-01-27
host: x86_64-apple-darwin
release: 1.41.0
LLVM version: 9.0

@ultrasaurus ultrasaurus added the C-bug label Mar 11, 2020
@ultrasaurus
Copy link
Author

@ultrasaurus ultrasaurus commented Mar 11, 2020

thx @sgrif for helping to create an isolated example!

@sgrif
Copy link
Contributor

@sgrif sgrif commented Mar 11, 2020

/cc @estebank

@jonas-schievink jonas-schievink added A-diagnostics D-incorrect T-compiler labels Mar 11, 2020
@Centril Centril added the A-async-await label Mar 11, 2020
@tmandry
Copy link
Contributor

@tmandry tmandry commented Mar 17, 2020

Seems related to #67651, and may be fixed by #68884.

@tmandry tmandry added AsyncAwait-Triaged P-medium labels Mar 17, 2020
@csmoe
Copy link
Member

@csmoe csmoe commented May 11, 2020

Fixed in latest nightly

error[E0119]: conflicting implementations of trait `std::marker::Send` for type `Foo`:
 --> src/main.rs:4:1
  |
3 | unsafe impl Send for Foo {}
  | ------------------------ first implementation here
4 | unsafe impl Send for Foo {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Foo`

@csmoe csmoe closed this as completed May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await A-diagnostics AsyncAwait-Triaged C-bug D-incorrect P-medium T-compiler
Projects
None yet
Development

No branches or pull requests

6 participants