Skip to content

Commit 1709a85

Browse files
Store resolution for self and crate root module segments
1 parent 9260be3 commit 1709a85

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

compiler/rustc_resolve/src/ident.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,9 +1511,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15111511
if segment_idx == 0 {
15121512
if name == kw::SelfLower {
15131513
let mut ctxt = ident.span.ctxt().normalize_to_macros_2_0();
1514-
module = Some(ModuleOrUniformRoot::Module(
1515-
self.resolve_self(&mut ctxt, parent_scope.module),
1516-
));
1514+
let self_mod = self.resolve_self(&mut ctxt, parent_scope.module);
1515+
if let Some(res) = self_mod.res() {
1516+
record_segment_res(self, res);
1517+
}
1518+
module = Some(ModuleOrUniformRoot::Module(self_mod));
15171519
continue;
15181520
}
15191521
if name == kw::PathRoot && ident.span.at_least_rust_2018() {
@@ -1530,7 +1532,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15301532
}
15311533
if name == kw::PathRoot || name == kw::Crate || name == kw::DollarCrate {
15321534
// `::a::b`, `crate::a::b` or `$crate::a::b`
1533-
module = Some(ModuleOrUniformRoot::Module(self.resolve_crate_root(ident)));
1535+
let crate_root = self.resolve_crate_root(ident);
1536+
if let Some(res) = crate_root.res() {
1537+
record_segment_res(self, res);
1538+
}
1539+
module = Some(ModuleOrUniformRoot::Module(crate_root));
15341540
continue;
15351541
}
15361542
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct Ty;
2+
3+
fn self_(_: self::<i32>::Ty) {}
4+
//~^ ERROR type arguments are not allowed on module `generics_on_self_mod_segment`
5+
6+
fn crate_(_: crate::<i32>::Ty) {}
7+
//~^ ERROR type arguments are not allowed on module `generics_on_self_mod_segment`
8+
9+
macro_rules! dollar_crate {
10+
() => {
11+
fn dollar_crate_(_: $crate::<i32>::Ty) {}
12+
//~^ ERROR type arguments are not allowed on module `generics_on_self_mod_segment`
13+
}
14+
}
15+
16+
dollar_crate!();
17+
18+
fn main() {}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0109]: type arguments are not allowed on module `generics_on_self_mod_segment`
2+
--> $DIR/generics-on-self-mod-segment.rs:3:20
3+
|
4+
LL | fn self_(_: self::<i32>::Ty) {}
5+
| ---- ^^^ type argument not allowed
6+
| |
7+
| not allowed on module `generics_on_self_mod_segment`
8+
9+
error[E0109]: type arguments are not allowed on module `generics_on_self_mod_segment`
10+
--> $DIR/generics-on-self-mod-segment.rs:6:22
11+
|
12+
LL | fn crate_(_: crate::<i32>::Ty) {}
13+
| ----- ^^^ type argument not allowed
14+
| |
15+
| not allowed on module `generics_on_self_mod_segment`
16+
17+
error[E0109]: type arguments are not allowed on module `generics_on_self_mod_segment`
18+
--> $DIR/generics-on-self-mod-segment.rs:11:38
19+
|
20+
LL | fn dollar_crate_(_: $crate::<i32>::Ty) {}
21+
| ------ ^^^ type argument not allowed
22+
| |
23+
| not allowed on module `generics_on_self_mod_segment`
24+
...
25+
LL | dollar_crate!();
26+
| --------------- in this macro invocation
27+
|
28+
= note: this error originates in the macro `dollar_crate` (in Nightly builds, run with -Z macro-backtrace for more info)
29+
30+
error: aborting due to 3 previous errors
31+
32+
For more information about this error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)