From 5add651223a8d3ba8e2efccf942f9013d2f270a1 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 9 Jul 2021 15:00:24 +0200 Subject: [PATCH 1/2] Remove lints_enabled function This function was redundant with the is_allowed function. Now is_allowed is used everywhere lints_enabled was used before. --- clippy_lints/src/cargo_common_metadata.rs | 5 ++--- clippy_lints/src/copies.rs | 8 ++++---- clippy_lints/src/multiple_crate_versions.rs | 4 ++-- clippy_lints/src/utils/internal_lints.rs | 14 +++++++------- clippy_lints/src/wildcard_dependencies.rs | 5 ++--- clippy_utils/src/lib.rs | 19 ------------------- 6 files changed, 17 insertions(+), 38 deletions(-) diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index a84d1d5d9..edb60bc9b 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -2,8 +2,7 @@ use std::path::PathBuf; -use clippy_utils::diagnostics::span_lint; -use clippy_utils::lints_enabled; +use clippy_utils::{diagnostics::span_lint, is_allowed}; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -85,7 +84,7 @@ fn is_empty_vec(value: &[String]) -> bool { impl LateLintPass<'_> for CargoCommonMetadata { fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { - if !lints_enabled(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) { + if is_allowed(cx, CARGO_COMMON_METADATA, CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 91e0f2a55..7a0edfca4 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then}; use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt}; use clippy_utils::{ - both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, is_else_clause, - lints_enabled, search_same, ContainsName, SpanlessEq, SpanlessHash, + both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, is_allowed, + is_else_clause, search_same, ContainsName, SpanlessEq, SpanlessHash, }; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; @@ -337,8 +337,8 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option< if block_expr_eq; if l_stmts.len() == r_stmts.len(); if l_stmts.len() == current_start_eq; - if lints_enabled(cx, &[IF_SAME_THEN_ELSE], win[0].hir_id); - if lints_enabled(cx, &[IF_SAME_THEN_ELSE], win[1].hir_id); + if !is_allowed(cx, IF_SAME_THEN_ELSE, win[0].hir_id); + if !is_allowed(cx, IF_SAME_THEN_ELSE, win[1].hir_id); then { span_lint_and_note( cx, diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 1eba7c124..6a50c9709 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -1,7 +1,7 @@ //! lint on multiple versions of a crate being used use clippy_utils::diagnostics::span_lint; -use clippy_utils::lints_enabled; +use clippy_utils::is_allowed; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::{Crate, CRATE_HIR_ID}; use rustc_lint::{LateContext, LateLintPass}; @@ -39,7 +39,7 @@ declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]); impl LateLintPass<'_> for MultipleCrateVersions { fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { - if !lints_enabled(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) { + if is_allowed(cx, MULTIPLE_CRATE_VERSIONS, CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index e8b14ee8e..cbaacddd8 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sug use clippy_utils::source::snippet; use clippy_utils::ty::match_type; use clippy_utils::{ - is_else_clause, is_expn_of, is_expr_path_def_path, lints_enabled, match_def_path, method_calls, path_to_res, paths, + is_allowed, is_else_clause, is_expn_of, is_expr_path_def_path, match_def_path, method_calls, path_to_res, paths, SpanlessEq, }; use if_chain::if_chain; @@ -353,7 +353,7 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]); impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if !lints_enabled(cx, &[DEFAULT_LINT], item.hir_id()) { + if is_allowed(cx, DEFAULT_LINT, item.hir_id()) { return; } @@ -411,7 +411,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { } fn check_crate_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx Crate<'_>) { - if !lints_enabled(cx, &[LINT_WITHOUT_LINT_PASS], CRATE_HIR_ID) { + if is_allowed(cx, LINT_WITHOUT_LINT_PASS, CRATE_HIR_ID) { return; } @@ -497,7 +497,7 @@ impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]); impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if !lints_enabled(cx, &[COMPILER_LINT_FUNCTIONS], expr.hir_id) { + if is_allowed(cx, COMPILER_LINT_FUNCTIONS, expr.hir_id) { return; } @@ -526,7 +526,7 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]); impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if !lints_enabled(cx, &[OUTER_EXPN_EXPN_DATA], expr.hir_id) { + if is_allowed(cx, OUTER_EXPN_EXPN_DATA, expr.hir_id) { return; } @@ -576,7 +576,7 @@ declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]); impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if !lints_enabled(cx, &[COLLAPSIBLE_SPAN_LINT_CALLS], expr.hir_id) { + if is_allowed(cx, COLLAPSIBLE_SPAN_LINT_CALLS, expr.hir_id) { return; } @@ -757,7 +757,7 @@ declare_lint_pass!(MatchTypeOnDiagItem => [MATCH_TYPE_ON_DIAGNOSTIC_ITEM]); impl<'tcx> LateLintPass<'tcx> for MatchTypeOnDiagItem { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if !lints_enabled(cx, &[MATCH_TYPE_ON_DIAGNOSTIC_ITEM], expr.hir_id) { + if is_allowed(cx, MATCH_TYPE_ON_DIAGNOSTIC_ITEM, expr.hir_id) { return; } diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index fe74698d7..df5127b00 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -1,5 +1,4 @@ -use clippy_utils::diagnostics::span_lint; -use clippy_utils::lints_enabled; +use clippy_utils::{diagnostics::span_lint, is_allowed}; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -31,7 +30,7 @@ declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]); impl LateLintPass<'_> for WildcardDependencies { fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { - if !lints_enabled(cx, &[WILDCARD_DEPENDENCIES], CRATE_HIR_ID) { + if is_allowed(cx, WILDCARD_DEPENDENCIES, CRATE_HIR_ID) { return; } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 9f09027aa..121ca2da5 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1541,25 +1541,6 @@ pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { } } -/// This function checks if any of the lints in the slice is enabled for the provided `HirId`. -/// A lint counts as enabled with any of the levels: `Level::Forbid` | `Level::Deny` | `Level::Warn` -/// -/// ```ignore -/// #[deny(clippy::YOUR_AWESOME_LINT)] -/// println!("Hello, World!"); // <- Clippy code: lints_enabled(cx, &[YOUR_AWESOME_LINT], id) == true -/// -/// #[allow(clippy::YOUR_AWESOME_LINT)] -/// println!("See you soon!"); // <- Clippy code: lints_enabled(cx, &[YOUR_AWESOME_LINT], id) == false -/// ``` -pub fn lints_enabled(cx: &LateContext<'_>, lints: &[&'static Lint], id: HirId) -> bool { - lints.iter().any(|lint| { - matches!( - cx.tcx.lint_level_at_node(lint, id), - (Level::Forbid | Level::Deny | Level::Warn, _) - ) - }) -} - /// Returns Option where String is a textual representation of the type encapsulated in the /// slice iff the given expression is a slice of primitives (as defined in the /// `is_recursively_primitive_type` function) and None otherwise. From d2c8f50bbed32a6bcec5f397043342c980e945b3 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 9 Jul 2021 15:06:12 +0200 Subject: [PATCH 2/2] Rename `is_allowed` -> `is_lint_allowed` --- clippy_lints/src/cargo_common_metadata.rs | 4 ++-- clippy_lints/src/copies.rs | 8 ++++---- clippy_lints/src/dereference.rs | 4 ++-- clippy_lints/src/derive.rs | 4 ++-- clippy_lints/src/inherent_impl.rs | 6 +++--- clippy_lints/src/len_zero.rs | 4 ++-- clippy_lints/src/manual_map.rs | 6 +++--- clippy_lints/src/matches.rs | 4 ++-- clippy_lints/src/multiple_crate_versions.rs | 4 ++-- clippy_lints/src/ptr.rs | 4 ++-- clippy_lints/src/strings.rs | 4 ++-- clippy_lints/src/unicode.rs | 6 +++--- clippy_lints/src/utils/internal_lints.rs | 16 ++++++++-------- clippy_lints/src/wildcard_dependencies.rs | 4 ++-- clippy_utils/src/lib.rs | 2 +- 15 files changed, 40 insertions(+), 40 deletions(-) diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index edb60bc9b..21c7b2448 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; -use clippy_utils::{diagnostics::span_lint, is_allowed}; +use clippy_utils::{diagnostics::span_lint, is_lint_allowed}; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; @@ -84,7 +84,7 @@ fn is_empty_vec(value: &[String]) -> bool { impl LateLintPass<'_> for CargoCommonMetadata { fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { - if is_allowed(cx, CARGO_COMMON_METADATA, CRATE_HIR_ID) { + if is_lint_allowed(cx, CARGO_COMMON_METADATA, CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 7a0edfca4..aea1acccc 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -1,8 +1,8 @@ use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then}; use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt}; use clippy_utils::{ - both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, is_allowed, - is_else_clause, search_same, ContainsName, SpanlessEq, SpanlessHash, + both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, is_else_clause, + is_lint_allowed, search_same, ContainsName, SpanlessEq, SpanlessHash, }; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; @@ -337,8 +337,8 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option< if block_expr_eq; if l_stmts.len() == r_stmts.len(); if l_stmts.len() == current_start_eq; - if !is_allowed(cx, IF_SAME_THEN_ELSE, win[0].hir_id); - if !is_allowed(cx, IF_SAME_THEN_ELSE, win[1].hir_id); + if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, win[0].hir_id); + if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, win[1].hir_id); then { span_lint_and_note( cx, diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 1415f8e23..682003f9c 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_context; use clippy_utils::ty::peel_mid_ty_refs; -use clippy_utils::{get_parent_node, in_macro, is_allowed}; +use clippy_utils::{get_parent_node, in_macro, is_lint_allowed}; use rustc_ast::util::parser::PREC_PREFIX; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, MatchSource, Mutability, Node, UnOp}; @@ -107,7 +107,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing { match kind { RefOp::Method(target_mut) - if !is_allowed(cx, EXPLICIT_DEREF_METHODS, expr.hir_id) + if !is_lint_allowed(cx, EXPLICIT_DEREF_METHODS, expr.hir_id) && is_linted_explicit_deref_position(parent, expr.hir_id, expr.span) => { self.state = Some(( diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index 3ac20fd98..7aafaf713 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_then}; use clippy_utils::paths; use clippy_utils::ty::{implements_trait, is_copy}; -use clippy_utils::{get_trait_def_id, is_allowed, is_automatically_derived, match_def_path}; +use clippy_utils::{get_trait_def_id, is_automatically_derived, is_lint_allowed, match_def_path}; use if_chain::if_chain; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor}; @@ -362,7 +362,7 @@ fn check_unsafe_derive_deserialize<'tcx>( if let ty::Adt(def, _) = ty.kind(); if let Some(local_def_id) = def.did.as_local(); let adt_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id); - if !is_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id); + if !is_lint_allowed(cx, UNSAFE_DERIVE_DESERIALIZE, adt_hir_id); if cx.tcx.inherent_impls(def.did) .iter() .map(|imp_did| item_from_def_id(cx, *imp_did)) diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index ee41c4aea..9641784eb 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -1,7 +1,7 @@ //! lint on inherent implementations use clippy_utils::diagnostics::span_lint_and_note; -use clippy_utils::{in_macro, is_allowed}; +use clippy_utils::{in_macro, is_lint_allowed}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::{def_id::LocalDefId, Crate, Item, ItemKind, Node}; use rustc_lint::{LateContext, LateLintPass}; @@ -59,7 +59,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { .filter(|(&id, impls)| { impls.len() > 1 // Check for `#[allow]` on the type definition - && !is_allowed( + && !is_lint_allowed( cx, MULTIPLE_INHERENT_IMPL, cx.tcx.hir().local_def_id_to_hir_id(id), @@ -123,7 +123,7 @@ fn get_impl_span(cx: &LateContext<'_>, id: LocalDefId) -> Option { .. }) = cx.tcx.hir().get(id) { - (!in_macro(span) && impl_item.generics.params.is_empty() && !is_allowed(cx, MULTIPLE_INHERENT_IMPL, id)) + (!in_macro(span) && impl_item.generics.params.is_empty() && !is_lint_allowed(cx, MULTIPLE_INHERENT_IMPL, id)) .then(|| span) } else { None diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index d69187f67..892b3af0b 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::{get_item_name, get_parent_as_impl, is_allowed}; +use clippy_utils::{get_item_name, get_parent_as_impl, is_lint_allowed}; use if_chain::if_chain; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; @@ -139,7 +139,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero { if let Some(ty_id) = cx.qpath_res(ty_path, imp.self_ty.hir_id).opt_def_id(); if let Some(local_id) = ty_id.as_local(); let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id); - if !is_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id); + if !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id); if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.def_id).skip_binder()); then { let (name, kind) = match cx.tcx.hir().find(ty_hir_id) { diff --git a/clippy_lints/src/manual_map.rs b/clippy_lints/src/manual_map.rs index 97e4a983f..563d5cdb5 100644 --- a/clippy_lints/src/manual_map.rs +++ b/clippy_lints/src/manual_map.rs @@ -3,7 +3,7 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::{snippet_with_applicability, snippet_with_context}; use clippy_utils::ty::{is_type_diagnostic_item, peel_mid_ty_refs_is_mutable}; use clippy_utils::{ - can_move_expr_to_closure, in_constant, is_allowed, is_else_clause, is_lang_ctor, path_to_local_id, + can_move_expr_to_closure, in_constant, is_else_clause, is_lang_ctor, is_lint_allowed, path_to_local_id, peel_hir_expr_refs, }; use rustc_ast::util::parser::PREC_POSTFIX; @@ -102,7 +102,7 @@ impl LateLintPass<'_> for ManualMap { // These two lints will go back and forth with each other. if cx.typeck_results().expr_ty(some_expr) == cx.tcx.types.unit - && !is_allowed(cx, OPTION_MAP_UNIT_FN, expr.hir_id) + && !is_lint_allowed(cx, OPTION_MAP_UNIT_FN, expr.hir_id) { return; } @@ -146,7 +146,7 @@ impl LateLintPass<'_> for ManualMap { }, _ => { if path_to_local_id(some_expr, id) - && !is_allowed(cx, MATCH_AS_REF, expr.hir_id) + && !is_lint_allowed(cx, MATCH_AS_REF, expr.hir_id) && binding_ref.is_some() { return; diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index f1e3492c4..986469a2b 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -7,7 +7,7 @@ use clippy_utils::sugg::Sugg; use clippy_utils::ty::{implements_trait, is_type_diagnostic_item, match_type, peel_mid_ty_refs}; use clippy_utils::visitors::LocalUsedVisitor; use clippy_utils::{ - get_parent_expr, in_macro, is_allowed, is_expn_of, is_lang_ctor, is_refutable, is_wild, meets_msrv, msrvs, + get_parent_expr, in_macro, is_expn_of, is_lang_ctor, is_lint_allowed, is_refutable, is_wild, meets_msrv, msrvs, path_to_local, path_to_local_id, peel_hir_pat_refs, peel_n_hir_expr_refs, recurse_or_patterns, remove_blocks, strip_pat_refs, }; @@ -707,7 +707,7 @@ fn check_single_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], exp }; let ty = cx.typeck_results().expr_ty(ex); - if *ty.kind() != ty::Bool || is_allowed(cx, MATCH_BOOL, ex.hir_id) { + if *ty.kind() != ty::Bool || is_lint_allowed(cx, MATCH_BOOL, ex.hir_id) { check_single_match_single_pattern(cx, ex, arms, expr, els); check_single_match_opt_like(cx, ex, arms, expr, ty, els); } diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index 6a50c9709..f5ce3e325 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -1,7 +1,7 @@ //! lint on multiple versions of a crate being used use clippy_utils::diagnostics::span_lint; -use clippy_utils::is_allowed; +use clippy_utils::is_lint_allowed; use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::{Crate, CRATE_HIR_ID}; use rustc_lint::{LateContext, LateLintPass}; @@ -39,7 +39,7 @@ declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]); impl LateLintPass<'_> for MultipleCrateVersions { fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { - if is_allowed(cx, MULTIPLE_CRATE_VERSIONS, CRATE_HIR_ID) { + if is_lint_allowed(cx, MULTIPLE_CRATE_VERSIONS, CRATE_HIR_ID) { return; } diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 12c444368..dba3b1805 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -4,7 +4,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_the use clippy_utils::ptr::get_spans; use clippy_utils::source::snippet_opt; use clippy_utils::ty::{is_type_diagnostic_item, match_type, walk_ptrs_hir_ty}; -use clippy_utils::{expr_path_res, is_allowed, match_any_def_paths, paths}; +use clippy_utils::{expr_path_res, is_lint_allowed, match_any_def_paths, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ @@ -246,7 +246,7 @@ fn check_fn(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_id: HirId, opt_body_id: for (idx, (arg, ty)) in decl.inputs.iter().zip(fn_ty.inputs()).enumerate() { // Honor the allow attribute on parameters. See issue 5644. if let Some(body) = &body { - if is_allowed(cx, PTR_ARG, body.params[idx].hir_id) { + if is_lint_allowed(cx, PTR_ARG, body.params[idx].hir_id) { continue; } } diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index 9d91b53e1..958e46212 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sug use clippy_utils::source::{snippet, snippet_with_applicability}; use clippy_utils::ty::is_type_diagnostic_item; use clippy_utils::SpanlessEq; -use clippy_utils::{get_parent_expr, is_allowed, match_function_call, method_calls, paths}; +use clippy_utils::{get_parent_expr, is_lint_allowed, match_function_call, method_calls, paths}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, LangItem, QPath}; @@ -124,7 +124,7 @@ impl<'tcx> LateLintPass<'tcx> for StringAdd { ) = e.kind { if is_string(cx, left) { - if !is_allowed(cx, STRING_ADD_ASSIGN, e.hir_id) { + if !is_lint_allowed(cx, STRING_ADD_ASSIGN, e.hir_id) { let parent = get_parent_expr(cx, e); if let Some(p) = parent { if let ExprKind::Assign(target, _, _) = p.kind { diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index 45291a120..2f0a61898 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -1,5 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_sugg; -use clippy_utils::is_allowed; +use clippy_utils::is_lint_allowed; use clippy_utils::source::snippet; use rustc_ast::ast::LitKind; use rustc_errors::Applicability; @@ -114,7 +114,7 @@ fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) { span, "literal non-ASCII character detected", "consider replacing the string with", - if is_allowed(cx, UNICODE_NOT_NFC, id) { + if is_lint_allowed(cx, UNICODE_NOT_NFC, id) { escape(string.chars()) } else { escape(string.nfc()) @@ -122,7 +122,7 @@ fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) { Applicability::MachineApplicable, ); } - if is_allowed(cx, NON_ASCII_LITERAL, id) && string.chars().zip(string.nfc()).any(|(a, b)| a != b) { + if is_lint_allowed(cx, NON_ASCII_LITERAL, id) && string.chars().zip(string.nfc()).any(|(a, b)| a != b) { span_lint_and_sugg( cx, UNICODE_NOT_NFC, diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index cbaacddd8..668807f49 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -3,8 +3,8 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sug use clippy_utils::source::snippet; use clippy_utils::ty::match_type; use clippy_utils::{ - is_allowed, is_else_clause, is_expn_of, is_expr_path_def_path, match_def_path, method_calls, path_to_res, paths, - SpanlessEq, + is_else_clause, is_expn_of, is_expr_path_def_path, is_lint_allowed, match_def_path, method_calls, path_to_res, + paths, SpanlessEq, }; use if_chain::if_chain; use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, ModKind, NodeId}; @@ -353,7 +353,7 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]); impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { - if is_allowed(cx, DEFAULT_LINT, item.hir_id()) { + if is_lint_allowed(cx, DEFAULT_LINT, item.hir_id()) { return; } @@ -411,7 +411,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass { } fn check_crate_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx Crate<'_>) { - if is_allowed(cx, LINT_WITHOUT_LINT_PASS, CRATE_HIR_ID) { + if is_lint_allowed(cx, LINT_WITHOUT_LINT_PASS, CRATE_HIR_ID) { return; } @@ -497,7 +497,7 @@ impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]); impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { - if is_allowed(cx, COMPILER_LINT_FUNCTIONS, expr.hir_id) { + if is_lint_allowed(cx, COMPILER_LINT_FUNCTIONS, expr.hir_id) { return; } @@ -526,7 +526,7 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]); impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if is_allowed(cx, OUTER_EXPN_EXPN_DATA, expr.hir_id) { + if is_lint_allowed(cx, OUTER_EXPN_EXPN_DATA, expr.hir_id) { return; } @@ -576,7 +576,7 @@ declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]); impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if is_allowed(cx, COLLAPSIBLE_SPAN_LINT_CALLS, expr.hir_id) { + if is_lint_allowed(cx, COLLAPSIBLE_SPAN_LINT_CALLS, expr.hir_id) { return; } @@ -757,7 +757,7 @@ declare_lint_pass!(MatchTypeOnDiagItem => [MATCH_TYPE_ON_DIAGNOSTIC_ITEM]); impl<'tcx> LateLintPass<'tcx> for MatchTypeOnDiagItem { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { - if is_allowed(cx, MATCH_TYPE_ON_DIAGNOSTIC_ITEM, expr.hir_id) { + if is_lint_allowed(cx, MATCH_TYPE_ON_DIAGNOSTIC_ITEM, expr.hir_id) { return; } diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index df5127b00..1ca1117a4 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -1,4 +1,4 @@ -use clippy_utils::{diagnostics::span_lint, is_allowed}; +use clippy_utils::{diagnostics::span_lint, is_lint_allowed}; use rustc_hir::{hir_id::CRATE_HIR_ID, Crate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; @@ -30,7 +30,7 @@ declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]); impl LateLintPass<'_> for WildcardDependencies { fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) { - if is_allowed(cx, WILDCARD_DEPENDENCIES, CRATE_HIR_ID) { + if is_lint_allowed(cx, WILDCARD_DEPENDENCIES, CRATE_HIR_ID) { return; } diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 121ca2da5..364ae536e 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1173,7 +1173,7 @@ pub fn is_try<'tcx>(cx: &LateContext<'_>, expr: &'tcx Expr<'tcx>) -> Option<&'tc /// Returns `true` if the lint is allowed in the current context /// /// Useful for skipping long running code when it's unnecessary -pub fn is_allowed(cx: &LateContext<'_>, lint: &'static Lint, id: HirId) -> bool { +pub fn is_lint_allowed(cx: &LateContext<'_>, lint: &'static Lint, id: HirId) -> bool { cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow }