Skip to content

Commit

Permalink
fix for_loop_over_fallibles lint docs
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Aug 18, 2022
1 parent aed1ae4 commit 71b8c89
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions compiler/rustc_lint/src/for_loop_over_fallibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ use rustc_span::{sym, Span};
use rustc_trait_selection::traits::TraitEngineExt;

declare_lint! {
/// Checks for `for` loops over `Option` or `Result` values.
/// The `for_loop_over_fallibles` lint checks for `for` loops over `Option` or `Result` values.
///
/// ### Example
///
/// ```rust
/// let opt = Some(1);
/// for x in opt { /* ... */}
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
Expand All @@ -25,27 +34,6 @@ declare_lint! {
/// The "intended" use of `IntoIterator` implementations for `Option` and `Result` is passing them to
/// generic code that expects something implementing `IntoIterator`. For example using `.chain(option)`
/// to optionally add a value to an iterator.
///
/// ### Example
///
/// ```rust
/// # let opt = Some(1);
/// # let res: Result<i32, std::io::Error> = Ok(1);
/// # let recv = || None::<i32>;
/// for x in opt { /* ... */}
/// for x in res { /* ... */ }
/// for x in recv() { /* ... */ }
/// ```
///
/// Use instead:
/// ```rust
/// # let opt = Some(1);
/// # let res: Result<i32, std::io::Error> = Ok(1);
/// # let recv = || None::<i32>;
/// if let Some(x) = opt { /* ... */}
/// if let Ok(x) = res { /* ... */ }
/// while let Some(x) = recv() { /* ... */ }
/// ```
pub FOR_LOOP_OVER_FALLIBLES,
Warn,
"for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`"
Expand Down

0 comments on commit 71b8c89

Please sign in to comment.