@@ -10,7 +10,16 @@ use rustc_span::{sym, Span};
1010use rustc_trait_selection:: traits:: TraitEngineExt ;
1111
1212declare_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}}
1423 ///
1524 /// ### Explanation
1625 ///
@@ -25,27 +34,6 @@ declare_lint! {
2534 /// The "intended" use of `IntoIterator` implementations for `Option` and `Result` is passing them to
2635 /// generic code that expects something implementing `IntoIterator`. For example using `.chain(option)`
2736 /// 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- /// ```
4937 pub FOR_LOOP_OVER_FALLIBLES ,
5038 Warn ,
5139 "for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`"
0 commit comments