Skip to content

manual_div_ceil suggestion requires dereferencing #15705

@Alexendoo

Description

@Alexendoo

Description

pub fn f(size: u64, c: &u64) {
    let _ = (size + c - 1) / c;
}

Suggests

warning: manually reimplementing `div_ceil`
 --> src/lib.rs:2:13
  |
2 |     let _ = (size + c - 1) / c;
  |             ^^^^^^^^^^^^^^^^^^ help: consider using `.div_ceil()`: `size.div_ceil(c)`

Which would be an error

error[E0308]: mismatched types
    --> src/lib.rs:2:27
     |
   2 |     let _ = size.div_ceil(c);
     |                  -------- ^ expected `u64`, found `&u64`
     |                  |
     |                  arguments to this method are incorrect
     |
note: method defined here
    --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1160:5
     |
1160 | /     uint_impl! {
1161 | |         Self = u64,
1162 | |         ActualT = u64,
1163 | |         SignedT = i64,
...    |
1180 | |         bound_condition = "",
1181 | |     }
     | |_____^
     = note: this error originates in the macro `uint_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider dereferencing the borrow
     |
   2 |     let _ = size.div_ceil(*c);
     |                           +

Version


Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions