-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #102441 - chenyukang:fix-102320-unwrap_or_else, r=com…
…piler-errors Suggest unwrap_or_else when a closure is given Fixes #102320 r? `@compiler-errors`
- Loading branch information
Showing
5 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
let x = "com.example.app"; | ||
let y: Option<&str> = None; | ||
let _s = y.unwrap_or_else(|| x.split('.').nth(1).unwrap()); | ||
//~^ ERROR: mismatched types [E0308] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// run-rustfix | ||
|
||
fn main() { | ||
let x = "com.example.app"; | ||
let y: Option<&str> = None; | ||
let _s = y.unwrap_or(|| x.split('.').nth(1).unwrap()); | ||
//~^ ERROR: mismatched types [E0308] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/sugg-else-for-closure.rs:6:26 | ||
| | ||
LL | let _s = y.unwrap_or(|| x.split('.').nth(1).unwrap()); | ||
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found closure | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: expected reference `&str` | ||
found closure `[closure@$DIR/sugg-else-for-closure.rs:6:26: 6:28]` | ||
note: associated function defined here | ||
--> $SRC_DIR/core/src/option.rs:LL:COL | ||
| | ||
LL | pub const fn unwrap_or(self, default: T) -> T | ||
| ^^^^^^^^^ | ||
help: try calling `unwrap_or_else` instead | ||
| | ||
LL | let _s = y.unwrap_or_else(|| x.split('.').nth(1).unwrap()); | ||
| +++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |