Skip to content

Commit 228b49e

Browse files
Rollup merge of #149151 - mu001999-contrib:test/use-path-kw, r=petrochenkov
Add test for importing path-segment keyword Adding new test to make a snapshot of current compiler's behavior. See #146972 (comment) r? `@petrochenkov`
2 parents b2f5cc7 + 640990f commit 228b49e

File tree

2 files changed

+1495
-0
lines changed

2 files changed

+1495
-0
lines changed
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
//@ edition: 2021
2+
3+
macro_rules! macro_dollar_crate {
4+
() => {
5+
use $crate::*;
6+
use $crate::{};
7+
8+
type A1 = $crate; //~ ERROR expected type, found module `$crate`
9+
use $crate; //~ ERROR `$crate` may not be imported
10+
pub use $crate as _dollar_crate; //~ ERROR `$crate` may not be imported
11+
12+
type A2 = ::$crate; //~ ERROR failed to resolve: global paths cannot start with `$crate`
13+
use ::$crate; //~ ERROR unresolved import `$crate`
14+
use ::$crate as _dollar_crate2; //~ ERROR unresolved import `$crate`
15+
use ::{$crate}; //~ ERROR unresolved import `$crate`
16+
use ::{$crate as _nested_dollar_crate2}; //~ ERROR unresolved import `$crate`
17+
18+
type A3 = foobar::$crate; //~ ERROR failed to resolve: `$crate` in paths can only be used in start position
19+
use foobar::$crate; //~ ERROR unresolved import `foobar::$crate`
20+
use foobar::$crate as _dollar_crate3; //~ ERROR unresolved import `foobar::$crate`
21+
use foobar::{$crate}; //~ ERROR unresolved import `foobar::$crate`
22+
use foobar::{$crate as _nested_dollar_crate3}; //~ ERROR unresolved import `foobar::$crate`
23+
24+
type A4 = crate::$crate; //~ ERROR failed to resolve: `$crate` in paths can only be used in start position
25+
use crate::$crate; //~ ERROR unresolved import `crate::$crate`
26+
use crate::$crate as _dollar_crate4; //~ ERROR unresolved import `crate::$crate`
27+
use crate::{$crate}; //~ ERROR unresolved import `crate::$crate`
28+
use crate::{$crate as _nested_dollar_crate4}; //~ ERROR unresolved import `crate::$crate`
29+
30+
type A5 = super::$crate; //~ ERROR failed to resolve: `$crate` in paths can only be used in start position
31+
use super::$crate; //~ ERROR unresolved import `super::$crate`
32+
use super::$crate as _dollar_crate5; //~ ERROR unresolved import `super::$crate`
33+
use super::{$crate}; //~ ERROR unresolved import `super::$crate`
34+
use super::{$crate as _nested_dollar_crate5}; //~ ERROR unresolved import `super::$crate`
35+
36+
type A6 = self::$crate; //~ ERROR failed to resolve: `$crate` in paths can only be used in start position
37+
use self::$crate;
38+
use self::$crate as _dollar_crate6;
39+
use self::{$crate};
40+
use self::{$crate as _nested_dollar_crate6};
41+
42+
type A7 = $crate::$crate; //~ ERROR failed to resolve: `$crate` in paths can only be used in start position
43+
use $crate::$crate; //~ ERROR unresolved import `$crate::$crate`
44+
use $crate::$crate as _dollar_crate7; //~ ERROR unresolved import `$crate::$crate`
45+
use $crate::{$crate}; //~ ERROR unresolved import `$crate::$crate`
46+
use $crate::{$crate as _nested_dollar_crate7}; //~ ERROR unresolved import `$crate::$crate`
47+
48+
type A8 = $crate::crate; //~ ERROR failed to resolve: `crate` in paths can only be used in start position
49+
use $crate::crate; //~ ERROR unresolved import `$crate::crate`
50+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
51+
use $crate::crate as _m_crate8; //~ ERROR unresolved import `$crate::crate`
52+
use $crate::{crate}; //~ ERROR unresolved import `$crate::crate`
53+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
54+
use $crate::{crate as _m_nested_crate8}; //~ ERROR unresolved import `$crate::crate`
55+
56+
type A9 = $crate::super; //~ ERROR failed to resolve: `super` in paths can only be used in start position
57+
use $crate::super; //~ ERROR unresolved import `$crate::super`
58+
use $crate::super as _m_super8; //~ ERROR unresolved import `$crate::super`
59+
use $crate::{super}; //~ ERROR unresolved import `$crate::super`
60+
use $crate::{super as _m_nested_super8}; //~ ERROR unresolved import `$crate::super`
61+
62+
type A10 = $crate::self; //~ ERROR failed to resolve: `self` in paths can only be used in start position
63+
use $crate::self; //~ ERROR `$crate` may not be imported
64+
//~^ ERROR `self` imports are only allowed within a { } list
65+
//~^^ ERROR the name `<!dummy!>` is defined multiple times
66+
pub use $crate::self as _m_self8; //~ ERROR `self` imports are only allowed within a { } list
67+
//~^ ERROR `$crate` may not be imported
68+
use $crate::{self};
69+
//~^ ERROR the name `$crate` is defined multiple times
70+
pub use $crate::{self as _m_nested_self8}; // Good
71+
}
72+
}
73+
74+
fn outer() {}
75+
76+
mod foo {
77+
pub mod bar {
78+
pub mod foobar {
79+
pub mod qux {
80+
pub use super::inner;
81+
}
82+
83+
pub mod baz {
84+
pub use super::inner;
85+
}
86+
87+
pub fn inner() {}
88+
}
89+
90+
// --- $crate ---
91+
macro_dollar_crate!();
92+
93+
// --- crate ---
94+
use crate::*;
95+
use crate::{};
96+
97+
type B1 = crate; //~ ERROR expected type, found module `crate`
98+
use crate; //~ ERROR crate root imports need to be explicitly named: `use crate as name;`
99+
pub use crate as _crate; // Good
100+
101+
type B2 = ::crate; //~ ERROR failed to resolve: global paths cannot start with `crate`
102+
use ::crate; //~ ERROR crate root imports need to be explicitly named: `use crate as name;`
103+
//~^ ERROR unresolved import `crate`
104+
use ::crate as _crate2; //~ ERROR unresolved import `crate`
105+
use ::{crate}; //~ ERROR crate root imports need to be explicitly named: `use crate as name;`
106+
//~^ ERROR unresolved import `crate`
107+
use ::{crate as _nested_crate2}; //~ ERROR unresolved import `crate`
108+
109+
type B3 = foobar::crate; //~ ERROR failed to resolve: `crate` in paths can only be used in start position
110+
use foobar::crate; //~ ERROR unresolved import `foobar::crate`
111+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
112+
use foobar::crate as _crate3; //~ ERROR unresolved import `foobar::crate`
113+
use foobar::{crate}; //~ ERROR unresolved import `foobar::crate`
114+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
115+
use foobar::{crate as _nested_crate3}; //~ ERROR unresolved import `foobar::crate`
116+
117+
type B4 = crate::crate; //~ ERROR failed to resolve: `crate` in paths can only be used in start position
118+
use crate::crate; //~ ERROR unresolved import `crate::crate`
119+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
120+
use crate::crate as _crate4; //~ ERROR unresolved import `crate::crate`
121+
use crate::{crate}; //~ ERROR unresolved import `crate::crate`
122+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
123+
use crate::{crate as _nested_crate4}; //~ ERROR unresolved import `crate::crate`
124+
125+
type B5 = super::crate; //~ ERROR failed to resolve: `crate` in paths can only be used in start position
126+
use super::crate; //~ ERROR unresolved import `super::crate`
127+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
128+
use super::crate as _crate5; //~ ERROR unresolved import `super::crate`
129+
use super::{crate}; //~ ERROR unresolved import `super::crate`
130+
//~^ ERROR crate root imports need to be explicitly named: `use crate as name;`
131+
use super::{crate as _nested_crate5}; //~ ERROR unresolved import `super::crate`
132+
133+
type B6 = self::crate; //~ ERROR failed to resolve: `crate` in paths can only be used in start position
134+
use self::crate; //~ ERROR crate root imports need to be explicitly named: `use crate as name;`
135+
//~^ ERROR the name `crate` is defined multiple times
136+
use self::crate as _crate6;
137+
use self::{crate}; //~ ERROR crate root imports need to be explicitly named: `use crate as name;`
138+
//~^ ERROR the name `crate` is defined multiple times
139+
use self::{crate as _nested_crate6};
140+
141+
// --- super ---
142+
use super::*;
143+
use super::{}; //~ ERROR unresolved import `super`
144+
145+
type C1 = super; //~ ERROR expected type, found module `super`
146+
use super; //~ ERROR unresolved import `super`
147+
pub use super as _super; //~ ERROR unresolved import `super`
148+
149+
type C2 = ::super; //~ ERROR failed to resolve: global paths cannot start with `super`
150+
use ::super; //~ ERROR unresolved import `super`
151+
use ::super as _super2; //~ ERROR unresolved import `super`
152+
use ::{super}; //~ ERROR unresolved import `super`
153+
use ::{super as _nested_super2}; //~ ERROR unresolved import `super`
154+
155+
type C3 = foobar::super; //~ ERROR failed to resolve: `super` in paths can only be used in start position
156+
use foobar::super; //~ ERROR unresolved import `foobar::super`
157+
use foobar::super as _super3; //~ ERROR unresolved import `foobar::super`
158+
use foobar::{super}; //~ ERROR unresolved import `foobar::super`
159+
use foobar::{super as _nested_super3}; //~ ERROR unresolved import `foobar::super`
160+
161+
type C4 = crate::super; //~ ERROR failed to resolve: `super` in paths can only be used in start position
162+
use crate::super; //~ ERROR unresolved import `crate::super`
163+
use crate::super as _super4; //~ ERROR unresolved import `crate::super`
164+
use crate::{super}; //~ ERROR unresolved import `crate::super`
165+
use crate::{super as _nested_super4}; //~ ERROR unresolved import `crate::super`
166+
167+
type C5 = super::super; //~ ERROR expected type, found module `super::super`
168+
use super::super; //~ ERROR unresolved import `super::super`
169+
pub use super::super as _super5; //~ ERROR unresolved import `super::super`
170+
use super::{super}; //~ ERROR unresolved import `super::super`
171+
pub use super::{super as _nested_super5}; //~ ERROR unresolved import `super::super`
172+
173+
type C6 = self::super; //~ ERROR expected type, found module `self::super`
174+
use self::super;
175+
use self::super as _super6;
176+
use self::{super};
177+
use self::{super as _nested_super6};
178+
179+
// --- self ---
180+
// use self::*; // Suppress other errors
181+
use self::{}; //~ ERROR unresolved import `self`
182+
183+
type D1 = self; //~ ERROR expected type, found module `self`
184+
use self; //~ ERROR `self` imports are only allowed within a { } list
185+
pub use self as _self; //~ ERROR `self` imports are only allowed within a { } list
186+
187+
type D2 = ::self; //~ ERROR failed to resolve: global paths cannot start with `self`
188+
use ::self; //~ ERROR `self` imports are only allowed within a { } list
189+
//~^ ERROR unresolved import `{{root}}`
190+
use ::self as _self2; //~ ERROR `self` imports are only allowed within a { } list
191+
//~^ ERROR unresolved import `{{root}}`
192+
use ::{self}; //~ ERROR `self` import can only appear in an import list with a non-empty prefix
193+
use ::{self as _nested_self2}; //~ ERROR `self` import can only appear in an import list with a non-empty prefix
194+
195+
type D3 = foobar::self; //~ ERROR failed to resolve: `self` in paths can only be used in start position
196+
pub use foobar::qux::self; //~ ERROR `self` imports are only allowed within a { } list
197+
pub use foobar::self as _self3; //~ ERROR `self` imports are only allowed within a { } list
198+
pub use foobar::baz::{self}; // Good
199+
pub use foobar::{self as _nested_self3}; // Good
200+
201+
type D4 = crate::self; //~ ERROR failed to resolve: `self` in paths can only be used in start position
202+
use crate::self; //~ ERROR crate root imports need to be explicitly named: `use crate as name;`
203+
//~^ ERROR `self` imports are only allowed within a { } list
204+
//~^^ ERROR the name `crate` is defined multiple times
205+
pub use crate::self as _self4; //~ ERROR `self` imports are only allowed within a { } list
206+
use crate::{self}; //~ ERROR crate root imports need to be explicitly named: `use crate as name;`
207+
//~^ ERROR the name `crate` is defined multiple times
208+
pub use crate::{self as _nested_self4}; // Good
209+
210+
type D5 = super::self; //~ ERROR failed to resolve: `self` in paths can only be used in start position
211+
use super::self; //~ ERROR unresolved import `super`
212+
//~^ ERROR `self` imports are only allowed within a { } list
213+
pub use super::self as _self5; //~ ERROR `self` imports are only allowed within a { } list
214+
//~^ ERROR unresolved import `super`
215+
use super::{self}; //~ ERROR unresolved import `super`
216+
pub use super::{self as _nested_self5}; //~ ERROR unresolved import `super`
217+
218+
type D6 = self::self; //~ ERROR failed to resolve: `self` in paths can only be used in start position
219+
use self::self; //~ ERROR `self` imports are only allowed within a { } list
220+
pub use self::self as _self6; //~ ERROR `self` imports are only allowed within a { } list
221+
use self::{self}; //~ ERROR unresolved import `self`
222+
pub use self::{self as _nested_self6}; //~ ERROR unresolved import `self`
223+
}
224+
}
225+
226+
fn main() {
227+
foo::bar::_dollar_crate::outer();
228+
foo::bar::_m_self8::outer();
229+
foo::bar::_dollar_crate::foo::bar::foobar::inner();
230+
foo::bar::_m_self8::foo::bar::foobar::inner();
231+
232+
foo::bar::_crate::outer();
233+
foo::bar::_crate::foo::bar::foobar::inner();
234+
235+
foo::bar::_super::bar::foobar::inner();
236+
foo::bar::_super5::outer();
237+
foo::bar::_nested_super5::outer();
238+
239+
foo::bar::_self::foobar::inner();
240+
foo::bar::qux::inner(); // Works after recovery
241+
foo::bar::baz::inner();
242+
foo::bar::_self3::inner(); // Works after recovery
243+
foo::bar::_nested_self3::inner();
244+
foo::bar::_self4::outer(); // Works after recovery
245+
foo::bar::_nested_self4::outer();
246+
foo::bar::_self5::bar::foobar::inner(); // Works after recovery
247+
foo::bar::_nested_self5::bar::foobar::inner();
248+
foo::bar::_self6::foobar::inner(); // Works after recovery
249+
foo::bar::_nested_self6::foobar::inner();
250+
}

0 commit comments

Comments
 (0)