Skip to content

remove arithmetic_side_effects#4120

Open
yanns wants to merge 1 commit into
hyperium:masterfrom
yanns:remove_arithmetic_side_effects
Open

remove arithmetic_side_effects#4120
yanns wants to merge 1 commit into
hyperium:masterfrom
yanns:remove_arithmetic_side_effects

Conversation

@yanns

@yanns yanns commented Jun 27, 2026

Copy link
Copy Markdown

part of #4071

In general, I've added quite a lot of #[allow(clippy::arithmetic_side_effects)]. I still think that this lint is useful. It's easier to search for this and to review arithmetic operations. It can also prevent some issues in the future.

There are some parts where I've used some saturating operations, which can have an impact of performance. This needs a careful review.

If this is too complex to review, I can remove the new saturating operations and add the allow in those places. I could later open smaller PRs trying to address some of those.

@yanns yanns force-pushed the remove_arithmetic_side_effects branch from 3027a46 to 7a5ddd9 Compare June 27, 2026 17:34
Comment thread src/rt/io.rs
#[allow(clippy::arithmetic_side_effects)]
fn remaining(&self) -> usize {
debug_assert!(
self.capacity() >= self.filled,

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.

This should be true. We could use an assert! as in put_slice, but this would have some performance impact in release mode. I've opted for a debug_assert. Let me know if you think it's the right thing to do.
An alternative is to use saturating_sub which would have a performance cost.

@yanns yanns marked this pull request as ready for review June 27, 2026 17:36
@yanns yanns marked this pull request as draft June 27, 2026 17:42
@yanns yanns force-pushed the remove_arithmetic_side_effects branch from 7a5ddd9 to 446fef5 Compare June 27, 2026 18:23
@yanns yanns marked this pull request as ready for review June 27, 2026 18:27
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.

1 participant