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 playground
Anything else?
No response
Code
Current output
Desired output
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
unwraporexpectis constmaybe even give a note instead about that you can't
unwrapResult in const so they need to found other workaroundOther cases
Rust Version
was tested in stable and nightly on playgroundAnything else?
No response