Rollup merge of #68129 - varkor:infer-binary-operand-behind-reference, r=nikomatsakis

Correct inference of primitive operand type behind binary operation

Fixes https://github.com/rust-lang/rust/issues/57447.

r? @nikomatsakis
This commit is contained in:
Yuki Okushi 2020-02-15 07:17:43 +09:00 committed by GitHub
commit 3f7ed88fdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 10 deletions

View file

@ -0,0 +1,30 @@
// check-pass
fn main() {
// Test that we can infer the type of binary operands when
// references are involved, on various types and operators.
let _: u8 = 0 + 0;
let _: u8 = 0 + &0;
let _: u8 = &0 + 0;
let _: u8 = &0 + &0;
let _: f32 = 0.0 + 0.0;
let _: f32 = 0.0 + &0.0;
let _: f32 = &0.0 + 0.0;
let _: f32 = &0.0 + &0.0;
let _: u8 = 0 << 0;
let _: u8 = 0 << &0;
let _: u8 = &0 << 0;
let _: u8 = &0 << &0;
// Test type inference when variable types are indirectly inferred.
let a = 22;
let _: usize = a + &44;
// When we have no expected type, the types of the operands is the default type.
let _ = 0 + 0;
let _ = 0 + &0;
let _ = &0 + 0;
let _ = &0 + &0;
}