Skip to content

Commit 0f286e8

Browse files
authored
Rollup merge of #67236 - petrochenkov:docerr2, r=matthewjasper
resolve: Always resolve visibilities on impl items Fixes #64705. Similarly to #67106 this was an issue with visitor discipline. Impl items were visited as a part of visiting `ast::ItemKind::Impl`, but they should be visit-able in isolation from their parents as well, because that's how they are visited when they are expanded from macros. I've checked that all the remaining `resolve_visibility` calls are used correctly. r? @matthewjasper
2 parents 3cf7996 + 914c9aa commit 0f286e8

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

src/librustc_resolve/build_reduced_graph.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
647647
self.r.define(parent, ident, TypeNS, imported_binding);
648648
}
649649

650-
ItemKind::GlobalAsm(..) => {}
651-
652650
ItemKind::Mod(..) if ident.name == kw::Invalid => {} // Crate root
653651

654652
ItemKind::Mod(..) => {
@@ -667,9 +665,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
667665
self.parent_scope.module = module;
668666
}
669667

670-
// Handled in `rustc_metadata::{native_libs,link_args}`
671-
ItemKind::ForeignMod(..) => {}
672-
673668
// These items live in the value namespace.
674669
ItemKind::Static(..) => {
675670
let res = Res::Def(DefKind::Static, self.r.definitions.local_def_id(item.id));
@@ -765,12 +760,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
765760
self.insert_field_names_local(def_id, vdata);
766761
}
767762

768-
ItemKind::Impl(.., ref impl_items) => {
769-
for impl_item in impl_items {
770-
self.resolve_visibility(&impl_item.vis);
771-
}
772-
}
773-
774763
ItemKind::Trait(..) => {
775764
let def_id = self.r.definitions.local_def_id(item.id);
776765

@@ -785,6 +774,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
785774
self.parent_scope.module = module;
786775
}
787776

777+
// These items do not add names to modules.
778+
ItemKind::Impl(..) | ItemKind::ForeignMod(..) | ItemKind::GlobalAsm(..) => {}
779+
788780
ItemKind::MacroDef(..) | ItemKind::Mac(_) => unreachable!(),
789781
}
790782
}
@@ -1118,7 +1110,6 @@ macro_rules! method {
11181110
}
11191111

11201112
impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
1121-
method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item);
11221113
method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
11231114
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);
11241115
method!(visit_ty: ast::Ty, ast::TyKind::Mac, walk_ty);
@@ -1202,6 +1193,15 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
12021193
visit::walk_trait_item(self, item);
12031194
}
12041195

1196+
fn visit_impl_item(&mut self, item: &'b ast::ImplItem) {
1197+
if let ast::ImplItemKind::Macro(..) = item.kind {
1198+
self.visit_invoc(item.id);
1199+
} else {
1200+
self.resolve_visibility(&item.vis);
1201+
visit::walk_impl_item(self, item);
1202+
}
1203+
}
1204+
12051205
fn visit_token(&mut self, t: Token) {
12061206
if let token::Interpolated(nt) = t.kind {
12071207
if let token::NtExpr(ref expr) = *nt {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Visibilities on impl items expanded from macros are resolved (issue #64705).
2+
3+
macro_rules! perftools_inline {
4+
($($item:tt)*) => (
5+
$($item)*
6+
);
7+
}
8+
9+
mod state {
10+
pub struct RawFloatState;
11+
impl RawFloatState {
12+
perftools_inline! {
13+
pub(super) fn new() {} // OK
14+
}
15+
}
16+
}
17+
18+
pub struct RawFloatState;
19+
impl RawFloatState {
20+
perftools_inline! {
21+
pub(super) fn new() {} //~ ERROR failed to resolve: there are too many initial `super`s
22+
}
23+
}
24+
25+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: there are too many initial `super`s.
2+
--> $DIR/impl-items-vis-unresolved.rs:21:13
3+
|
4+
LL | pub(super) fn new() {}
5+
| ^^^^^ there are too many initial `super`s.
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)