File tree Expand file tree Collapse file tree
rust/ql/test/library-tests/path-resolution Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,3 +4,15 @@ struct A; // A1
44struct A ; // A2
55
66fn f ( x : A ) { } // $ item=A2 (the latter occurence takes precedence)
7+
8+ /// Test `m::{self}` where `m` is a struct. Per the Rust specification `m` must
9+ /// resolve to a module, trait, or enum:
10+ /// https://doc.rust-lang.org/reference/items/use-declarations.html#r-items.use.self.module
11+ mod self_import_from_struct {
12+ struct MyStruct ; // Struct
13+
14+ #[ rustfmt:: skip]
15+ use self :: MyStruct :: { // $ item=Struct
16+ self // $ SPURIOUS: item=Struct
17+ } ;
18+ }
Original file line number Diff line number Diff line change @@ -685,29 +685,38 @@ mod m18 {
685685 }
686686}
687687
688- mod m21 {
689- mod m22 {
688+ /// Test importing modules, traits, and enums with `{self}`.
689+ mod self_imports {
690+ mod definitions {
691+ pub mod my_module {
692+ pub fn f ( ) { } // I107
693+ } // I104
694+ pub trait MyTrait { } // I105
690695 pub enum MyEnum {
691- A , // I104
692- } // I105
696+ A , // I108
697+ } // I106
698+ }
693699
694- pub struct MyStruct ; // I106
695- } // I107
700+ mod imports {
701+ #[ rustfmt:: skip]
702+ use super :: definitions:: my_module:: { // $ item=I104
703+ self // $ item=I104
704+ } ;
696705
697- mod m33 {
698706 #[ rustfmt:: skip]
699- use super :: m22 :: MyEnum :: { // $ item=I105
700- self // $ item=I105
707+ use super :: definitions :: MyTrait :: { // $ item=I105
708+ self // $ MISSING: item=I105 SPURIOUS: item=definitions
701709 } ;
702710
703711 #[ rustfmt:: skip]
704- use super :: m22 :: MyStruct :: { // $ item=I106
712+ use super :: definitions :: MyEnum :: { // $ item=I106
705713 self // $ item=I106
706714 } ;
707715
708- fn f ( ) {
709- let _ = MyEnum :: A ; // $ item=I104
710- let _ = MyStruct { } ; // $ item=I106
716+ #[ rustfmt:: skip]
717+ fn f < T : MyTrait > ( ) { // $ MISSING: item=I105
718+ my_module:: f ( ) ; // $ item=I107
719+ let _ = MyEnum :: A ; // $ item=I108
711720 }
712721 }
713722}
You can’t perform that action at this time.
0 commit comments