-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
const fn f(value: u32) -> Result<u32, ()> {
Ok(value)
}
const TEST: u32 = f(2);Current output
error[E0308]: mismatched types
--> src/lib.rs:10:19
|
10 | const TEST: u32 = f(2);
| ^^^^ expected `u32`, found `Result<u32, ()>`
|
= note: expected type `u32`
found enum `Result<u32, ()>`
help: consider using `Result::expect` to unwrap the `Result<u32, ()>` value, panicking if the value is a `Result::Err`
|
10 | const TEST: u32 = f(2).expect("REASON");
| +++++++++++++++++Desired output
error[E0308]: mismatched types
--> src/lib.rs:10:19
|
10 | const TEST: u32 = f(2);
| ^^^^ expected `u32`, found `Result<u32, ()>`
|
= note: expected type `u32`
found enum `Result<u32, ()>`Rationale and extra context
I don't quiet sure about what is the best desired output, but for start it should be nice to remove this missleading suggestion to unwrap Result's value in const context which is not possible since neither unwrap or expect is const
maybe even give a note instead about that you can't unwrap Result in const so they need to found other workaround
Other cases
Rust Version
was tested in stable and nightly on playgroundAnything else?
No response
reddevilmidzy and FeldrinH
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.