Skip to content

Commit 4513106

Browse files
committed
Rust: Add type inference test for inherent implementation shadowing trait implementation
1 parent e45b5c5 commit 4513106

File tree

3 files changed

+982
-916
lines changed

3 files changed

+982
-916
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
multipleMethodCallTargets
2+
| main.rs:401:26:401:42 | x.common_method() | main.rs:376:9:379:9 | fn common_method |
3+
| main.rs:401:26:401:42 | x.common_method() | main.rs:388:9:391:9 | fn common_method |
4+
| main.rs:402:26:402:44 | x.common_method_2() | main.rs:381:9:384:9 | fn common_method_2 |
5+
| main.rs:402:26:402:44 | x.common_method_2() | main.rs:393:9:396:9 | fn common_method_2 |

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,47 @@ mod method_non_parametric_trait_impl {
362362
}
363363
}
364364

365+
mod impl_overlap {
366+
#[derive(Debug, Clone, Copy)]
367+
struct S1;
368+
369+
trait OverlappingTrait {
370+
fn common_method(self) -> S1;
371+
372+
fn common_method_2(self, s1: S1) -> S1;
373+
}
374+
375+
impl OverlappingTrait for S1 {
376+
// <S1_as_OverlappingTrait>::common_method
377+
fn common_method(self) -> S1 {
378+
panic!("not called");
379+
}
380+
381+
// <S1_as_OverlappingTrait>::common_method_2
382+
fn common_method_2(self, s1: S1) -> S1 {
383+
panic!("not called");
384+
}
385+
}
386+
387+
impl S1 {
388+
// S1::common_method
389+
fn common_method(self) -> S1 {
390+
self
391+
}
392+
393+
// S1::common_method_2
394+
fn common_method_2(self) -> S1 {
395+
self
396+
}
397+
}
398+
399+
pub fn f() {
400+
let x = S1;
401+
println!("{:?}", x.common_method()); // $ method=S1::common_method SPURIOUS: method=<S1_as_OverlappingTrait>::common_method
402+
println!("{:?}", x.common_method_2()); // $ method=S1::common_method_2 SPURIOUS: method=<S1_as_OverlappingTrait>::common_method_2
403+
}
404+
}
405+
365406
mod type_parameter_bounds {
366407
use std::fmt::Debug;
367408

0 commit comments

Comments
 (0)