Function rustc_hir_typeck::op::is_builtin_binop

source ·
fn is_builtin_binop<'tcx>(lhs: Ty<'tcx>, rhs: Ty<'tcx>, op: BinOp) -> bool
Expand description

Returns true if this is a built-in arithmetic operation (e.g., u32

  • u32, i16x4 == i16x4) and false if these types would have to be overloaded to be legal. There are two reasons that we distinguish builtin operations from overloaded ones (vs trying to drive everything uniformly through the trait system and intrinsics or something like that):
  1. Builtin operations can trivially be evaluated in constants.
  2. For comparison operators applied to SIMD types the result is not of type bool. For example, i16x4 == i16x4 yields a type like i16x4. This means that the overloaded trait PartialEq is not applicable.

Reason #2 is the killer. I tried for a while to always use overloaded logic and just check the types in constants/codegen after the fact, and it worked fine, except for SIMD types. -nmatsakis