Skip to content

Commit

Permalink
option_if_let_else - change misleading test file section
Browse files Browse the repository at this point in the history
  • Loading branch information
tnielens committed Sep 16, 2020
1 parent 6ba36bc commit 79da747
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
7 changes: 4 additions & 3 deletions tests/ui/unnecessary_lazy_eval.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ fn main() {
let _: Result<usize, usize> = res.or_else(|_| Err(ext_str.some_field));

// should lint, bind_instead_of_map doesn't apply
let _: Result<usize, usize> = res.and_then(|x| Err(x));
let _: Result<usize, usize> = res.or_else(|err| Ok(err));

let _: Result<usize, usize> = res.and(Err(2));
let _: Result<usize, usize> = res.and(Err(astronomers_pi));
let _: Result<usize, usize> = res.and(Err(ext_str.some_field));

let _: Result<usize, usize> = res.or(Ok(2));
let _: Result<usize, usize> = res.or(Ok(astronomers_pi));
let _: Result<usize, usize> = res.or(Ok(ext_str.some_field));

// neither bind_instead_of_map nor unnecessary_lazy_eval applies here
let _: Result<usize, usize> = res.and_then(|x| Err(x));
let _: Result<usize, usize> = res.or_else(|err| Ok(err));
}
7 changes: 4 additions & 3 deletions tests/ui/unnecessary_lazy_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ fn main() {
let _: Result<usize, usize> = res.or_else(|_| Err(ext_str.some_field));

// should lint, bind_instead_of_map doesn't apply
let _: Result<usize, usize> = res.and_then(|x| Err(x));
let _: Result<usize, usize> = res.or_else(|err| Ok(err));

let _: Result<usize, usize> = res.and_then(|_| Err(2));
let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field));

let _: Result<usize, usize> = res.or_else(|_| Ok(2));
let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));

// neither bind_instead_of_map nor unnecessary_lazy_eval applies here
let _: Result<usize, usize> = res.and_then(|x| Err(x));
let _: Result<usize, usize> = res.or_else(|err| Ok(err));
}
12 changes: 6 additions & 6 deletions tests/ui/unnecessary_lazy_eval.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -157,37 +157,37 @@ LL | let _ = res2.unwrap_or_else(|_| ext_str.some_field);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `unwrap_or` instead: `res2.unwrap_or(ext_str.some_field)`

error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval.rs:114:35
--> $DIR/unnecessary_lazy_eval.rs:111:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(2));
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(2))`

error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval.rs:115:35
--> $DIR/unnecessary_lazy_eval.rs:112:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(astronomers_pi));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(astronomers_pi))`

error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval.rs:116:35
--> $DIR/unnecessary_lazy_eval.rs:113:35
|
LL | let _: Result<usize, usize> = res.and_then(|_| Err(ext_str.some_field));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `and` instead: `res.and(Err(ext_str.some_field))`

error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval.rs:118:35
--> $DIR/unnecessary_lazy_eval.rs:115:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(2));
| ^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(2))`

error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval.rs:119:35
--> $DIR/unnecessary_lazy_eval.rs:116:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(astronomers_pi));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(astronomers_pi))`

error: unnecessary closure used to substitute value for `Result::Err`
--> $DIR/unnecessary_lazy_eval.rs:120:35
--> $DIR/unnecessary_lazy_eval.rs:117:35
|
LL | let _: Result<usize, usize> = res.or_else(|_| Ok(ext_str.some_field));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Use `or` instead: `res.or(Ok(ext_str.some_field))`
Expand Down

0 comments on commit 79da747

Please sign in to comment.