mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
Rust: Add type inference tests for impl trait types
This commit is contained in:
@@ -1873,8 +1873,10 @@ mod async_ {
|
||||
}
|
||||
|
||||
mod impl_trait {
|
||||
#[derive(Copy, Clone)]
|
||||
struct S1;
|
||||
struct S2;
|
||||
struct S3<T3>(T3);
|
||||
|
||||
trait Trait1 {
|
||||
fn f1(&self) {} // Trait1f1
|
||||
@@ -1906,6 +1908,13 @@ mod impl_trait {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone> MyTrait<T> for S3<T> {
|
||||
fn get_a(&self) -> T {
|
||||
let S3(t) = self;
|
||||
t.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_a_my_trait() -> impl MyTrait<S2> {
|
||||
S1
|
||||
}
|
||||
@@ -1914,6 +1923,14 @@ mod impl_trait {
|
||||
t.get_a() // $ target=MyTrait::get_a
|
||||
}
|
||||
|
||||
fn get_a_my_trait2<T: Clone>(x: T) -> impl MyTrait<T> {
|
||||
S3(x)
|
||||
}
|
||||
|
||||
fn get_a_my_trait3<T: Clone>(x: T) -> Option<impl MyTrait<T>> {
|
||||
Some(S3(x))
|
||||
}
|
||||
|
||||
fn uses_my_trait2<A>(t: impl MyTrait<A>) -> A {
|
||||
t.get_a() // $ target=MyTrait::get_a
|
||||
}
|
||||
@@ -1927,6 +1944,9 @@ mod impl_trait {
|
||||
let a = get_a_my_trait(); // $ target=get_a_my_trait
|
||||
let c = uses_my_trait2(a); // $ type=c:S2 target=uses_my_trait2
|
||||
let d = uses_my_trait2(S1); // $ type=d:S2 target=uses_my_trait2
|
||||
let e = get_a_my_trait2(S1).get_a(); // $ target=get_a_my_trait2 target=MyTrait::get_a MISSING: type=e:S1
|
||||
// For this function the `impl` type does not appear in the root of the return type
|
||||
let f = get_a_my_trait3(S1).unwrap().get_a(); // $ target=get_a_my_trait3 target=unwrap MISSING: target=MyTrait::get_a type=f:S1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2385,7 +2405,7 @@ mod tuples {
|
||||
|
||||
let pair = [1, 1].into(); // $ type=pair:(T_2) type=pair:0(2).i32 type=pair:1(2).i32 MISSING: target=into
|
||||
match pair {
|
||||
(0,0) => print!("unexpected"),
|
||||
(0, 0) => print!("unexpected"),
|
||||
_ => print!("expected"),
|
||||
}
|
||||
let x = pair.0; // $ type=x:i32
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user