@@ -10,7 +10,16 @@ use rustc_span::{sym, Span};
10
10
use rustc_trait_selection:: traits:: TraitEngineExt ;
11
11
12
12
declare_lint ! {
13
- /// Checks for `for` loops over `Option` or `Result` values.
13
+ /// The `for_loop_over_fallibles` lint checks for `for` loops over `Option` or `Result` values.
14
+ ///
15
+ /// ### Example
16
+ ///
17
+ /// ```rust
18
+ /// let opt = Some(1);
19
+ /// for x in opt { /* ... */}
20
+ /// ```
21
+ ///
22
+ /// {{produces}}
14
23
///
15
24
/// ### Explanation
16
25
///
@@ -25,27 +34,6 @@ declare_lint! {
25
34
/// The "intended" use of `IntoIterator` implementations for `Option` and `Result` is passing them to
26
35
/// generic code that expects something implementing `IntoIterator`. For example using `.chain(option)`
27
36
/// to optionally add a value to an iterator.
28
- ///
29
- /// ### Example
30
- ///
31
- /// ```rust
32
- /// # let opt = Some(1);
33
- /// # let res: Result<i32, std::io::Error> = Ok(1);
34
- /// # let recv = || None::<i32>;
35
- /// for x in opt { /* ... */}
36
- /// for x in res { /* ... */ }
37
- /// for x in recv() { /* ... */ }
38
- /// ```
39
- ///
40
- /// Use instead:
41
- /// ```rust
42
- /// # let opt = Some(1);
43
- /// # let res: Result<i32, std::io::Error> = Ok(1);
44
- /// # let recv = || None::<i32>;
45
- /// if let Some(x) = opt { /* ... */}
46
- /// if let Ok(x) = res { /* ... */ }
47
- /// while let Some(x) = recv() { /* ... */ }
48
- /// ```
49
37
pub FOR_LOOP_OVER_FALLIBLES ,
50
38
Warn ,
51
39
"for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`"
0 commit comments