|
1 | 1 | use crate::consts::constant_simple;
|
2 | 2 | use crate::utils;
|
3 |
| -use crate::utils::{path_to_local_id, sugg}; |
| 3 | +use crate::utils::{in_constant, path_to_local_id, sugg}; |
4 | 4 | use clippy_utils::diagnostics::span_lint_and_sugg;
|
5 | 5 | use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt};
|
6 | 6 | use clippy_utils::ty::is_type_diagnostic_item;
|
7 | 7 | use if_chain::if_chain;
|
8 | 8 | use rustc_errors::Applicability;
|
9 |
| -use rustc_hir::{hir_id::HirId, intravisit::FnKind, Arm, Body, Expr, ExprKind, FnDecl, Pat, PatKind, StmtKind}; |
| 9 | +use rustc_hir::{Arm, Expr, ExprKind, Pat, PatKind}; |
10 | 10 | use rustc_lint::LintContext;
|
11 | 11 | use rustc_lint::{LateContext, LateLintPass};
|
12 | 12 | use rustc_middle::lint::in_external_macro;
|
13 | 13 | use rustc_session::{declare_lint_pass, declare_tool_lint};
|
14 |
| -use rustc_span::{source_map::Span, sym}; |
| 14 | +use rustc_span::sym; |
15 | 15 |
|
16 | 16 | declare_clippy_lint! {
|
17 | 17 | /// **What it does:**
|
@@ -44,34 +44,11 @@ declare_clippy_lint! {
|
44 | 44 | declare_lint_pass!(ManualUnwrapOr => [MANUAL_UNWRAP_OR]);
|
45 | 45 |
|
46 | 46 | impl LateLintPass<'_> for ManualUnwrapOr {
|
47 |
| - fn check_fn( |
48 |
| - &mut self, |
49 |
| - cx: &LateContext<'tcx>, |
50 |
| - kind: FnKind<'tcx>, |
51 |
| - _: &'tcx FnDecl<'tcx>, |
52 |
| - body: &'tcx Body<'tcx>, |
53 |
| - span: Span, |
54 |
| - _: HirId, |
55 |
| - ) { |
56 |
| - if in_external_macro(cx.sess(), span) { |
| 47 | + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { |
| 48 | + if in_external_macro(cx.sess(), expr.span) || in_constant(cx, expr.hir_id) { |
57 | 49 | return;
|
58 | 50 | }
|
59 |
| - if_chain! { |
60 |
| - if let FnKind::ItemFn(_, _, header, _) = kind; |
61 |
| - if !header.is_const(); |
62 |
| - let expr = &body.value; |
63 |
| - if let ExprKind::Block(block, _) = expr.kind; |
64 |
| - then { |
65 |
| - for stmt in block.stmts { |
66 |
| - if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = &stmt.kind { |
67 |
| - lint_manual_unwrap_or(cx, expr); |
68 |
| - } |
69 |
| - } |
70 |
| - if let Some(expr) = block.expr { |
71 |
| - lint_manual_unwrap_or(cx, expr); |
72 |
| - } |
73 |
| - } |
74 |
| - } |
| 51 | + lint_manual_unwrap_or(cx, expr); |
75 | 52 | }
|
76 | 53 | }
|
77 | 54 |
|
|
0 commit comments