Skip to content

Commit

Permalink
Merge pull request #923 from psychon/lints
Browse files Browse the repository at this point in the history
Try to clean up some lints and enable more
  • Loading branch information
psychon committed Apr 1, 2024
2 parents 08ce9fa + 6551db1 commit 2b3a646
Show file tree
Hide file tree
Showing 26 changed files with 50 additions and 72 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
2 changes: 0 additions & 2 deletions generator/src/generator/namespace/parse.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::convert::TryFrom;

use xcbgen::defs as xcbdefs;

use super::{
Expand Down
2 changes: 1 addition & 1 deletion generator/src/generator/namespace/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub(super) fn generate_request(
ImplMode::Async,
);

super::special_cases::handle_request(request_def, proto_out);
special_cases::handle_request(request_def, proto_out);

outln!(proto_out, "");
outln!(x11rb_out, "");
Expand Down
1 change: 0 additions & 1 deletion generator/src/generator/namespace/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::convert::TryFrom;

use xcbgen::defs as xcbdefs;

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
1 change: 0 additions & 1 deletion x11rb-async/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use x11rb_protocol::{DiscardMode, RawEventAndSeqNumber, SequenceNumber};
use crate::errors::{ConnectionError, ParseError, ReplyError, ReplyOrIdError};
use crate::{Cookie, CookieWithFds, VoidCookie};

use std::boxed::Box;
use std::future::Future;
use std::io::IoSlice;
use std::pin::Pin;
Expand Down
19 changes: 10 additions & 9 deletions x11rb-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
//! * `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 +60,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
2 changes: 0 additions & 2 deletions x11rb-protocol/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::xauth::{get_auth, Family};

use alloc::{vec, vec::Vec};

use core::convert::TryFrom;
use core::fmt;

/// The connection handshake used to connect to the X11 server.
Expand Down Expand Up @@ -270,7 +269,6 @@ mod tests {
use crate::protocol::xproto::{ImageOrder, Setup, SetupAuthenticate, SetupFailed};
use crate::x11_utils::Serialize;
use alloc::vec;
use core::mem::drop;

fn test_setup() -> Setup {
let mut s = Setup {
Expand Down
23 changes: 12 additions & 11 deletions x11rb-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
//! * `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 +61,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
1 change: 0 additions & 1 deletion x11rb-protocol/src/packet_reader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Collects X11 data into "packets" to be parsed by a display.

use core::convert::TryInto;
use core::fmt;
use core::mem::replace;

Expand Down
2 changes: 1 addition & 1 deletion x11rb-protocol/src/resource_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl Database {
}
} else {
// 5. Load `$HOME/.Xdefaults-[hostname]`
let mut file = std::ffi::OsString::from(".Xdefaults-");
let mut file = OsString::from(".Xdefaults-");
file.push(hostname);
let mut path = match var_os("HOME") {
Some(home) => PathBuf::from(home),
Expand Down
2 changes: 0 additions & 2 deletions x11rb-protocol/src/x11_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//! [`Serialize`] traits. These traits are used internally for parsing incoming data and producing
//! outgoing data when talking with the X11 server.

use core::convert::TryInto;

use alloc::string::String;
use alloc::vec::Vec;

Expand Down
1 change: 0 additions & 1 deletion x11rb/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//! This module contains the `Connection` trait and related definitions. The code in this module is
//! used by each concrete implementation of the X11 protocol.

use std::convert::{TryFrom, TryInto};
use std::io::IoSlice;

use x11rb_protocol::x11_utils::{ReplyFDsRequest, ReplyRequest, VoidRequest};
Expand Down
1 change: 0 additions & 1 deletion x11rb/src/cursor/parse_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Copyright © 2013 Michael Stapelberg
// and is covered by MIT/X Consortium License

use std::convert::TryInto;
use std::io::{Read, Seek, SeekFrom};

const FILE_MAGIC: u32 = 0x7275_6358;
Expand Down
3 changes: 0 additions & 3 deletions x11rb/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
// begins with the second bit of each pixel etc.

use std::borrow::Cow;
use std::convert::{TryFrom, TryInto};

use crate::connection::Connection;
use crate::cookie::VoidCookie;
Expand Down Expand Up @@ -248,7 +247,6 @@ fn compute_stride(width: u16, bits_per_pixel: BitsPerPixel, scanline_pad: Scanli
#[cfg(test)]
mod test_stride {
use super::compute_stride;
use std::convert::TryInto;

#[test]
fn test_stride() {
Expand Down Expand Up @@ -370,7 +368,6 @@ impl ScanlinePad {
#[cfg(test)]
mod test_scanline_pad {
use super::ScanlinePad;
use std::convert::TryInto;

#[test]
fn number_conversions() {
Expand Down
19 changes: 10 additions & 9 deletions x11rb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@
//! 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 +139,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
8 changes: 2 additions & 6 deletions x11rb/src/properties.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Utility functions for working with X11 properties

use std::convert::TryInto;

use crate::connection::RequestConnection;
use crate::cookie::{Cookie, VoidCookie};
use crate::errors::{ConnectionError, ParseError, ReplyError};
Expand Down Expand Up @@ -572,8 +570,8 @@ impl WmHints {
conn,
xproto::PropMode::REPLACE,
window,
xproto::AtomEnum::WM_HINTS,
xproto::AtomEnum::WM_HINTS,
AtomEnum::WM_HINTS,
AtomEnum::WM_HINTS,
32,
NUM_WM_HINTS_ELEMENTS,
&data,
Expand Down Expand Up @@ -681,8 +679,6 @@ fn parse_with_flag<T: TryParse>(

#[cfg(test)]
mod test {
use std::convert::TryInto;

use super::{WmClass, WmHints, WmHintsState, WmSizeHints};
use crate::protocol::xproto::{Atom, AtomEnum, GetPropertyReply, Gravity};
use crate::x11_utils::Serialize;
Expand Down
2 changes: 0 additions & 2 deletions x11rb/src/rust_connection/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! A pure-rust implementation of a connection to an X11 server.

use std::convert::TryInto;
use std::io::IoSlice;
use std::mem::drop;
use std::sync::{Condvar, Mutex, MutexGuard, TryLockError};
use std::time::Instant;

Expand Down
6 changes: 3 additions & 3 deletions x11rb/src/rust_connection/packet_reader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Read X11 packets from a reader

use std::io::{Error, ErrorKind, Result};
use std::{cmp, fmt, io};
use std::{cmp, fmt};

use super::Stream;
use crate::utils::RawFdContainer;
Expand Down Expand Up @@ -67,7 +67,7 @@ impl PacketReader {
out_packets.push(packet);
}
}
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => break,
Err(ref e) if e.kind() == ErrorKind::WouldBlock => break,
Err(e) => return Err(e),
}
} else {
Expand All @@ -81,7 +81,7 @@ impl PacketReader {
));
}
Ok(n) => n,
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => break,
Err(ref e) if e.kind() == ErrorKind::WouldBlock => break,
Err(e) => return Err(e),
};
crate::trace!("Read {} bytes into read buffer", nread);
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
2 changes: 0 additions & 2 deletions x11rb/src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Some wrappers around the generated code to simplify use.

use std::convert::TryInto;

use super::cookie::VoidCookie;
use super::errors::{ConnectionError, ReplyError};
use super::protocol::xproto::{Atom, ConnectionExt as XProtoConnectionExt, PropMode, Window};
Expand Down
1 change: 0 additions & 1 deletion x11rb/src/xcb_ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! This module is only available when the `allow-unsafe-code` feature is enabled.

use std::convert::TryInto;
use std::ffi::CStr;
use std::io::{Error as IOError, ErrorKind, IoSlice};
use std::os::raw::c_int;
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
1 change: 0 additions & 1 deletion xtrace-example/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use futures_io::{AsyncRead, AsyncWrite};
use std::cell::RefCell;
use std::convert::{TryFrom, TryInto};
use std::io::Result as IOResult;
use std::sync::atomic::{AtomicBool, Ordering};

Expand Down
1 change: 0 additions & 1 deletion xtrace-example/src/connection_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use x11rb_protocol::x11_utils::{
};

use std::collections::VecDeque;
use std::convert::TryInto;

/// Parse some data and print the resulting object.
///
Expand Down
11 changes: 6 additions & 5 deletions xtrace-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +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,
)]

use smol::Async;
use std::io::Result as IOResult;
Expand Down

0 comments on commit 2b3a646

Please sign in to comment.