2017-08-14 22:21:36 +00:00
|
|
|
macro_rules! borrow {
|
2022-07-20 03:05:14 +00:00
|
|
|
($x:expr) => { &$x }
|
2017-08-14 22:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn foo(_: String) {}
|
|
|
|
|
|
|
|
fn foo2(s: &String) {
|
2018-08-26 23:54:06 +00:00
|
|
|
foo(s);
|
|
|
|
//~^ ERROR mismatched types
|
2017-08-14 22:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn foo3(_: u32) {}
|
|
|
|
fn foo4(u: &u32) {
|
2018-08-26 23:54:06 +00:00
|
|
|
foo3(u);
|
|
|
|
//~^ ERROR mismatched types
|
2017-08-14 22:21:36 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 02:04:25 +00:00
|
|
|
struct S<'a> {
|
|
|
|
u: &'a u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct R {
|
|
|
|
i: u32,
|
|
|
|
}
|
|
|
|
|
2017-08-14 22:21:36 +00:00
|
|
|
fn main() {
|
|
|
|
let s = String::new();
|
|
|
|
let r_s = &s;
|
|
|
|
foo2(r_s);
|
2018-08-26 23:54:06 +00:00
|
|
|
foo(&"aaa".to_owned());
|
|
|
|
//~^ ERROR mismatched types
|
|
|
|
foo(&mut "aaa".to_owned());
|
|
|
|
//~^ ERROR mismatched types
|
2017-08-14 22:21:36 +00:00
|
|
|
foo3(borrow!(0));
|
2022-07-20 03:05:14 +00:00
|
|
|
//~^ ERROR mismatched types
|
2017-08-14 22:21:36 +00:00
|
|
|
foo4(&0);
|
2018-08-26 23:54:06 +00:00
|
|
|
assert_eq!(3i32, &3i32);
|
|
|
|
//~^ ERROR mismatched types
|
2019-03-27 02:04:25 +00:00
|
|
|
let u = 3;
|
|
|
|
let s = S { u };
|
|
|
|
//~^ ERROR mismatched types
|
2019-03-27 02:07:15 +00:00
|
|
|
let s = S { u: u };
|
|
|
|
//~^ ERROR mismatched types
|
2019-03-27 02:04:25 +00:00
|
|
|
let i = &4;
|
|
|
|
let r = R { i };
|
|
|
|
//~^ ERROR mismatched types
|
2019-03-27 02:07:15 +00:00
|
|
|
let r = R { i: i };
|
|
|
|
//~^ ERROR mismatched types
|
2020-12-06 00:14:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
let a = &1;
|
|
|
|
let b = &2;
|
|
|
|
let val: i32 = if true {
|
|
|
|
a + 1
|
|
|
|
} else {
|
|
|
|
b
|
|
|
|
//~^ ERROR mismatched types
|
|
|
|
};
|
2020-12-17 12:24:51 +00:00
|
|
|
let val: i32 = if true {
|
|
|
|
let _ = 2;
|
|
|
|
a + 1
|
|
|
|
} else {
|
|
|
|
let _ = 2;
|
|
|
|
b
|
|
|
|
//~^ ERROR mismatched types
|
|
|
|
};
|
2021-03-25 20:53:56 +00:00
|
|
|
let val = if true {
|
|
|
|
*a
|
|
|
|
} else if true {
|
|
|
|
//~^ ERROR incompatible types
|
|
|
|
b
|
|
|
|
} else {
|
|
|
|
&0
|
|
|
|
};
|
2023-04-19 16:47:06 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq, Eq)]
|
|
|
|
struct Foo;
|
|
|
|
let foo = Foo;
|
|
|
|
let bar = &Foo;
|
|
|
|
|
|
|
|
if foo == bar {
|
|
|
|
//~^ ERROR mismatched types
|
|
|
|
}
|
2018-08-27 01:03:57 +00:00
|
|
|
}
|