rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

[`manual_div_ceil`]: init

Open belyakov-am opened this issue 1 year ago • 7 comments

Suggest using div_ceil() instead of manual implementation for basic cases.

Partially fixes #12894

changelog: new lint: [manual_div_ceil]

belyakov-am avatar Jun 23 '24 17:06 belyakov-am

r? @blyxyas

rustbot has assigned @blyxyas. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar Jun 23 '24 17:06 rustbot

See #12894 for more details

belyakov-am avatar Jun 23 '24 17:06 belyakov-am

Not related, but maybe we should do some benchmarks on (a + (b - 1)) / b vs div_ceil, it seems to be 1 instruction faster

blyxyas avatar Jul 01 '24 18:07 blyxyas

:umbrella: The latest upstream changes (presumably #12873) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Jul 04 '24 05:07 bors

Looking at lintcheck, all new lint suggestions are valid, so no FPs there. But the suggestions generation for macros is broken:

warning: manually reimplementing `div_ceil`
   --> target/lintcheck/sources/rand_core-0.6.0/src/impls.rs:59:26
    |
59  |         let chunk_size = (chunk_size_u8 + SIZE - 1) / SIZE;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `chunk_size_u8.div_ceil(fill_via_chunks!(src, dest, u64))`
...
132 |     fill_via_chunks!(src, dest, u64)
    |     -------------------------------- in this macro invocation
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_div_ceil
    = note: this warning originates in the macro `fill_via_chunks` (in Nightly builds, run with -Z macro-backtrace for more info)

flip1995 avatar Jul 19 '24 12:07 flip1995

:umbrella: The latest upstream changes (presumably #11476) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Aug 28 '24 08:08 bors

I've done some updating. But I'm not being able to replicate the macro bug that Philipp is talking about, is there any more information? @belyakov-am Can you replicate it?

If we're not able to replicate it, we can safely merge this.

blyxyas avatar Aug 28 '24 22:08 blyxyas

:umbrella: The latest upstream changes (presumably #13247) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 03 '24 17:09 bors

Thanks! And sorry for disappearing for so long I wasn't able to reproduce this one

belyakov-am avatar Sep 05 '24 09:09 belyakov-am

I also doesn't show up in the latest lintcheck run anymore. So I guess my concern is resolved.

flip1995 avatar Sep 05 '24 14:09 flip1995

Just looked at lintcheck, everything looks correct!

@bors r+

blyxyas avatar Sep 05 '24 23:09 blyxyas

:pushpin: Commit 9415e6e6eb9a570acecebd3dda0ed2b5db9fb910 has been approved by blyxyas

It is now in the queue for this repository.

bors avatar Sep 05 '24 23:09 bors

:hourglass: Testing commit 9415e6e6eb9a570acecebd3dda0ed2b5db9fb910 with merge 9e9042a11074c83a2c40b4e8ce29f9e2bb610d34...

bors avatar Sep 05 '24 23:09 bors

:sunny: Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test Approved by: blyxyas Pushing 9e9042a11074c83a2c40b4e8ce29f9e2bb610d34 to master...

bors avatar Sep 05 '24 23:09 bors