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

E0308 source of expectation isn't shown for closures #106821

Open
estebank opened this issue Jan 13, 2023 · 1 comment
Open

E0308 source of expectation isn't shown for closures #106821

estebank opened this issue Jan 13, 2023 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

fn main() {
|| {
if false {
return Foo(0);
}
Foo(())
//~^ ERROR mismatched types [E0308]
};
}

currently emits

error[E0308]: mismatched types
--> $DIR/issue-84128.rs:13:13
|
LL | Foo(())
| --- ^^ expected integer, found `()`
| |
| arguments to this struct are incorrect
|
note: tuple struct defined here
--> $DIR/issue-84128.rs:5:8
|
LL | struct Foo<T>(T);
| ^^^

It should include the source of the expectation (the return statement earlier in the closure).

Noticed here https://github.com/rust-lang/rust/pull/106752/files#r1069781007

@estebank estebank added 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. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Jan 13, 2023
@estebank
Copy link
Contributor Author

Another few other cases

async fn func() -> Result<u16, u64> {
let _ = async {
Err(42u64)
}.await?;
Ok(())
//~^ ERROR: mismatched types [E0308]
}
async fn func2() -> Result<u16, u64> {
Err(42u64)?;
Ok(())
//~^ ERROR: mismatched types [E0308]
}
fn main() {
|| -> Result<u16, u64> {
if true {
return Err(42u64);
}
Ok(())
//~^ ERROR: mismatched types [E0308]
};
}

error[E0308]: mismatched types
--> $DIR/args-instead-of-tuple-errors.rs:14:34
|
LL | let _: Option<(i32,)> = Some(5_usize);
| ---- ^^^^^^^ expected tuple, found `usize`
| |
| arguments to this enum variant are incorrect
|
= note: expected tuple `(i32,)`
found type `usize`
note: tuple variant defined here
--> $SRC_DIR/core/src/option.rs:LL:COL

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 D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. 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

1 participant