Skip to content

Fix manual is multiple of #15205

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

samueltardieu
Copy link
Contributor

@samueltardieu samueltardieu commented Jul 3, 2025

Fix several issues with manual_is_multiple_of

  • &a % &b == 0 compiles, but requires dereferencing b when replacing with a.is_multiple_of(b).
  • In a % b == 0, if type of a is not certain, a.is_multiple_of(b) might not be typable.
  • In a % b == 0, a and b must be unsigned integers, not any arbitrary types implementing Rem and outputing an integer.

Those fixes have required increasing the precision of type certainty determination in the two first patches.

Fixes #15203
Fixes #15204

changelog: [manual_is_multiple_of]: fix various false positive

However, if they appear within the context of a function argument, they
will be marked as certain, as they might eventually be considered `i32`
by default if the context is not more specific.

Also, in the case of binary expressions, if one of the side is
uncertain, then the certainty will come from the other side.
`Node::Param(…)` can represent function parameters as well as closure
parameters. In the second case, a type is not always given. When no
type is given, consider it uncertain.
- `&a % &b == 0` compiles, but requires dereferencing `b` when
  replacing with `a.is_multiple_of(b)`.
- In `a % b == 0`, if type of `a` is not certain,
  `a.is_multiple_of(b)` might not be typable.
- In `a % b == 0`, `a` and `b` must be unsigned integers, not any
  arbitrary types implementing `Rem` and outputing an integer.
@rustbot
Copy link
Collaborator

rustbot commented Jul 3, 2025

r? @Jarcho

rustbot has assigned @Jarcho.
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 rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 3, 2025
@samueltardieu

This comment was marked as outdated.

@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 3, 2025
@samueltardieu
Copy link
Contributor Author

@rustbot note remove Beta-nomination
@rustbot label -beta-nominated

Despite what is in the code, this lint has been introduced in 1.90 only. Those fixes only need to be merged before the next beta is cut from master.

@rustbot rustbot removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

manual_is_multiple_of triggers on arbitrary types implementing Rem and outputing an integer Smarter clippy::manual_is_multiple_of ?
3 participants