Skip to content

Unhelpful error message for async method on invalid type #72590

Closed
@euclio

Description

@euclio

I tried this code:

Playground

struct Foo {
    foo: Nonexistent,
}

impl Foo {
    async fn frob(mut self) {}
}

I expected to see this happen: resolution error reported for Nonexistent type.

Instead, this happened: In addition to the resolution error, the compiler emitted errors complaining that it couldn't determine the size of Foo. That error is also emitted twice. These errors should be silent, since the true error is that Foo isn't fully formed.

error[E0412]: cannot find type `Nonexistent` in this scope
 --> src/lib.rs:2:10
  |
2 |     foo: Nonexistent,
  |          ^^^^^^^^^^^ not found in this scope

error[E0161]: cannot move a value of type Foo: the size of Foo cannot be statically determined
 --> src/lib.rs:6:19
  |
6 |     async fn frob(mut self) {}
  |                   ^^^^^^^^

error[E0161]: cannot move a value of type Foo: the size of Foo cannot be statically determined
 --> src/lib.rs:6:19
  |
6 |     async fn frob(mut self) {}
  |                   ^^^^^^^^

warning: variable does not need to be mutable
 --> src/lib.rs:6:19
  |
6 |     async fn frob(mut self) {}
  |                   ----^^^^
  |                   |
  |                   help: remove this `mut`
  |
  = note: `#[warn(unused_mut)]` on by default

error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0161, E0412.
For more information about an error, try `rustc --explain E0161`.

Meta

rustc --version --verbose:

rustc 1.45.0-nightly (a74d1862d 2020-05-14)
binary: rustc
commit-hash: a74d1862d4d87a56244958416fd05976c58ca1a8
commit-date: 2020-05-14
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 9.0
Backtrace

<backtrace>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions