-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
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
If map_or
's first arguments is given a closure, the diagnostic now is as below, which is not right:
fn main() {
let k = 1 as usize;
let x: Option<&str> = None;
let _res = x.map_or(|| k * 2, |v| v.len());
}
The current output is:
Compiling playground v0.0.1 (/playground)
error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
--> src/main.rs:5:39
|
5 | let _res = x.map_or(|| k * 2, |v| v.len());
| -- ^^^^^^^ expected closure, found `usize`
| |
| the expected closure
|
= note: expected closure `[closure@src/main.rs:5:25: 5:27]`
found type `usize`
For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error
Ideally, we should suggest to use map_or_else
.
Maybe related to #102320, which I was working on, but the above diagnostic message for arguments is not right, may be another issue.
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.