mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 17:07:17 +00:00
Remove lints_enabled function
This function was redundant with the is_allowed function. Now is_allowed is used everywhere lints_enabled was used before.
This commit is contained in:
parent
8da39e66ac
commit
5add651223
6 changed files with 17 additions and 38 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1541,25 +1541,6 @@ pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<DefId> {
|
|||
}
|
||||
}
|
||||
|
||||
/// 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<String> 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.
|
||||
|
|
Loading…
Reference in a new issue