blob: dc39cc9dbffb00538de542553c67dfd69fa6a62c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
macro_rules! borrow {
($x:expr) => { &$x }
}
fn foo(_: String) {}
fn foo2(s: &String) {
foo(s);
//~^ ERROR mismatched types
}
fn foo3(_: u32) {}
fn foo4(u: &u32) {
foo3(u);
//~^ ERROR mismatched types
}
struct S<'a> {
u: &'a u32,
}
struct R {
i: u32,
}
fn main() {
let s = String::new();
let r_s = &s;
foo2(r_s);
foo(&"aaa".to_owned());
//~^ ERROR mismatched types
foo(&mut "aaa".to_owned());
//~^ ERROR mismatched types
foo3(borrow!(0));
//~^ ERROR mismatched types
foo4(&0);
assert_eq!(3i32, &3i32);
//~^ ERROR mismatched types
let u = 3;
let s = S { u };
//~^ ERROR mismatched types
let s = S { u: u };
//~^ ERROR mismatched types
let i = &4;
let r = R { i };
//~^ ERROR mismatched types
let r = R { i: i };
//~^ ERROR mismatched types
let a = &1;
let b = &2;
let val: i32 = if true {
a + 1
} else {
b
//~^ ERROR mismatched types
};
let val: i32 = if true {
let _ = 2;
a + 1
} else {
let _ = 2;
b
//~^ ERROR mismatched types
};
let val = if true {
*a
} else if true {
//~^ ERROR incompatible types
b
} else {
&0
};
#[derive(PartialEq, Eq)]
struct Foo;
let foo = Foo;
let bar = &Foo;
if foo == bar {
//~^ ERROR mismatched types
}
}
|