summaryrefslogtreecommitdiffstats
path: root/src/test/ui/inference/deref-suggestion.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/inference/deref-suggestion.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/test/ui/inference/deref-suggestion.rs75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/test/ui/inference/deref-suggestion.rs b/src/test/ui/inference/deref-suggestion.rs
new file mode 100644
index 000000000..0d8e7289d
--- /dev/null
+++ b/src/test/ui/inference/deref-suggestion.rs
@@ -0,0 +1,75 @@
+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
+ };
+}