Skip to content

Commit 884b94a

Browse files
committed
Rust: Add examples where trait visibility affects path and method resolution
1 parent b4d6cb6 commit 884b94a

File tree

6 files changed

+4529
-4380
lines changed

6 files changed

+4529
-4380
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
multipleCallTargets
22
| main.rs:118:9:118:11 | f(...) |
3+
| main.rs:494:13:494:27 | ...::a_method(...) |
4+
| main.rs:498:13:498:27 | ...::a_method(...) |
5+
| main.rs:502:13:502:27 | ...::a_method(...) |
36
| proc_macro.rs:9:5:9:10 | ...::new(...) |

rust/ql/test/library-tests/path-resolution/main.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,50 @@ mod m16 {
460460
} // I83
461461
}
462462

463+
mod trait_visibility {
464+
mod m {
465+
pub trait Foo {
466+
fn a_method(&self); // Foo::a_method
467+
} // Foo
468+
469+
pub trait Bar {
470+
fn a_method(&self); // Bar::a_method
471+
} // Bar
472+
473+
pub struct X;
474+
#[rustfmt::skip]
475+
impl Foo for X { // $ item=Foo item=X
476+
fn a_method(&self) {
477+
println!("foo!");
478+
} // X_Foo::a_method
479+
}
480+
#[rustfmt::skip]
481+
impl Bar for X { // $ item=Bar item=X
482+
fn a_method(&self) {
483+
println!("bar!");
484+
} // X_Bar::a_method
485+
}
486+
}
487+
488+
use m::X; // $ item=X
489+
490+
pub fn f() {
491+
let x = X; // $ item=X
492+
{
493+
use m::Foo; // $ item=Foo
494+
X::a_method(&x); // $ item=X_Foo::a_method SPURIOUS: item=X_Bar::a_method
495+
}
496+
{
497+
use m::Bar; // $ item=Bar
498+
X::a_method(&x); // $ item=X_Bar::a_method SPURIOUS: item=X_Foo::a_method
499+
}
500+
{
501+
use m::Bar as _; // $ item=Bar
502+
X::a_method(&x); // $ item=X_Bar::a_method SPURIOUS: item=X_Foo::a_method
503+
}
504+
} // trait_visibility::f
505+
}
506+
463507
mod m17 {
464508
trait MyTrait {
465509
fn f(&self); // I1
@@ -730,6 +774,7 @@ fn main() {
730774
m11::f(); // $ item=I63
731775
m15::f(); // $ item=I75
732776
m16::f(); // $ item=I83
777+
trait_visibility::f(); // $ item=trait_visibility::f
733778
m17::f(); // $ item=I99
734779
nested6::f(); // $ item=I116
735780
nested8::f(); // $ item=I119

0 commit comments

Comments
 (0)