Skip to content

Commit 83d5940

Browse files
committed
useless_attribute: Add unreachable_pub to whitelists
1 parent 11194e3 commit 83d5940

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

clippy_lints/src/attrs.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ declare_clippy_lint! {
5050
/// **What it does:** Checks for `extern crate` and `use` items annotated with
5151
/// lint attributes.
5252
///
53-
/// This lint whitelists `#[allow(unused_imports)]` and `#[allow(deprecated)]` on
54-
/// `use` items and `#[allow(unused_imports)]` on `extern crate` items with a
55-
/// `#[macro_use]` attribute.
53+
/// This lint whitelists `#[allow(unused_imports)]`, `#[allow(deprecated)]` and
54+
/// `#[allow(unreachable_pub)]` on `use` items and `#[allow(unused_imports)]` on
55+
/// `extern crate` items with a `#[macro_use]` attribute.
5656
///
5757
/// **Why is this bad?** Lint attributes have no effect on crate imports. Most
5858
/// likely a `!` was forgotten.
@@ -240,13 +240,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
240240
if let Some(ident) = attr.ident() {
241241
match &*ident.as_str() {
242242
"allow" | "warn" | "deny" | "forbid" => {
243-
// whitelist `unused_imports` and `deprecated` for `use` items
243+
// whitelist `unused_imports`, `deprecated` and `unreachable_pub` for `use` items
244244
// and `unused_imports` for `extern crate` items with `macro_use`
245245
for lint in lint_list {
246246
match item.node {
247247
ItemKind::Use(..) => {
248248
if is_word(lint, *sym::unused_imports)
249249
|| is_word(lint, *sym::deprecated)
250+
|| is_word(lint, *sym::unreachable_pub)
250251
{
251252
return;
252253
}

clippy_lints/src/utils/sym.rs

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ symbols_simple! {
363363
uninit,
364364
uninitialized,
365365
unreachable,
366+
unreachable_pub,
366367
unused_extern_crates,
367368
unused_imports,
368369
unwrap,

tests/ui/useless_attribute.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// aux-build:proc_macro_derive.rs
22

33
#![warn(clippy::useless_attribute)]
4+
#![warn(unreachable_pub)]
45

56
#[allow(dead_code)]
67
#[cfg_attr(feature = "cargo-clippy", allow(dead_code))]
@@ -32,4 +33,16 @@ pub use foo::Bar;
3233
#[derive(DeriveSomething)]
3334
struct Baz;
3435

36+
// don't lint on unreachable_pub for `use` items
37+
mod a {
38+
mod b {
39+
#[allow(dead_code)]
40+
#[allow(unreachable_pub)]
41+
pub struct C {}
42+
}
43+
44+
#[allow(unreachable_pub)]
45+
pub use b::C;
46+
}
47+
3548
fn main() {}

0 commit comments

Comments
 (0)