Skip to content

Commit b5f31e2

Browse files
Fix useless_attribute FP on exported_private_dependencies lint attributes (rust-lang#16470)
The `exported_private_dependencies` lint can fire on any mention of an item from a private dependency, including mentions inside of `use`. Therefore, `useless_attribute` should not fire on lint attributes mentioning `exported_private_dependencies` attached to a `use`. changelog: [`useless_attribute`]: fix false positive on `exported_private_dependencies` lint attributes PR rust-lang#15645 was used as an example for preparing this PR.
2 parents 7e3cf26 + 17f89e7 commit b5f31e2

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

clippy_lints/src/attrs/useless_attribute.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
3131
| sym::dead_code
3232
| sym::deprecated
3333
| sym::deprecated_in_future
34+
| sym::exported_private_dependencies
3435
| sym::hidden_glob_reexports
3536
| sym::unreachable_pub
3637
| sym::unused

clippy_utils/src/sym.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ generate! {
147147
exp,
148148
expect_err,
149149
expn_data,
150+
exported_private_dependencies,
150151
extend,
151152
filter,
152153
filter_map,

tests/ui/useless_attribute.fixed

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ mod foo {
4242
#[allow(deprecated)]
4343
pub use foo::Bar;
4444

45+
// don't lint on exported_private_dependencies for `use` items
46+
#[allow(exported_private_dependencies)]
47+
use {};
48+
4549
// This should not trigger the lint. There's lint level definitions inside the external derive
4650
// that would trigger the useless_attribute lint.
4751
#[derive(DeriveSomething)]

tests/ui/useless_attribute.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ mod foo {
4242
#[allow(deprecated)]
4343
pub use foo::Bar;
4444

45+
// don't lint on exported_private_dependencies for `use` items
46+
#[allow(exported_private_dependencies)]
47+
use {};
48+
4549
// This should not trigger the lint. There's lint level definitions inside the external derive
4650
// that would trigger the useless_attribute lint.
4751
#[derive(DeriveSomething)]

0 commit comments

Comments
 (0)