Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c0f0b51

Browse files
committed
Add ui test for for-loops-over-falibles
Signed-off-by: xizheyin <[email protected]>
1 parent 7e552b4 commit c0f0b51

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![forbid(for_loops_over_fallibles)]
2+
3+
fn main() {
4+
macro_rules! x {
5+
() => {
6+
None::<i32> //~ ERROR for loop over an `Option`. This is more readably written as an `if let` statement [for_loops_over_fallibles]
7+
};
8+
}
9+
for _ in x! {} {}
10+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: for loop over an `Option`. This is more readably written as an `if let` statement
2+
--> $DIR/macro-issue-140747.rs:6:13
3+
|
4+
LL | None::<i32>
5+
| ^^^^^^^^^^^
6+
...
7+
LL | for _ in x! {} {}
8+
| ----- in this macro invocation
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/macro-issue-140747.rs:1:11
12+
|
13+
LL | #![forbid(for_loops_over_fallibles)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^
15+
= note: this error originates in the macro `x` (in Nightly builds, run with -Z macro-backtrace for more info)
16+
help: to check pattern in a loop use `while let`
17+
|
18+
LL ~ ) =
19+
LL | };
20+
LL | }
21+
LL ~ while let Some(_ in x! {} {}
22+
|
23+
help: consider using `if let` to clear intent
24+
|
25+
LL ~ ) =
26+
LL | };
27+
LL | }
28+
LL ~ if let Some(_ in x! {} {}
29+
|
30+
31+
error: aborting due to 1 previous error
32+

0 commit comments

Comments
 (0)