This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
tests/ui/lint/for-loops-over-falibles Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments