Skip to content

style(lib): Address clippy panics and missing_panics_doc lints - #4191

Open
Siech0 wants to merge 1 commit into
hyperium:masterfrom
Siech0:style/address-clippy-panic
Open

style(lib): Address clippy panics and missing_panics_doc lints#4191
Siech0 wants to merge 1 commit into
hyperium:masterfrom
Siech0:style/address-clippy-panic

Conversation

@Siech0

@Siech0 Siech0 commented Sep 11, 2026

Copy link
Copy Markdown

Towards #4071

Most of the panics are structurally unreachable, I attempted to reproduce them with adversarial workflows (panics, malformed inputs, etc) and I believe they are truly unreachable so I have marked them as unreachable!(...). This will still panic if it is hit, but it makes the intent clear and avoids needing a panic doc.

Two panics were reproducible and have had their panic docs written.

Connection::without_shutdown @ src/server/conn/http1.rs:184

// `without_shutdown` returns `impl Future`, so it can be driven by hand.
let mut conn = Box::pin(conn.without_shutdown());
let mut cx = Context::from_waker(Waker::noop());

assert!(conn.as_mut().poll(&mut cx).is_ready());

// Polling a completed future panics.
let _ = conn.as_mut().poll(&mut cx);

ReadBufCursor::advance @ src/rt/io.rs:346

let mut raw = [0u8; 8];
let mut rb = ReadBuf::new(&mut raw);
let mut cursor = rb.unfilled();
unsafe { cursor.advance(usize::MAX) }; // filled: 0 -> usize::MAX, no panic
unsafe { cursor.advance(1) };          // usize::MAX + 1 overflows and expect fires

Both cases are pretty silly to ever hit, but documentation is free.

@Siech0
Siech0 force-pushed the style/address-clippy-panic branch 2 times, most recently from 49ceb1c to 54b211d Compare September 11, 2026 03:55

@seanmonstar seanmonstar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on! 2 notes inline.

Comment thread src/client/conn/http1.rs Outdated
ready!(conn
.as_mut()
.expect("client connection polled after completion")
.unwrap_or_else(|| unreachable!("client connection polled after completion"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using expect in this case, polling a completed future, is normal. I wouldn't call this unreachable, because if the user does so, it sounds like we made a mistake.

But the docs of Future indicate the user should not do so. I don't think we need to document that behavior.

@Siech0 Siech0 Sep 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks for the prompt review!

Please note, on rebase I hit more lints and have updated accordingly.

Comment thread src/server/conn/http1.rs Outdated
///
/// # Panics
///
/// This future will panic if polled after it has already completed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this is basically expected from the Future docs, we can leave it off.

@Siech0 Siech0 Sep 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@Siech0
Siech0 marked this pull request as draft September 11, 2026 15:15
@Siech0
Siech0 force-pushed the style/address-clippy-panic branch 2 times, most recently from d59e9ae to 30577fc Compare September 11, 2026 15:46
@Siech0
Siech0 marked this pull request as ready for review September 11, 2026 15:47
@Siech0
Siech0 force-pushed the style/address-clippy-panic branch from 30577fc to d5729db Compare September 11, 2026 15:47
@Siech0
Siech0 requested a review from seanmonstar September 11, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants