Skip to content

async fn presence affects an unrelated error message #66312

Closed
@tguser402

Description

@tguser402

The following code

trait Test<T> {
    fn is_some(self: T);
}

fn f() {
    let x = Some(2);
    if x.is_some() {
        println!("Some");
    }
}

produces an expected error:

error[E0307]: invalid `self` parameter type: T
 --> src/lib.rs:2:22
  |
2 |     fn is_some(self: T);
  |                      ^
  |
  = note: type of `self` must be `Self` or a type that dereferences to it
  = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)

If I make f async,

trait Test<T> {
    fn is_some(self: T);
}

async fn f() {
    let x = Some(2);
    if x.is_some() {
        println!("Some");
    }
}

the original error is replaced with this:

error[E0308]: mismatched types
 --> src/lib.rs:7:8
  |
7 |     if x.is_some() {
  |        ^^^^^^^^^^^ expected bool, found ()
  |
  = note: expected type `bool`
             found type `()`

Meta

rustc --version --verbose:

rustc 1.39.0 (4560ea788 2019-11-04)
binary: rustc
commit-hash: 4560ea788cb760f0a34127156c78e2552949f734
commit-date: 2019-11-04
host: x86_64-unknown-linux-gnu
release: 1.39.0
LLVM version: 9.0

Metadata

Metadata

Assignees

Labels

A-async-awaitArea: Async & AwaitA-trait-systemArea: Trait systemAsyncAwait-PolishAsync-await issues that are part of the "polish" areaAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions