Skip to content

"consider using a semicolon" where there already is one, after a ? #87051

Closed
@ben0x539

Description

@ben0x539

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=47f2843373fb4ad713fa520aa446ee5a

fn main() -> Result<(), ()> {
    a(|| {
        b()
    })?;
    
    Ok(())
}

fn a<F>(f: F) -> Result<(), ()> where F: FnMut() { Ok(()) }
fn b() -> i32 { 42 }

The current output is:

error[E0308]: mismatched types
 --> src/main.rs:3:9
  |
2 | /     a(|| {
3 | |         b()
  | |         ^^^ expected `()`, found `i32`
4 | |     })?;
  | |_______- expected this to be `()`
  |
help: consider using a semicolon here
  |
3 |         b();
  |            ^
help: consider using a semicolon here
  |
4 |     })?;;
  |        ^

Ideally the output should look like:

error[E0308]: mismatched types
 --> src/main.rs:3:9
  |
3 |          b()
  |          ^^^ expected `()`, found `i32`
  |
help: consider using a semicolon here
  |
3 |         b();
  |            ^

(I guess, even tho in my un-reduced case I needed to make a take a closure returning a non-() thing)

Doesn't happen without the ?.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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