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

Enable some more lints #919

Merged
merged 11 commits into from
Feb 25, 2024
1 change: 1 addition & 0 deletions x11rb-async/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use x11rb_protocol::DiscardMode;
/// The [`blocking`] threadpool is used to handle all requests.
///
/// [`blocking`]: https://docs.rs/blocking
#[derive(Debug)]
pub struct BlockingConnection<C> {
inner: Arc<C>,
}
Expand Down
12 changes: 12 additions & 0 deletions x11rb-async/src/cookie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use crate::protocol::record::EnableContextReply;

/// A cookie for a request without a reply.
#[derive(Debug)]
pub struct VoidCookie<'conn, C: RequestConnection + ?Sized> {
conn: &'conn C,
sequence: SequenceNumber,
Expand Down Expand Up @@ -75,6 +76,7 @@
}

/// Helper for cookies that hold a reply.
#[derive(Debug)]
struct RawCookie<'a, C: RequestConnection + ?Sized> {
conn: &'a C,
sequence: SequenceNumber,
Expand Down Expand Up @@ -103,6 +105,7 @@
}

/// A cookie for a request that has a reply.
#[derive(Debug)]
pub struct Cookie<'conn, C: RequestConnection + ?Sized, R> {
raw: RawCookie<'conn, C>,
capture: PhantomData<R>,
Expand Down Expand Up @@ -173,6 +176,7 @@
}

/// A cookie for a request that has a reply containing file descriptors.
#[derive(Debug)]
pub struct CookieWithFds<'conn, C: RequestConnection + ?Sized, R> {
raw: RawCookie<'conn, C>,
capture: PhantomData<R>,
Expand Down Expand Up @@ -235,6 +239,14 @@
wait: Option<Pin<Box<dyn Future<Output = Result<C::Buf, ReplyError>> + Send + 'conn>>>,
}

impl<'conn, C: RequestConnection + std::fmt::Debug + ?Sized> std::fmt::Debug for $name<'conn, C> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct(stringify!($name))
.field("raw", &self.raw)
.finish_non_exhaustive()
}

Check warning on line 247 in x11rb-async/src/cookie.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/cookie.rs#L243-L247

Added lines #L243 - L247 were not covered by tests
}

impl<'conn, C: RequestConnection + ?Sized> $name<'conn, C> {
pub(crate) fn new(
cookie: Cookie<'conn, C, $reply>,
Expand Down
28 changes: 27 additions & 1 deletion x11rb-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,36 @@
//! * `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.

#![forbid(
missing_copy_implementations,
missing_debug_implementations,
rustdoc::private_doc_tests,
rust_2018_idioms,
//single_use_lifetimes,
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 --

pub mod blocking;
pub mod connection;
#[allow(clippy::type_complexity)]
#[allow(clippy::type_complexity, missing_docs)]
#[rustfmt::skip]
pub mod protocol;
pub mod rust_connection;
Expand All @@ -63,5 +88,6 @@ mod cookie;
pub use cookie::{Cookie, CookieWithFds, VoidCookie};

pub mod utils {
//! Utility functions that are not specific to X11.
pub use x11rb::utils::RawFdContainer;
}
2 changes: 1 addition & 1 deletion x11rb-async/src/rust_connection/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
let cookie = crate::protocol::xproto::query_extension(conn, name.as_bytes()).await?;

// Add the extension to the cache.
entry.insert(ExtensionState::Loading(cookie.sequence_number()));
let _entry = entry.insert(ExtensionState::Loading(cookie.sequence_number()));

Check warning on line 46 in x11rb-async/src/rust_connection/extensions.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/extensions.rs#L46

Added line #L46 was not covered by tests

std::mem::forget(cookie);
}
Expand Down
26 changes: 10 additions & 16 deletions x11rb-async/src/rust_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@
.send_request(ReplyFdKind::ReplyWithoutFDs)
.expect("This request should not be blocked by syncs");
inner.discard_reply(seq, DiscardMode::DiscardReplyAndError);

seq
};

// Write the entire packet.
Expand Down Expand Up @@ -414,7 +412,7 @@
&'this self,
bufs: &'bufs [io::IoSlice<'sl>],
fds: Vec<RawFdContainer>,
) -> Fut<'future, crate::Cookie<'this, Self, R>, ConnectionError>
) -> Fut<'future, Cookie<'this, Self, R>, ConnectionError>

Check warning on line 415 in x11rb-async/src/rust_connection/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/mod.rs#L415

Added line #L415 was not covered by tests
where
'this: 'future,
'bufs: 'future,
Expand All @@ -435,7 +433,7 @@
&'this self,
bufs: &'bufs [io::IoSlice<'sl>],
fds: Vec<RawFdContainer>,
) -> Fut<'future, crate::CookieWithFds<'this, Self, R>, ConnectionError>
) -> Fut<'future, CookieWithFds<'this, Self, R>, ConnectionError>

Check warning on line 436 in x11rb-async/src/rust_connection/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/mod.rs#L436

Added line #L436 was not covered by tests
where
'this: 'future,
'bufs: 'future,
Expand All @@ -456,7 +454,7 @@
&'this self,
bufs: &'bufs [io::IoSlice<'sl>],
fds: Vec<RawFdContainer>,
) -> Fut<'future, crate::VoidCookie<'this, Self>, ConnectionError>
) -> Fut<'future, VoidCookie<'this, Self>, ConnectionError>
where
'this: 'future,
'bufs: 'future,
Expand All @@ -473,7 +471,7 @@
&self,
sequence: SequenceNumber,
_kind: x11rb::connection::RequestKind,
mode: x11rb_protocol::DiscardMode,
mode: DiscardMode,
) {
tracing::debug!(
"Discarding reply to request {} in mode {:?}",
Expand Down Expand Up @@ -542,8 +540,7 @@
fn wait_for_reply_with_fds_raw(
&self,
sequence: SequenceNumber,
) -> Fut<'_, ReplyOrError<x11rb::connection::BufWithFds<Self::Buf>, Self::Buf>, ConnectionError>
{
) -> Fut<'_, ReplyOrError<BufWithFds<Self::Buf>, Self::Buf>, ConnectionError> {

Check warning on line 543 in x11rb-async/src/rust_connection/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/mod.rs#L543

Added line #L543 was not covered by tests
Box::pin(
self.wait_for_reply_with_fds_impl(sequence)
.instrument(tracing::info_span!("wait_for_reply_with_fds_raw", sequence)),
Expand Down Expand Up @@ -588,19 +585,16 @@
)
}

fn prefetch_maximum_request_bytes(
&self,
) -> Pin<Box<dyn futures_lite::Future<Output = ()> + Send + '_>> {
fn prefetch_maximum_request_bytes(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>> {

Check warning on line 588 in x11rb-async/src/rust_connection/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/mod.rs#L588

Added line #L588 was not covered by tests
Box::pin(async move {
self.prefetch_len_impl()
let _guard = self
.prefetch_len_impl()

Check warning on line 591 in x11rb-async/src/rust_connection/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/mod.rs#L590-L591

Added lines #L590 - L591 were not covered by tests
.await
.expect("Failed to prefetch maximum request bytes");
})
}

fn maximum_request_bytes(
&self,
) -> Pin<Box<dyn futures_lite::Future<Output = usize> + Send + '_>> {
fn maximum_request_bytes(&self) -> Pin<Box<dyn Future<Output = usize> + Send + '_>> {

Check warning on line 597 in x11rb-async/src/rust_connection/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/mod.rs#L597

Added line #L597 was not covered by tests
Box::pin(
async move {
let mut mrl = self
Expand Down Expand Up @@ -645,7 +639,7 @@
)
}

fn parse_error(&self, error: &[u8]) -> Result<x11rb::x11_utils::X11Error, ParseError> {
fn parse_error(&self, error: &[u8]) -> Result<X11Error, ParseError> {

Check warning on line 642 in x11rb-async/src/rust_connection/mod.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/mod.rs#L642

Added line #L642 was not covered by tests
let extensions = future::block_on(self.extensions.read());
X11Error::try_parse(error, &*extensions)
}
Expand Down
4 changes: 2 additions & 2 deletions x11rb-async/src/rust_connection/nb_connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Option<Self::Item>> {
match self.get_mut() {
Either::Left(a) => a.poll_next(cx),
Either::Right(b) => b.poll_next(cx),
Left(a) => a.poll_next(cx),
Right(b) => b.poll_next(cx),

Check warning on line 137 in x11rb-async/src/rust_connection/nb_connect.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/nb_connect.rs#L136-L137

Added lines #L136 - L137 were not covered by tests
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions x11rb-async/src/rust_connection/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

if packet_count > 0 {
// Notify any listeners that there is new data.
self.new_input.notify_additional(std::usize::MAX);
let _num_notified = self.new_input.notify_additional(std::usize::MAX);

Check warning on line 118 in x11rb-async/src/rust_connection/shared_state.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/shared_state.rs#L118

Added line #L118 was not covered by tests
} else {
// Wait for more data.
self.stream.readable().await?;
Expand Down Expand Up @@ -223,6 +223,6 @@
self.0.driver_dropped.store(true, Ordering::SeqCst);

// Wake up everyone that might be waiting
self.0.new_input.notify_additional(std::usize::MAX);
let _num_notified = self.0.new_input.notify_additional(std::usize::MAX);
}
}
5 changes: 3 additions & 2 deletions x11rb-async/src/rust_connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
pub type DefaultStream = StreamAdaptor<X11rbDefaultStream>;

/// An adaptor that implements a `Stream` for a type that implements `X11rbStream`.
#[derive(Debug)]
pub struct StreamAdaptor<S> {
inner: Async<S>,
}
Expand All @@ -62,7 +63,7 @@
impl<S> Future for Readable<'_, S> {
type Output = io::Result<()>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {

Check warning on line 66 in x11rb-async/src/rust_connection/stream.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/stream.rs#L66

Added line #L66 was not covered by tests
Pin::new(&mut self.0).poll(cx)
}
}
Expand All @@ -76,7 +77,7 @@
impl<S> Future for Writable<'_, S> {
type Output = io::Result<()>;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {

Check warning on line 80 in x11rb-async/src/rust_connection/stream.rs

View check run for this annotation

Codecov / codecov/patch

x11rb-async/src/rust_connection/stream.rs#L80

Added line #L80 was not covered by tests
Pin::new(&mut self.0).poll(cx)
}
}
Expand Down
8 changes: 4 additions & 4 deletions x11rb-async/src/rust_connection/write_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl WriteBuffer {
/// considered corrupted. This mechanism exists to catch futures being dropped without being
/// polled to completion. In this situation we cannot be sure how many bytes were already
/// written to the stream, so the complete connection is now broken.
pub async fn lock(&self) -> Result<WriteBufferGuard<'_>, ConnectionError> {
pub(super) async fn lock(&self) -> Result<WriteBufferGuard<'_>, ConnectionError> {
let mut lock = self.0.lock().await;
if std::mem::replace(&mut lock.corrupted, true) {
return Err(ConnectionError::IoError(io::Error::new(
Expand All @@ -58,7 +58,7 @@ impl WriteBuffer {

impl WriteBufferGuard<'_> {
/// Unlock this guard.
pub fn unlock(mut self) {
pub(super) fn unlock(mut self) {
self.0.corrupted = false;
}
}
Expand All @@ -79,7 +79,7 @@ impl std::ops::DerefMut for WriteBufferGuard<'_> {

impl WriteBufferInner {
/// Flush the write buffer.
pub async fn flush<'b, S: StreamBase<'b>>(
pub(super) async fn flush<'b, S: StreamBase<'b>>(
&mut self,
stream: &'b S,
) -> Result<(), ConnectionError> {
Expand Down Expand Up @@ -130,7 +130,7 @@ impl WriteBufferInner {
}

/// Write a set of buffers to the stream.
pub async fn write_all_vectored<'b, S: StreamBase<'b>>(
pub(super) async fn write_all_vectored<'b, S: StreamBase<'b>>(
&mut self,
stream: &'b S,
mut bufs: &[io::IoSlice<'_>],
Expand Down
1 change: 1 addition & 0 deletions x11rb-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
unreachable_pub,
unsafe_code,
unused_import_braces,
unused_must_use,
unused_results,
clippy::cast_lossless,
clippy::needless_pass_by_value,
Expand Down
1 change: 1 addition & 0 deletions x11rb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
trivial_numeric_casts,
unreachable_pub,
unused_import_braces,
unused_must_use,
unused_results,
clippy::cast_lossless,
clippy::needless_pass_by_value,
Expand Down
4 changes: 2 additions & 2 deletions xcbgen-rs/src/defs/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl FieldDef {
}

/// A `<pad>` field.
#[derive(Clone, Debug)]
#[derive(Clone, Copy, Debug)]
pub struct PadField {
/// The kind and size of padding
pub kind: PadKind,
Expand Down Expand Up @@ -377,7 +377,7 @@ pub enum FieldValueSet {
}

/// The kind of padding a `<pad>` can represent.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Copy)]
pub enum PadKind {
/// A fixed size padding of the given size (`bytes` attribute).
Bytes(u16),
Expand Down
2 changes: 1 addition & 1 deletion xcbgen-rs/src/defs/top_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub struct EnumItem {
}

/// The value of an enum item
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub enum EnumValue {
/// A `<value>`.
Value(u32),
Expand Down
8 changes: 7 additions & 1 deletion xcbgen-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
unreachable_pub,
unused_import_braces,
unused_must_use,
unused_qualifications
unused_qualifications,
missing_copy_implementations,
missing_debug_implementations,
rustdoc::private_doc_tests,
single_use_lifetimes,
clippy::cast_lossless,
clippy::needless_pass_by_value
)]
#![forbid(unsafe_code)]

Expand Down
3 changes: 2 additions & 1 deletion xcbgen-rs/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use crate::defs;

/// An error that occurred while parsing an error.
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]

Check warning on line 15 in xcbgen-rs/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

xcbgen-rs/src/parser.rs#L15

Added line #L15 was not covered by tests
pub enum ParseError {
/// The XML tree is in some way malformed.
///
Expand Down Expand Up @@ -51,6 +51,7 @@
/// A `Parser` that adds namespaces to a module.
///
/// One instance of this struct can be used to parse multiple namespaces, one after another.
#[derive(Debug)]

Check warning on line 54 in xcbgen-rs/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

xcbgen-rs/src/parser.rs#L54

Added line #L54 was not covered by tests
pub struct Parser {
module: Rc<defs::Module>,
}
Expand Down
Loading
Loading