Skip to content

Commit 5add651

Browse files
committed
Remove lints_enabled function
This function was redundant with the is_allowed function. Now is_allowed is used everywhere lints_enabled was used before.
1 parent 8da39e6 commit 5add651

File tree

6 files changed

+17
-38
lines changed

6 files changed

+17
-38
lines changed

clippy_lints/src/cargo_common_metadata.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
33
use std::path::PathBuf;
44

5-
use clippy_utils::diagnostics::span_lint;
6-
use clippy_utils::lints_enabled;
5+
use clippy_utils::{diagnostics::span_lint, is_allowed};
76
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
87
use rustc_lint::{LateContext, LateLintPass};
98
use rustc_session::{declare_tool_lint, impl_lint_pass};
@@ -85,7 +84,7 @@ fn is_empty_vec(value: &[String]) -> bool {
8584

8685
impl LateLintPass<'_> for CargoCommonMetadata {
8786
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
88-
if !lints_enabled(cx, &[CARGO_COMMON_METADATA], CRATE_HIR_ID) {
87+
if is_allowed(cx, CARGO_COMMON_METADATA, CRATE_HIR_ID) {
8988
return;
9089
}
9190

clippy_lints/src/copies.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_then};
22
use clippy_utils::source::{first_line_of_span, indent_of, reindent_multiline, snippet, snippet_opt};
33
use clippy_utils::{
4-
both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, is_else_clause,
5-
lints_enabled, search_same, ContainsName, SpanlessEq, SpanlessHash,
4+
both, count_eq, eq_expr_value, get_enclosing_block, get_parent_expr, if_sequence, in_macro, is_allowed,
5+
is_else_clause, search_same, ContainsName, SpanlessEq, SpanlessHash,
66
};
77
use if_chain::if_chain;
88
use rustc_data_structures::fx::FxHashSet;
@@ -337,8 +337,8 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option<
337337
if block_expr_eq;
338338
if l_stmts.len() == r_stmts.len();
339339
if l_stmts.len() == current_start_eq;
340-
if lints_enabled(cx, &[IF_SAME_THEN_ELSE], win[0].hir_id);
341-
if lints_enabled(cx, &[IF_SAME_THEN_ELSE], win[1].hir_id);
340+
if !is_allowed(cx, IF_SAME_THEN_ELSE, win[0].hir_id);
341+
if !is_allowed(cx, IF_SAME_THEN_ELSE, win[1].hir_id);
342342
then {
343343
span_lint_and_note(
344344
cx,

clippy_lints/src/multiple_crate_versions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! lint on multiple versions of a crate being used
22
33
use clippy_utils::diagnostics::span_lint;
4-
use clippy_utils::lints_enabled;
4+
use clippy_utils::is_allowed;
55
use rustc_hir::def_id::LOCAL_CRATE;
66
use rustc_hir::{Crate, CRATE_HIR_ID};
77
use rustc_lint::{LateContext, LateLintPass};
@@ -39,7 +39,7 @@ declare_lint_pass!(MultipleCrateVersions => [MULTIPLE_CRATE_VERSIONS]);
3939

4040
impl LateLintPass<'_> for MultipleCrateVersions {
4141
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
42-
if !lints_enabled(cx, &[MULTIPLE_CRATE_VERSIONS], CRATE_HIR_ID) {
42+
if is_allowed(cx, MULTIPLE_CRATE_VERSIONS, CRATE_HIR_ID) {
4343
return;
4444
}
4545

clippy_lints/src/utils/internal_lints.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sug
33
use clippy_utils::source::snippet;
44
use clippy_utils::ty::match_type;
55
use clippy_utils::{
6-
is_else_clause, is_expn_of, is_expr_path_def_path, lints_enabled, match_def_path, method_calls, path_to_res, paths,
6+
is_allowed, is_else_clause, is_expn_of, is_expr_path_def_path, match_def_path, method_calls, path_to_res, paths,
77
SpanlessEq,
88
};
99
use if_chain::if_chain;
@@ -353,7 +353,7 @@ impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]);
353353

354354
impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
355355
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
356-
if !lints_enabled(cx, &[DEFAULT_LINT], item.hir_id()) {
356+
if is_allowed(cx, DEFAULT_LINT, item.hir_id()) {
357357
return;
358358
}
359359

@@ -411,7 +411,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
411411
}
412412

413413
fn check_crate_post(&mut self, cx: &LateContext<'tcx>, _: &'tcx Crate<'_>) {
414-
if !lints_enabled(cx, &[LINT_WITHOUT_LINT_PASS], CRATE_HIR_ID) {
414+
if is_allowed(cx, LINT_WITHOUT_LINT_PASS, CRATE_HIR_ID) {
415415
return;
416416
}
417417

@@ -497,7 +497,7 @@ impl_lint_pass!(CompilerLintFunctions => [COMPILER_LINT_FUNCTIONS]);
497497

498498
impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions {
499499
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
500-
if !lints_enabled(cx, &[COMPILER_LINT_FUNCTIONS], expr.hir_id) {
500+
if is_allowed(cx, COMPILER_LINT_FUNCTIONS, expr.hir_id) {
501501
return;
502502
}
503503

@@ -526,7 +526,7 @@ declare_lint_pass!(OuterExpnDataPass => [OUTER_EXPN_EXPN_DATA]);
526526

527527
impl<'tcx> LateLintPass<'tcx> for OuterExpnDataPass {
528528
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
529-
if !lints_enabled(cx, &[OUTER_EXPN_EXPN_DATA], expr.hir_id) {
529+
if is_allowed(cx, OUTER_EXPN_EXPN_DATA, expr.hir_id) {
530530
return;
531531
}
532532

@@ -576,7 +576,7 @@ declare_lint_pass!(CollapsibleCalls => [COLLAPSIBLE_SPAN_LINT_CALLS]);
576576

577577
impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
578578
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
579-
if !lints_enabled(cx, &[COLLAPSIBLE_SPAN_LINT_CALLS], expr.hir_id) {
579+
if is_allowed(cx, COLLAPSIBLE_SPAN_LINT_CALLS, expr.hir_id) {
580580
return;
581581
}
582582

@@ -757,7 +757,7 @@ declare_lint_pass!(MatchTypeOnDiagItem => [MATCH_TYPE_ON_DIAGNOSTIC_ITEM]);
757757

758758
impl<'tcx> LateLintPass<'tcx> for MatchTypeOnDiagItem {
759759
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
760-
if !lints_enabled(cx, &[MATCH_TYPE_ON_DIAGNOSTIC_ITEM], expr.hir_id) {
760+
if is_allowed(cx, MATCH_TYPE_ON_DIAGNOSTIC_ITEM, expr.hir_id) {
761761
return;
762762
}
763763

clippy_lints/src/wildcard_dependencies.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint;
2-
use clippy_utils::lints_enabled;
1+
use clippy_utils::{diagnostics::span_lint, is_allowed};
32
use rustc_hir::{hir_id::CRATE_HIR_ID, Crate};
43
use rustc_lint::{LateContext, LateLintPass};
54
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -31,7 +30,7 @@ declare_lint_pass!(WildcardDependencies => [WILDCARD_DEPENDENCIES]);
3130

3231
impl LateLintPass<'_> for WildcardDependencies {
3332
fn check_crate(&mut self, cx: &LateContext<'_>, _: &Crate<'_>) {
34-
if !lints_enabled(cx, &[WILDCARD_DEPENDENCIES], CRATE_HIR_ID) {
33+
if is_allowed(cx, WILDCARD_DEPENDENCIES, CRATE_HIR_ID) {
3534
return;
3635
}
3736

clippy_utils/src/lib.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,25 +1541,6 @@ pub fn fn_def_id(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<DefId> {
15411541
}
15421542
}
15431543

1544-
/// This function checks if any of the lints in the slice is enabled for the provided `HirId`.
1545-
/// A lint counts as enabled with any of the levels: `Level::Forbid` | `Level::Deny` | `Level::Warn`
1546-
///
1547-
/// ```ignore
1548-
/// #[deny(clippy::YOUR_AWESOME_LINT)]
1549-
/// println!("Hello, World!"); // <- Clippy code: lints_enabled(cx, &[YOUR_AWESOME_LINT], id) == true
1550-
///
1551-
/// #[allow(clippy::YOUR_AWESOME_LINT)]
1552-
/// println!("See you soon!"); // <- Clippy code: lints_enabled(cx, &[YOUR_AWESOME_LINT], id) == false
1553-
/// ```
1554-
pub fn lints_enabled(cx: &LateContext<'_>, lints: &[&'static Lint], id: HirId) -> bool {
1555-
lints.iter().any(|lint| {
1556-
matches!(
1557-
cx.tcx.lint_level_at_node(lint, id),
1558-
(Level::Forbid | Level::Deny | Level::Warn, _)
1559-
)
1560-
})
1561-
}
1562-
15631544
/// Returns Option<String> where String is a textual representation of the type encapsulated in the
15641545
/// slice iff the given expression is a slice of primitives (as defined in the
15651546
/// `is_recursively_primitive_type` function) and None otherwise.

0 commit comments

Comments
 (0)