Closed
Description
Originally posted as a comment on #36549, but in hindsight this may be a different issue. (in that #36549
very clearly looks like a bug, whereas this one is in a potential gray area)
let _: f32 = 1. - 1.; // allowed
let _: f32 = 1. - &1.; // type error
let _: f32 = &1. - 1.; // type error
let _: f32 = &1. - &1.; // type error
In the latter 3 cases, the type of &1.
is apparently defaulted to &f64
:
Compiling playground v0.0.1 (/playground)
error[E0271]: type mismatch resolving `<f64 as std::ops::Sub<&f64>>::Output == f32`
--> src/main.rs:3:21
|
3 | let _: f32 = 1. - &1.; // type error
| ^ expected f64, found f32
error[E0271]: type mismatch resolving `<&f64 as std::ops::Sub<f64>>::Output == f32`
--> src/main.rs:4:22
|
4 | let _: f32 = &1. - 1.; // type error
| ^ expected f64, found f32
error[E0271]: type mismatch resolving `<&f64 as std::ops::Sub<&f64>>::Output == f32`
--> src/main.rs:5:22
|
5 | let _: f32 = &1. - &1.; // type error
| ^ expected f64, found f32
To a mortal like me, it seems that the only reason the first line works is because the compiler must have a special case for binary operations between two unconstrained "floating-point flavored" type inference variables. Can the compiler not just special case the latter three examples in the same way it special cases the first?