Rust: Add more type inference tests

This commit is contained in:
Tom Hvitved
2025-10-23 15:17:30 +02:00
parent caccee9990
commit 72b7dd8955
3 changed files with 4226 additions and 4146 deletions

View File

@@ -9,9 +9,9 @@ multipleCallTargets
| main.rs:590:9:590:18 | ...::m(...) |
| main.rs:591:9:591:20 | ... .m() |
| main.rs:592:9:592:24 | ...::m(...) |
| main.rs:2524:13:2524:31 | ...::from(...) |
| main.rs:2525:13:2525:31 | ...::from(...) |
| main.rs:2526:13:2526:31 | ...::from(...) |
| main.rs:2532:13:2532:31 | ...::from(...) |
| main.rs:2533:13:2533:31 | ...::from(...) |
| main.rs:2534:13:2534:31 | ...::from(...) |
| main.rs:2553:13:2553:31 | ...::from(...) |
| main.rs:2554:13:2554:31 | ...::from(...) |
| main.rs:2555:13:2555:31 | ...::from(...) |
| main.rs:2561:13:2561:31 | ...::from(...) |
| main.rs:2562:13:2562:31 | ...::from(...) |
| main.rs:2563:13:2563:31 | ...::from(...) |

View File

@@ -758,6 +758,26 @@ mod function_trait_bounds {
fn assoc(x: Self) -> A;
}
impl<T: Default> MyTrait<T> for S2 {
fn m1(self) -> T {
Default::default() // $ target=default
}
fn assoc(x: Self) -> T {
Default::default() // $ target=default
}
}
impl MyTrait<i32> for S1 {
fn m1(self) -> i32 {
0
}
fn assoc(x: Self) -> i32 {
0
}
}
// Type parameter with bound occurs in the root of a parameter type.
fn call_trait_m1<T1, T2: MyTrait<T1> + Copy>(x: T2) -> T1 {
@@ -863,6 +883,8 @@ mod function_trait_bounds {
println!("{:?}", b);
let b = call_trait_thing_m1_3(y3); // $ type=b:S2 target=call_trait_thing_m1_3
println!("{:?}", b);
let x = S1::m2(S1); // $ target=m2 $ type=x:i32
let y: i32 = S2::m2(S2); // $ target=m2
}
}
@@ -1576,11 +1598,18 @@ mod implicit_self_borrow {
fn foo(&self) -> &Self {
self
}
fn bar(&self, x: &Self) -> &Self {
self
}
}
pub fn f() {
let x = MyStruct(S);
x.foo(); // $ target=foo
let x = MyStruct(S);
// `&&x` below is Deref coerced to `&x` (see https://doc.rust-lang.org/std/ops/trait.Deref.html#deref-coercion)
x.bar(&&x); // $ target=bar
}
}