diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index b4aa9759f06..c1c58eecbb6 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -1029,7 +1029,7 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id: } } - if !is_crate_node { + if self.lint_added_lints && !is_crate_node { for (id, &(level, ref src)) in self.current_specs().iter() { if !id.lint.crate_level_only { continue; diff --git a/tests/ui/lint/crate_level_only_lint.rs b/tests/ui/lint/crate_level_only_lint.rs index d9673faa214..6679cc0862f 100644 --- a/tests/ui/lint/crate_level_only_lint.rs +++ b/tests/ui/lint/crate_level_only_lint.rs @@ -3,20 +3,14 @@ mod foo { #![allow(uncommon_codepoints)] //~^ ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] -//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] -//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] #[allow(uncommon_codepoints)] //~^ ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] -//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] -//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] const BAR: f64 = 0.000001; } #[allow(uncommon_codepoints)] //~^ ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] -//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] -//~| ERROR allow(uncommon_codepoints) is ignored unless specified at crate level [unused_attributes] fn main() { } diff --git a/tests/ui/lint/crate_level_only_lint.stderr b/tests/ui/lint/crate_level_only_lint.stderr index fbb1ec381c8..34d27f873f6 100644 --- a/tests/ui/lint/crate_level_only_lint.stderr +++ b/tests/ui/lint/crate_level_only_lint.stderr @@ -11,64 +11,16 @@ LL | #![deny(uncommon_codepoints, unused_attributes)] | ^^^^^^^^^^^^^^^^^ error: allow(uncommon_codepoints) is ignored unless specified at crate level - --> $DIR/crate_level_only_lint.rs:9:9 + --> $DIR/crate_level_only_lint.rs:7:9 | LL | #[allow(uncommon_codepoints)] | ^^^^^^^^^^^^^^^^^^^ error: allow(uncommon_codepoints) is ignored unless specified at crate level - --> $DIR/crate_level_only_lint.rs:17:9 + --> $DIR/crate_level_only_lint.rs:13:9 | LL | #[allow(uncommon_codepoints)] | ^^^^^^^^^^^^^^^^^^^ -error: allow(uncommon_codepoints) is ignored unless specified at crate level - --> $DIR/crate_level_only_lint.rs:4:10 - | -LL | #![allow(uncommon_codepoints)] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: allow(uncommon_codepoints) is ignored unless specified at crate level - --> $DIR/crate_level_only_lint.rs:9:9 - | -LL | #[allow(uncommon_codepoints)] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: allow(uncommon_codepoints) is ignored unless specified at crate level - --> $DIR/crate_level_only_lint.rs:17:9 - | -LL | #[allow(uncommon_codepoints)] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: allow(uncommon_codepoints) is ignored unless specified at crate level - --> $DIR/crate_level_only_lint.rs:4:10 - | -LL | #![allow(uncommon_codepoints)] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: allow(uncommon_codepoints) is ignored unless specified at crate level - --> $DIR/crate_level_only_lint.rs:9:9 - | -LL | #[allow(uncommon_codepoints)] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: allow(uncommon_codepoints) is ignored unless specified at crate level - --> $DIR/crate_level_only_lint.rs:17:9 - | -LL | #[allow(uncommon_codepoints)] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 9 previous errors +error: aborting due to 3 previous errors