Skip to content

Add tests for ensuring we have the right impls for arithmetic traits #49660

Closed
@clarfonthey

Description

@clarfonthey

The other day I noticed that Wrapping only implements Shl and co. for usize, which contradicts that without Wrapping the shift amount can be any type. So, I think it may be useful to create tests which use macros to shove together all the types we expect to have impls for and check that we're consistent there.

What I've noticed:

  • For every operation three extra impls are added, with the combinations of single-level references on both sides, e.g. &T + T, T + &T, &T + &T for Add.
  • Assignment ops do the same as the above, with only one extra impl, e.g. T += &T for Add.
  • Add, Sub, Mul, Div, Rem exist for all int and float types with themselves
  • BitAnd, BitOr, BitXor exist for all int types and bool
  • Shl and Shr allow any integer type for both the left and the right side
  • Neg exists for all ints and floats
  • Not exists for all ints and bool
  • Wrapping should mimic all of the above, where references are of the form &Wrapping<T> and not Wrapping<&T>.

Like, I wouldn't be surprised if rearranging some macros might add or remove impls for these and adding comprehensive tests might help make sure we covered everything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-testsuiteArea: The testsuite used to check the correctness of rustcC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions