From 71b8c89a5b467dda27ca29a91a17b8c933d5ce25 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 18 Aug 2022 11:43:10 +0400 Subject: [PATCH] fix `for_loop_over_fallibles` lint docs --- .../rustc_lint/src/for_loop_over_fallibles.rs | 32 ++++++------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_lint/src/for_loop_over_fallibles.rs b/compiler/rustc_lint/src/for_loop_over_fallibles.rs index 0a6b6e4163622..2253546b5d357 100644 --- a/compiler/rustc_lint/src/for_loop_over_fallibles.rs +++ b/compiler/rustc_lint/src/for_loop_over_fallibles.rs @@ -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 /// @@ -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 = Ok(1); - /// # let recv = || None::; - /// for x in opt { /* ... */} - /// for x in res { /* ... */ } - /// for x in recv() { /* ... */ } - /// ``` - /// - /// Use instead: - /// ```rust - /// # let opt = Some(1); - /// # let res: Result = Ok(1); - /// # let recv = || None::; - /// 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`"