Skip to content

Commit

Permalink
Add or_fun_call tests
Browse files Browse the repository at this point in the history
  • Loading branch information
camsteffen committed Oct 29, 2020
1 parent 741d497 commit 1a03eec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
8 changes: 8 additions & 0 deletions tests/ui/or_fun_call.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ fn or_fun_call() {
let opt = Some(1);
let hello = "Hello";
let _ = opt.ok_or(format!("{} world.", hello));

// reference
let _ = Some(&1).unwrap_or_else(|| &make());
// index
let map = HashMap::<u64, u64>::new();
let _ = Some(1).unwrap_or_else(|| map[&1]);
// index and reference
let _ = Some(&1).unwrap_or_else(|| &map[&1]);
}

struct Foo(u8);
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/or_fun_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ fn or_fun_call() {
let opt = Some(1);
let hello = "Hello";
let _ = opt.ok_or(format!("{} world.", hello));

// reference
let _ = Some(&1).unwrap_or(&make());
// index
let map = HashMap::<u64, u64>::new();
let _ = Some(1).unwrap_or(map[&1]);
// index and reference
let _ = Some(&1).unwrap_or(&map[&1]);
}

struct Foo(u8);
Expand Down
24 changes: 21 additions & 3 deletions tests/ui/or_fun_call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,35 @@ error: use of `unwrap_or` followed by a function call
LL | let _ = stringy.unwrap_or("".to_owned());
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())`

error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:75:22
|
LL | let _ = Some(&1).unwrap_or(&make());
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| &make())`

error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:78:21
|
LL | let _ = Some(1).unwrap_or(map[&1]);
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`

error: use of `unwrap_or` followed by a function call
--> $DIR/or_fun_call.rs:80:22
|
LL | let _ = Some(&1).unwrap_or(&map[&1]);
| ^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| &map[&1])`

error: use of `or` followed by a function call
--> $DIR/or_fun_call.rs:93:35
--> $DIR/or_fun_call.rs:101:35
|
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`

error: use of `or` followed by a function call
--> $DIR/or_fun_call.rs:97:10
--> $DIR/or_fun_call.rs:105: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
error: aborting due to 18 previous errors

0 comments on commit 1a03eec

Please sign in to comment.