File tree 2 files changed +17
-5
lines changed
2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ fn or_fun_call() {
29
29
with_enum.unwrap_or(Enum::A(5));
30
30
31
31
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));
33
33
34
34
let with_constructor = Some(vec![1]);
35
35
with_constructor.unwrap_or_else(make);
@@ -94,7 +94,7 @@ fn test_or_with_ctors() {
94
94
95
95
let b = "b".to_string();
96
96
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))));
98
98
99
99
let vec = vec!["foo"];
100
100
let _ = opt.ok_or(vec.len());
Original file line number Diff line number Diff line change
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
+
1
9
error: use of `unwrap_or` followed by a function call
2
10
--> $DIR/or_fun_call.rs:35:22
3
11
|
4
12
LL | with_constructor.unwrap_or(make());
5
13
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
6
- |
7
- = note: `-D clippy::or-fun-call` implied by `-D warnings`
8
14
9
15
error: use of `unwrap_or` followed by a call to `new`
10
16
--> $DIR/or_fun_call.rs:38:5
@@ -78,5 +84,11 @@ error: use of `or` followed by a function call
78
84
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
79
85
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
80
86
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
82
94
You can’t perform that action at this time.
0 commit comments