Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useless_attribute: Add unreachable_pub to whitelists #4107

Merged
merged 1 commit into from
May 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ declare_clippy_lint! {
/// **What it does:** Checks for `extern crate` and `use` items annotated with
/// lint attributes.
///
/// This lint whitelists `#[allow(unused_imports)]` and `#[allow(deprecated)]` on
/// `use` items and `#[allow(unused_imports)]` on `extern crate` items with a
/// `#[macro_use]` attribute.
/// This lint whitelists `#[allow(unused_imports)]`, `#[allow(deprecated)]` and
/// `#[allow(unreachable_pub)]` on `use` items and `#[allow(unused_imports)]` on
/// `extern crate` items with a `#[macro_use]` attribute.
///
/// **Why is this bad?** Lint attributes have no effect on crate imports. Most
/// likely a `!` was forgotten.
Expand Down Expand Up @@ -239,13 +239,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
if let Some(ident) = attr.ident() {
match &*ident.as_str() {
"allow" | "warn" | "deny" | "forbid" => {
// whitelist `unused_imports` and `deprecated` for `use` items
// whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items
// and `unused_imports` for `extern crate` items with `macro_use`
for lint in lint_list {
match item.node {
ItemKind::Use(..) => {
if is_word(lint, sym!(unused_imports))
|| is_word(lint, sym!(deprecated))
|| is_word(lint, sym!(unreachable_pub))
{
return;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/useless_attribute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// aux-build:proc_macro_derive.rs

#![warn(clippy::useless_attribute)]
#![warn(unreachable_pub)]

#[allow(dead_code)]
#[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
Expand Down Expand Up @@ -32,4 +33,16 @@ pub use foo::Bar;
#[derive(DeriveSomething)]
struct Baz;

// don't lint on unreachable_pub for `use` items
mod a {
mod b {
#[allow(dead_code)]
#[allow(unreachable_pub)]
pub struct C {}
}

#[allow(unreachable_pub)]
pub use self::b::C;
}

fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/useless_attribute.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: useless lint attribute
--> $DIR/useless_attribute.rs:5:1
--> $DIR/useless_attribute.rs:6:1
|
LL | #[allow(dead_code)]
| ^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![allow(dead_code)]`
|
= note: `-D clippy::useless-attribute` implied by `-D warnings`

error: useless lint attribute
--> $DIR/useless_attribute.rs:6:1
--> $DIR/useless_attribute.rs:7:1
|
LL | #[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: if you just forgot a `!`, use: `#![cfg_attr(feature = "cargo-clippy", allow(dead_code)`
Expand Down