Rust: Add type inference tests with default for type parameters

This commit is contained in:
Simon Friis Vindum
2025-06-13 14:18:37 +02:00
parent 2a51749a31
commit 1425bb8b08
2 changed files with 2675 additions and 2640 deletions

View File

@@ -14,7 +14,7 @@ mod field_access {
}
#[derive(Debug)]
struct GenericThing<A> {
struct GenericThing<A = bool> {
a: A,
}
@@ -27,6 +27,11 @@ mod field_access {
println!("{:?}", x.a); // $ fieldof=MyThing
}
fn default_field_access(x: GenericThing) {
let a = x.a; // $ fieldof=GenericThing MISSING: type=a:bool
println!("{:?}", a);
}
fn generic_field_access() {
// Explicit type argument
let x = GenericThing::<S> { a: S }; // $ type=x:A.S
@@ -472,7 +477,7 @@ mod type_parameter_bounds {
println!("{:?}", s); // $ type=s:S1
}
trait Pair<P1, P2> {
trait Pair<P1 = bool, P2 = i64> {
fn fst(self) -> P1;
fn snd(self) -> P2;
@@ -480,8 +485,8 @@ mod type_parameter_bounds {
fn call_trait_per_bound_with_type_1<T: Pair<S1, S2>>(x: T, y: T) {
// The type in the type parameter bound determines the return type.
let s1 = x.fst(); // $ method=fst
let s2 = y.snd(); // $ method=snd
let s1 = x.fst(); // $ method=fst type=s1:S1
let s2 = y.snd(); // $ method=snd type=s2:S2
println!("{:?}, {:?}", s1, s2);
}
@@ -491,6 +496,20 @@ mod type_parameter_bounds {
let s2 = y.snd(); // $ method=snd
println!("{:?}, {:?}", s1, s2);
}
fn call_trait_per_bound_with_type_3<T: Pair>(x: T, y: T) {
// The type in the type parameter bound determines the return type.
let s1 = x.fst(); // $ method=fst MISSING: type=s1:bool
let s2 = y.snd(); // $ method=snd MISSING: type=s2:i64
println!("{:?}, {:?}", s1, s2);
}
fn call_trait_per_bound_with_type_4<T: Pair<u8>>(x: T, y: T) {
// The type in the type parameter bound determines the return type.
let s1 = x.fst(); // $ method=fst type=s1:u8
let s2 = y.snd(); // $ method=snd MISSING: type=s2:i64
println!("{:?}, {:?}", s1, s2);
}
}
mod function_trait_bounds {