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

Overlapping From impls produce confusing errors in async code #69632

Closed
DomantasJ opened this issue Mar 2, 2020 · 1 comment
Closed

Overlapping From impls produce confusing errors in async code #69632

DomantasJ opened this issue Mar 2, 2020 · 1 comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DomantasJ
Copy link

DomantasJ commented Mar 2, 2020

Playground

struct MyError;

impl<T> From<T> for MyError {
    fn from(error: T) -> Self {
        MyError::from(error)
    }
}

async fn test() -> Result<(), MyError> {
    block().await?;
    Ok(())
}

async fn block() -> Result<(), MyError> {
    Ok(())
}

This produces a rather confusing error:

error[E0283]: type annotations needed
  --> src/lib.rs:10:18
   |
10 |     block().await?;
   |                  ^ cannot infer type for struct `MyError`
   |
   = note: cannot resolve `MyError: std::convert::From<MyError>`
   = note: required by `std::convert::From::from`

If you make functions non-async and remove the await then you get a proper error about overlapping From impls:

error[E0119]: conflicting implementations of trait `std::convert::From<MyError>` for type `MyError`:
 --> src/lib.rs:3:1
  |
3 | impl<T> From<T> for MyError {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: conflicting implementation in crate `core`:
          - impl<T> std::convert::From<T> for T;

Meta

Rust version 1.41.1 (current version on playground)
Same problem appears on beta and nightly.

@DomantasJ DomantasJ added the C-bug Category: This is a bug. label Mar 2, 2020
@jonas-schievink jonas-schievink added A-async-await Area: Async & Await 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. labels Mar 2, 2020
@tmandry
Copy link
Member

tmandry commented Mar 3, 2020

Duplicate of #67651

@tmandry tmandry marked this as a duplicate of #67651 Mar 3, 2020
@tmandry tmandry closed this as completed Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. 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

3 participants