Skip to content

Commit cfa3c3e

Browse files
committed
Add or_fun_call index test
1 parent b8a9ab9 commit cfa3c3e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

tests/ui/or_fun_call.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ fn or_fun_call() {
7070
let opt = Some(1);
7171
let hello = "Hello";
7272
let _ = opt.ok_or(format!("{} world.", hello));
73+
74+
// index
75+
let map = HashMap::<u64, u64>::new();
76+
let _ = Some(1).unwrap_or_else(|| map[&1]);
7377
}
7478

7579
struct Foo(u8);

tests/ui/or_fun_call.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ fn or_fun_call() {
7070
let opt = Some(1);
7171
let hello = "Hello";
7272
let _ = opt.ok_or(format!("{} world.", hello));
73+
74+
// index
75+
let map = HashMap::<u64, u64>::new();
76+
let _ = Some(1).unwrap_or(map[&1]);
7377
}
7478

7579
struct Foo(u8);

tests/ui/or_fun_call.stderr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,23 @@ 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:76:21
83+
|
84+
LL | let _ = Some(1).unwrap_or(map[&1]);
85+
| ^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| map[&1])`
86+
8187
error: use of `or` followed by a function call
82-
--> $DIR/or_fun_call.rs:93:35
88+
--> $DIR/or_fun_call.rs:97:35
8389
|
8490
LL | let _ = Some("a".to_string()).or(Some("b".to_string()));
8591
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some("b".to_string()))`
8692

8793
error: use of `or` followed by a function call
88-
--> $DIR/or_fun_call.rs:97:10
94+
--> $DIR/or_fun_call.rs:101:10
8995
|
9096
LL | .or(Some(Bar(b, Duration::from_secs(2))));
9197
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `or_else(|| Some(Bar(b, Duration::from_secs(2))))`
9298

93-
error: aborting due to 15 previous errors
99+
error: aborting due to 16 previous errors
94100

0 commit comments

Comments
 (0)