Skip to content

Commit 5bdbc45

Browse files
committed
1 parent 1a8a69d commit 5bdbc45

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

tests/ui/or_fun_call.fixed

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn or_fun_call() {
2929
with_enum.unwrap_or(Enum::A(5));
3030

3131
let with_const_fn = Some(Duration::from_secs(1));
32-
with_const_fn.unwrap_or(Duration::from_secs(5));
32+
with_const_fn.unwrap_or_else(|| Duration::from_secs(5));
3333

3434
let with_constructor = Some(vec![1]);
3535
with_constructor.unwrap_or_else(make);
@@ -94,7 +94,7 @@ fn test_or_with_ctors() {
9494

9595
let b = "b".to_string();
9696
let _ = Some(Bar("a".to_string(), Duration::from_secs(1)))
97-
.or(Some(Bar(b, Duration::from_secs(2))));
97+
.or_else(|| Some(Bar(b, Duration::from_secs(2))));
9898

9999
let vec = vec!["foo"];
100100
let _ = opt.ok_or(vec.len());

tests/ui/or_fun_call.stderr

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
error: use of `unwrap_or` followed by a function call
2+
--> $DIR/or_fun_call.rs:32:19
3+
|
4+
LL | with_const_fn.unwrap_or(Duration::from_secs(5));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Duration::from_secs(5))`
6+
|
7+
= note: `-D clippy::or-fun-call` implied by `-D warnings`
8+
19
error: use of `unwrap_or` followed by a function call
210
--> $DIR/or_fun_call.rs:35:22
311
|
412
LL | with_constructor.unwrap_or(make());
513
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
6-
|
7-
= note: `-D clippy::or-fun-call` implied by `-D warnings`
814

915
error: use of `unwrap_or` followed by a call to `new`
1016
--> $DIR/or_fun_call.rs:38:5
@@ -78,5 +84,11 @@ error: use of `or` followed by a function call
7884
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
7985
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
8086

81-
error: aborting due to 13 previous errors
87+
error: use of `or` followed by a function call
88+
--> $DIR/or_fun_call.rs:97:10
89+
|
90+
LL | .or(Some(Bar(b, Duration::from_secs(2))));
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`
92+
93+
error: aborting due to 15 previous errors
8294

0 commit comments

Comments
 (0)