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

let else: wrong diagnostic span on return type mismatch #96961

Closed
Dirbaio opened this issue May 12, 2022 · 3 comments · Fixed by #100443
Closed

let else: wrong diagnostic span on return type mismatch #96961

Dirbaio opened this issue May 12, 2022 · 3 comments · Fixed by #100443
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-let_else Issues related to let-else statements (RFC 3137) requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented May 12, 2022

The following code [playground]

#![feature(let_else)]

fn foo() -> u32 {
    println!("foo");

    let () = () else {
        return 12;
    };

    println!("foo");
}

fails to build with the following:

error[E0308]: mismatched types
 --> src/lib.rs:6:5
  |
6 | /     let () = () else {
7 | |         return 12;
8 | |     };
  | |______^ expected `u32`, found `()`

note the span points to just the let .. else, but there's nothing wrong with it, the problem is the function return type doesn't match. I'd have expected the error to look the same as if the let else wasn't there, which is:

error[E0308]: mismatched types
 --> src/lib.rs:3:13
  |
3 | fn foo() -> u32 {
  |    ---      ^^^ expected `u32`, found `()`
  |    |
  |    implicitly returns `()` as its body has no tail or `return` expression
@TaKO8Ki TaKO8Ki added the A-diagnostics Area: Messages for errors, warnings, and lints label May 12, 2022
@rajrupdasofficial
Copy link

yeah I also see that , it's some type of compiler issue or some mistake while creating the example

@est31
Copy link
Member

est31 commented May 12, 2022

@rustbot labels: +T-compiler +F-let-else +requires-nightly

@rustbot rustbot added F-let_else Issues related to let-else statements (RFC 3137) requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 12, 2022
@est31
Copy link
Member

est31 commented May 13, 2022

This is a dupe of #94176.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-let_else Issues related to let-else statements (RFC 3137) requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants