Skip to content

Commit 02ceeb5

Browse files
committed
Use in_constant instead of is_const
1 parent aa5f1f9 commit 02ceeb5

File tree

1 file changed

+6
-29
lines changed

1 file changed

+6
-29
lines changed

clippy_lints/src/manual_unwrap_or.rs

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use crate::consts::constant_simple;
22
use crate::utils;
3-
use crate::utils::{path_to_local_id, sugg};
3+
use crate::utils::{in_constant, path_to_local_id, sugg};
44
use clippy_utils::diagnostics::span_lint_and_sugg;
55
use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt};
66
use clippy_utils::ty::is_type_diagnostic_item;
77
use if_chain::if_chain;
88
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};
1010
use rustc_lint::LintContext;
1111
use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::lint::in_external_macro;
1313
use rustc_session::{declare_lint_pass, declare_tool_lint};
14-
use rustc_span::{source_map::Span, sym};
14+
use rustc_span::sym;
1515

1616
declare_clippy_lint! {
1717
/// **What it does:**
@@ -44,34 +44,11 @@ declare_clippy_lint! {
4444
declare_lint_pass!(ManualUnwrapOr => [MANUAL_UNWRAP_OR]);
4545

4646
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) {
5749
return;
5850
}
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);
7552
}
7653
}
7754

0 commit comments

Comments
 (0)