mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Use in_constant instead of is_const
This commit is contained in:
parent
aa5f1f9078
commit
02ceeb59d4
@ -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:**
|
||||
@ -44,36 +44,13 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum Case {
|
||||
|
Loading…
Reference in New Issue
Block a user