@@ -64,6 +64,8 @@ declare_clippy_lint! {
64
64
/// y*y
65
65
/// }, |foo| foo);
66
66
/// ```
67
+ // FIXME: Before moving this lint out of nursery, the lint name needs to be updated. It now also
68
+ // covers matches and `Result`.
67
69
#[ clippy:: version = "1.47.0" ]
68
70
pub OPTION_IF_LET_ELSE ,
69
71
nursery,
@@ -235,24 +237,25 @@ fn is_none_or_err_arm(cx: &LateContext<'_>, arm: &Arm<'_>) -> bool {
235
237
236
238
impl < ' tcx > LateLintPass < ' tcx > for OptionIfLetElse {
237
239
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
+ ) ;
256
259
}
257
260
}
258
261
}
0 commit comments