Skip to content

Commit 602e617

Browse files
committed
Rust: Add type inference test for trait with multiple associated types
1 parent 8e76bb1 commit 602e617

File tree

2 files changed

+634
-574
lines changed

2 files changed

+634
-574
lines changed

rust/ql/test/library-tests/type-inference/main.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,18 @@ mod trait_associated_type {
368368
}
369369
}
370370

371+
// A generic trait with multiple associated types.
372+
trait TraitMultipleAssoc<TrG> {
373+
type Assoc1;
374+
type Assoc2;
375+
376+
fn get_zero(&self) -> TrG;
377+
378+
fn get_one(&self) -> Self::Assoc1;
379+
380+
fn get_two(&self) -> Self::Assoc2;
381+
}
382+
371383
#[derive(Debug, Default)]
372384
struct S;
373385

@@ -417,6 +429,23 @@ mod trait_associated_type {
417429
thing.m1() // $ method=MyTrait::m1
418430
}
419431

432+
impl TraitMultipleAssoc<AT> for AT {
433+
type Assoc1 = S;
434+
type Assoc2 = S2;
435+
436+
fn get_zero(&self) -> AT {
437+
AT
438+
}
439+
440+
fn get_one(&self) -> Self::Assoc1 {
441+
S
442+
}
443+
444+
fn get_two(&self) -> Self::Assoc2 {
445+
S2
446+
}
447+
}
448+
420449
pub fn f() {
421450
let x1 = S;
422451
// Call to method in `impl` block
@@ -441,6 +470,10 @@ mod trait_associated_type {
441470
println!("{:?}", x5.m1()); // $ method=m1 MISSING: type=x5.m1():A.S2
442471
let x6 = S2;
443472
println!("{:?}", x6.m2()); // $ method=m2 type=x6.m2():A.S2
473+
474+
let assoc_zero = AT.get_zero(); // $ method=get_zero type=assoc_zero:AT
475+
let assoc_one = AT.get_one(); // $ method=get_one type=assoc_one:S
476+
let assoc_two = AT.get_two(); // $ method=get_two type=assoc_two:S2
444477
}
445478
}
446479

0 commit comments

Comments
 (0)