Skip to content

Commit

Permalink
Try to clean up some lints and enable more
Browse files Browse the repository at this point in the history
I came across the unused_extern_crates lint, which is allow-by-default.
It is however part of the rust_2018_idioms lint group, which we are
already denying.

Anyway, this discovery led me down a linting rabbit hole.

There is the unused_import_braces lint which arguable lints against
something that rustfmt already deals with. Both the lint and rustfmt
deal with the braces in  "use test::{A};". Thus, this lint can just be
dropped.

The "unused" lint group includes "unused_must_use" and some other things
that sound helpful, so let's just switch to the more generic lint. This
found some unused_macro_rules in x11rb/src/tracing.rs, which need to be
allowed, so this lint can just be denied and not forbidden. But some of
the lints that we forbid are part of the "unused" group and #[deny]ing
something that was previously #[forbid]en is an error. Thus, I am
switching the order of these and move all the #[deny]s up.

Next, I thought that "unused_qualifications" should be part of "unused",
but it actually is not. The following code warns about the allows for
unused_extern_crates and unused_must_use, but not unused_qualifications,
so this is not part of the unused group. Same for unused_results.

    #![forbid(unused)]
    #![allow(unused_extern_crates)]
    #![allow(unused_must_use)]
    #![allow(unused_qualifications)]
    #![allow(unused_results)]

Signed-off-by: Uli Schlachter <[email protected]>
  • Loading branch information
psychon committed Mar 17, 2024
1 parent 08ce9fa commit e65fb09
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 41 deletions.
3 changes: 1 addition & 2 deletions extract-generated-code-doc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
trivial_numeric_casts,
unsafe_code,
unreachable_pub,
unused_import_braces,
unused_must_use,
unused,
unused_qualifications
)]
#![forbid(unsafe_code)]
Expand Down
3 changes: 1 addition & 2 deletions generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
trivial_numeric_casts,
unsafe_code,
unreachable_pub,
unused_import_braces,
unused_must_use,
unused,
unused_qualifications
)]
#![forbid(unsafe_code)]
Expand Down
20 changes: 11 additions & 9 deletions x11rb-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@
//! * `extra-traits`: Implement extra traits for X11 types. This improves the output of the `Debug`
//! impl and adds `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` where possible.
// A list of lints that are only #![deny] and not the stronger #![forbid]. Each one has a comment
// explaining why it gets the weaker treatment.
#![deny(
// Contains unreachable_code and "?" generates an #[allow] for this
unused,
// #[derive] generates an #[allow] for this; not part of "unused"
unused_qualifications,
// Not everything in x11rb::protocol has doc comments
missing_docs,
)]

#![forbid(
missing_copy_implementations,
missing_debug_implementations,
Expand All @@ -50,20 +61,11 @@
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unused_import_braces,
unused_must_use,
unused_results,
clippy::cast_lossless,
clippy::needless_pass_by_value,
)]
// A list of lints that are only #![deny] and not the stronger #![forbid]. Each one has a comment
// explaining why it gets the weaker treatment.
#![deny(
// #[derive] generates an #[allow] for this
unused_qualifications,
// Not everything in x11rb::protocol has doc comments
missing_docs,
)]
#![cfg_attr(not(feature = "allow-unsafe-code"), forbid(unsafe_code))]

// -- Public Modules --
Expand Down
24 changes: 13 additions & 11 deletions x11rb-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@
//! * `extra-traits`: Implement extra traits for types. This improves the output of the `Debug`
//! impl and adds `PartialEq`, `Eq`, `PartialOrd`, `Ord`, and `Hash` where possible.
// A list of lints that are only #![deny] and not the stronger #![forbid]. Each one has a comment
// explaining why it gets the weaker treatment.
#![deny(
// Contains unreachable_code and "?" generates an #[allow] for this
unused,
// #[derive] generates an #[allow] for this; not part of "unused"
unused_qualifications,
// serde's Deserialize/Serialize impls add allows for this
rust_2018_idioms,
// Not everything in x11rb_protocol::protocol has doc comments
missing_docs,
)]

#![forbid(
missing_copy_implementations,
missing_debug_implementations,
Expand All @@ -49,22 +62,11 @@
trivial_numeric_casts,
unreachable_pub,
unsafe_code,
unused_import_braces,
unused_must_use,
unused_results,
clippy::cast_lossless,
clippy::needless_pass_by_value,
)]
// A list of lints that are only #![deny] and not the stronger #![forbid]. Each one has a comment
// explaining why it gets the weaker treatment.
#![deny(
// #[derive] generates an #[allow] for this
unused_qualifications,
// serde's Deserialize/Serialize impls add allows for this
rust_2018_idioms,
// Not everything in x11rb_protocol::protocol has doc comments
missing_docs,
)]
#![no_std]

// std crate imports
Expand Down
20 changes: 11 additions & 9 deletions x11rb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@
//! The [event_loop_integration](event_loop_integration/index.html) module contains some hints for
//! integrating x11rb with an event loop as doc comments.
// A list of lints that are only #![deny] and not the stronger #![forbid]. Each one has a comment
// explaining why it gets the weaker treatment.
#![deny(
// Contains unreachable_code and "?" generates an #[allow] for this
unused,
// #[derive] generates an #[allow] for this; not part of "unused"
unused_qualifications,
// Not everything in x11rb::protocol has doc comments
missing_docs,
)]

#![forbid(
missing_copy_implementations,
missing_debug_implementations,
Expand All @@ -129,20 +140,11 @@
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unused_import_braces,
unused_must_use,
unused_results,
clippy::cast_lossless,
clippy::needless_pass_by_value,
)]
// A list of lints that are only #![deny] and not the stronger #![forbid]. Each one has a comment
// explaining why it gets the weaker treatment.
#![deny(
// #[derive] generates an #[allow] for this
unused_qualifications,
// Not everything in x11rb::protocol has doc comments
missing_docs,
)]
#![cfg_attr(not(feature = "allow-unsafe-code"), forbid(unsafe_code))]

// Only contains documentation, but no "actual rust"
Expand Down
2 changes: 2 additions & 0 deletions x11rb/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ macro_rules! warning_span {
( $name:expr ) => { $crate::tracing::implementation::span!($crate::tracing::Level::Warn, $name, ) };
( $name:expr, $($fields:tt)* ) => { $crate::tracing::implementation::span!($crate::tracing::Level::Warn, $name, $($fields)*) };
}
#[allow(unused_macro_rules)]
macro_rules! info_span {
( $name:expr ) => { $crate::tracing::implementation::span!($crate::tracing::Level::Info, $name, ) };
( $name:expr, $($fields:tt)* ) => { $crate::tracing::implementation::span!($crate::tracing::Level::Info, $name, $($fields)*) };
Expand All @@ -110,6 +111,7 @@ macro_rules! debug_span {
( $name:expr ) => { $crate::tracing::implementation::span!($crate::tracing::Level::Debug, $name, ) };
( $name:expr, $($fields:tt)* ) => { $crate::tracing::implementation::span!($crate::tracing::Level::Debug, $name, $($fields)*) };
}
#[allow(unused_macro_rules)]
macro_rules! trace_span {
( $name:expr ) => { $crate::tracing::implementation::span!($crate::tracing::Level::Trace, $name, ) };
( $name:expr, $($fields:tt)* ) => { $crate::tracing::implementation::span!($crate::tracing::Level::Trace, $name, $($fields)*) };
Expand Down
3 changes: 1 addition & 2 deletions xcbgen-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
trivial_numeric_casts,
unsafe_code,
unreachable_pub,
unused_import_braces,
unused_must_use,
unused,
unused_qualifications,
missing_copy_implementations,
missing_debug_implementations,
Expand Down
14 changes: 8 additions & 6 deletions xtrace-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,19 @@
//! The code in `connection_inner` then handles decoding X11 packets, updating the state of the
//! connection, and generating output via `println!`.
#![deny(
// Contains unreachable_code and "?" generates an #[allow] for this
unused,
// #[derive] generates an #[allow] for this; not part of "unused"
unused_qualifications,
)]

#![forbid(
missing_docs,
rust_2018_idioms,
trivial_casts,
trivial_numeric_casts,
unused_import_braces,
unused_results
)]
#![deny(
// #[derive] generates an #[allow] for this
unused_qualifications,
unused_results,
)]

use smol::Async;
Expand Down

0 comments on commit e65fb09

Please sign in to comment.