Skip to content

Commit 1a03eec

Browse files
committed
Add or_fun_call tests
1 parent 741d497 commit 1a03eec

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

tests/ui/or_fun_call.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ fn or_fun_call() {
7070
let opt = Some(1);
7171
let hello = "Hello";
7272
let _ = opt.ok_or(format!("{} world.", hello));
73+
74+
// reference
75+
let _ = Some(&1).unwrap_or_else(|| &make());
76+
// index
77+
let map = HashMap::<u64, u64>::new();
78+
let _ = Some(1).unwrap_or_else(|| map[&1]);
79+
// index and reference
80+
let _ = Some(&1).unwrap_or_else(|| &map[&1]);
7381
}
7482

7583
struct Foo(u8);

tests/ui/or_fun_call.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ fn or_fun_call() {
7070
let opt = Some(1);
7171
let hello = "Hello";
7272
let _ = opt.ok_or(format!("{} world.", hello));
73+
74+
// reference
75+
let _ = Some(&1).unwrap_or(&make());
76+
// index
77+
let map = HashMap::<u64, u64>::new();
78+
let _ = Some(1).unwrap_or(map[&1]);
79+
// index and reference
80+
let _ = Some(&1).unwrap_or(&map[&1]);
7381
}
7482

7583
struct Foo(u8);

tests/ui/or_fun_call.stderr

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,35 @@ error: use of `unwrap_or` followed by a function call
7878
LL | let _ = stringy.unwrap_or("".to_owned());
7979
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| "".to_owned())`
8080

81+
error: use of `unwrap_or` followed by a function call
82+
--> $DIR/or_fun_call.rs:75:22
83+
|
84+
LL | let _ = Some(&1).unwrap_or(&make());
85+
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| &make())`
86+
87+
error: use of `unwrap_or` followed by a function call
88+
--> $DIR/or_fun_call.rs:78:21
89+
|
90+
LL | let _ = Some(1).unwrap_or(map[&1]);
91+
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
92+
93+
error: use of `unwrap_or` followed by a function call
94+
--> $DIR/or_fun_call.rs:80:22
95+
|
96+
LL | let _ = Some(&1).unwrap_or(&map[&1]);
97+
| ^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| &map[&1])`
98+
8199
error: use of `or` followed by a function call
82-
--> $DIR/or_fun_call.rs:93:35
100+
--> $DIR/or_fun_call.rs:101:35
83101
|
84102
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
85103
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
86104

87105
error: use of `or` followed by a function call
88-
--> $DIR/or_fun_call.rs:97:10
106+
--> $DIR/or_fun_call.rs:105:10
89107
|
90108
LL | .or(Some(Bar(b, Duration::from_secs(2))));
91109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`
92110

93-
error: aborting due to 15 previous errors
111+
error: aborting due to 18 previous errors
94112

0 commit comments

Comments
 (0)