forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#6272 - camsteffen:unnecesary-lazy-eval-type, …
…r=llogiq Fix unnecessary_lazy_eval suggestion applicability changelog: Fix unnecessary_lazy_eval suggestion applicability when breaking type inference Fixes rust-lang#6240
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#![warn(clippy::unnecessary_lazy_evaluations)] | ||
|
||
struct Deep(Option<usize>); | ||
|
||
#[derive(Copy, Clone)] | ||
struct SomeStruct { | ||
some_field: usize, | ||
} | ||
|
||
fn main() { | ||
// fix will break type inference | ||
let _ = Ok(1).unwrap_or_else(|()| 2); | ||
mod e { | ||
pub struct E; | ||
} | ||
let _ = Ok(1).unwrap_or_else(|e::E| 2); | ||
let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | ||
} |
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,22 @@ | ||
error: unnecessary closure used to substitute value for `Result::Err` | ||
--> $DIR/unnecessary_lazy_eval_unfixable.rs:12:13 | ||
| | ||
LL | let _ = Ok(1).unwrap_or_else(|()| 2); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)` | ||
| | ||
= note: `-D clippy::unnecessary-lazy-evaluations` implied by `-D warnings` | ||
|
||
error: unnecessary closure used to substitute value for `Result::Err` | ||
--> $DIR/unnecessary_lazy_eval_unfixable.rs:16:13 | ||
| | ||
LL | let _ = Ok(1).unwrap_or_else(|e::E| 2); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)` | ||
|
||
error: unnecessary closure used to substitute value for `Result::Err` | ||
--> $DIR/unnecessary_lazy_eval_unfixable.rs:17:13 | ||
| | ||
LL | let _ = Ok(1).unwrap_or_else(|SomeStruct { .. }| 2); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `Ok(1).unwrap_or(2)` | ||
|
||
error: aborting due to 3 previous errors | ||
|