Skip to content

wrong clippy suggestion for div_ceil in macro definition #14665

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

Closed
glorv opened this issue Apr 21, 2025 · 2 comments · Fixed by #14666
Closed

wrong clippy suggestion for div_ceil in macro definition #14665

glorv opened this issue Apr 21, 2025 · 2 comments · Fixed by #14666

Comments

@glorv
Copy link

glorv commented Apr 21, 2025

The source code is here https://github.com/tikv/tikv/blob/7467871cb55b4fe29cee23fa85f0e7fb89768d2b/components/file_system/src/rate_limiter.rs#L266
When I update rust-toolchain from nightly-2023-12-28 to nightly-2025-04-03 and run cargo clippy, it returns

I expected to see this happen: explanation

warning: manually reimplementing `div_ceil`
   --> components/file_system/src/rate_limiter.rs:266:23
    |
266 |                       * ((locked.pending_bytes[priority_idx] + cached_b...
    |  _______________________^
267 | |                         / cached_bytes_per_epoch) as u32
    | |_________________________________________________^ help: consider using `.div_ceil()`: `locked.pending_bytes[priority_idx].div_ceil(cached_bytes_per_epoch)`

Instead, this happened: explanation

warning: manually reimplementing `div_ceil`
   --> components/file_system/src/rate_limiter.rs:266:23
    |
266 |                       * ((locked.pending_bytes[priority_idx] + cached_b...
    |  _______________________^
267 | |                         / cached_bytes_per_epoch) as u32
    | |_________________________________________________^ help: consider using `.div_ceil()`: `locked.pending_bytes[priority_idx].div_ceil(request_imp!(self, priority, amount, sync))`

Meta

rustc --version --verbose:
The tool chain is nightly-2025-04-03

$ cargo --version
cargo 1.88.0-nightly (a6c604d1b 2025-03-26)
Backtrace

<backtrace>

@glorv glorv added the C-bug Category: Clippy is not doing the correct thing label Apr 21, 2025
@Kivooeo
Copy link
Contributor

Kivooeo commented Apr 21, 2025

Will take this one

@fmease fmease removed the C-bug Category: Clippy is not doing the correct thing label Apr 22, 2025
@fmease
Copy link
Member

fmease commented Apr 22, 2025

@rustbot transfer rust-clippy

@rustbot rustbot transferred this issue from rust-lang/rust Apr 22, 2025
github-merge-queue bot pushed a commit that referenced this issue Apr 27, 2025
here is my small fix

changelog: fix suggestion span to avoid showing macro name in
`.div_ceil()` suggestion

i changed this line
`let divisor_snippet = snippet_with_applicability(cx,
rhs.spansource_callsite(), "..", applicability);`
to this line
`let divisor_snippet = snippet_with_applicability(cx, rhs.span, "..",
applicability);`
to fix problem where this warning in macro expands like this
```rust
4  |         let _ = (x + 7) / 8;
   |                 ^^^^^^^^^^^ help: consider using `.div_ceil()`: `x.div_ceil(y!())`
```
[play it
yourself](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=397aa8cd2ffffb24a286fbddbc75446c)

as you can see here it looks like `x.div_ceil(y!())` and contains macro
signature
so i fixed this problem, i will look closely if there any more problems
like this and fix them in order

**Related issue**

fixes
[#14665](#14665)
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 a pull request may close this issue.

3 participants