This commit is contained in:
flip1995 2020-06-07 03:07:48 +02:00
parent 1a8a69d012
commit 5bdbc45ae5
No known key found for this signature in database
GPG Key ID: 2CEFCDB27ED0BE79
2 changed files with 17 additions and 5 deletions

View File

@ -29,7 +29,7 @@ fn or_fun_call() {
with_enum.unwrap_or(Enum::A(5));
let with_const_fn = Some(Duration::from_secs(1));
with_const_fn.unwrap_or(Duration::from_secs(5));
with_const_fn.unwrap_or_else(|| Duration::from_secs(5));
let with_constructor = Some(vec![1]);
with_constructor.unwrap_or_else(make);
@ -94,7 +94,7 @@ fn test_or_with_ctors() {
let b = "b".to_string();
let _ = Some(Bar("a".to_string(), Duration::from_secs(1)))
.or(Some(Bar(b, Duration::from_secs(2))));
.or_else(|| Some(Bar(b, Duration::from_secs(2))));
let vec = vec!["foo"];
let _ = opt.ok_or(vec.len());

View File

@ -1,10 +1,16 @@
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:32:19
|
LL | with_const_fn.unwrap_or(Duration::from_secs(5));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| Duration::from_secs(5))`
|
= note: `-D clippy::or-fun-call` implied by `-D warnings`
error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:35:22
|
LL | with_constructor.unwrap_or(make());
| ^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(make)`
|
= note: `-D clippy::or-fun-call` implied by `-D warnings`
error: use of `unwrap_or` followed by a call to `new`
--> $DIR/or_fun_call.rs:38:5
@ -78,5 +84,11 @@ error: use of `or` followed by a function call
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
error: aborting due to 13 previous errors
error: use of `or` followed by a function call
--> $DIR/or_fun_call.rs:97:10
|
LL | .or(Some(Bar(b, Duration::from_secs(2))));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`
error: aborting due to 15 previous errors