Skip to content

Commit

Permalink
Use in_constant instead of is_const
Browse files Browse the repository at this point in the history
  • Loading branch information
MysteryJump committed Mar 16, 2021
1 parent aa5f1f9 commit 02ceeb5
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions clippy_lints/src/manual_unwrap_or.rs
@@ -1,17 +1,17 @@
use crate::consts::constant_simple;
use crate::utils;
use crate::utils::{path_to_local_id, sugg};
use crate::utils::{in_constant, path_to_local_id, sugg};
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::{indent_of, reindent_multiline, snippet_opt};
use clippy_utils::ty::is_type_diagnostic_item;
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{hir_id::HirId, intravisit::FnKind, Arm, Body, Expr, ExprKind, FnDecl, Pat, PatKind, StmtKind};
use rustc_hir::{Arm, Expr, ExprKind, Pat, PatKind};
use rustc_lint::LintContext;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{source_map::Span, sym};
use rustc_span::sym;

declare_clippy_lint! {
/// **What it does:**
Expand Down Expand Up @@ -44,34 +44,11 @@ declare_clippy_lint! {
declare_lint_pass!(ManualUnwrapOr => [MANUAL_UNWRAP_OR]);

impl LateLintPass<'_> for ManualUnwrapOr {
fn check_fn(
&mut self,
cx: &LateContext<'tcx>,
kind: FnKind<'tcx>,
_: &'tcx FnDecl<'tcx>,
body: &'tcx Body<'tcx>,
span: Span,
_: HirId,
) {
if in_external_macro(cx.sess(), span) {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if in_external_macro(cx.sess(), expr.span) || in_constant(cx, expr.hir_id) {
return;
}
if_chain! {
if let FnKind::ItemFn(_, _, header, _) = kind;
if !header.is_const();
let expr = &body.value;
if let ExprKind::Block(block, _) = expr.kind;
then {
for stmt in block.stmts {
if let StmtKind::Expr(expr) | StmtKind::Semi(expr) = &stmt.kind {
lint_manual_unwrap_or(cx, expr);
}
}
if let Some(expr) = block.expr {
lint_manual_unwrap_or(cx, expr);
}
}
}
lint_manual_unwrap_or(cx, expr);
}
}

Expand Down

0 comments on commit 02ceeb5

Please sign in to comment.