@@ -64,6 +64,8 @@ declare_clippy_lint! {
6464 /// y*y
6565 /// }, |foo| foo);
6666 /// ```
67+ // FIXME: Before moving this lint out of nursery, the lint name needs to be updated. It now also
68+ // covers matches and `Result`.
6769 #[ clippy:: version = "1.47.0" ]
6870 pub OPTION_IF_LET_ELSE ,
6971 nursery,
@@ -235,24 +237,25 @@ fn is_none_or_err_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
235237
236238impl < ' tcx > LateLintPass < ' tcx > for OptionIfLetElse {
237239 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & Expr < ' tcx > ) {
238- // Don't lint macros, because it behaves weirdly
239- // and don't lint constant as well
240- if !expr. span . from_expansion ( ) && !in_constant ( cx, expr. hir_id ) {
241- let detection = detect_option_if_let_else ( cx, expr) . or_else ( || detect_option_match ( cx, expr) ) ;
242- if let Some ( det) = detection {
243- span_lint_and_sugg (
244- cx,
245- OPTION_IF_LET_ELSE ,
246- expr. span ,
247- format ! ( "use Option::{} instead of an if let/else" , det. method_sugg) . as_str ( ) ,
248- "try" ,
249- format ! (
250- "{}.{}({}, {})" ,
251- det. option, det. method_sugg, det. none_expr, det. some_expr
252- ) ,
253- Applicability :: MaybeIncorrect ,
254- ) ;
255- }
240+ // Don't lint macros and constants
241+ if expr. span . from_expansion ( ) || in_constant ( cx, expr. hir_id ) {
242+ return ;
243+ }
244+
245+ let detection = detect_option_if_let_else ( cx, expr) . or_else ( || detect_option_match ( cx, expr) ) ;
246+ if let Some ( det) = detection {
247+ span_lint_and_sugg (
248+ cx,
249+ OPTION_IF_LET_ELSE ,
250+ expr. span ,
251+ format ! ( "use Option::{} instead of an if let/else" , det. method_sugg) . as_str ( ) ,
252+ "try" ,
253+ format ! (
254+ "{}.{}({}, {})" ,
255+ det. option, det. method_sugg, det. none_expr, det. some_expr
256+ ) ,
257+ Applicability :: MaybeIncorrect ,
258+ ) ;
256259 }
257260 }
258261}
0 commit comments