Skip to content

Commit bb75c20

Browse files
petrochenkovMark-Simulacrum
authored andcommitted
resolve: Always resolve visibilities on impl items
1 parent b509d9b commit bb75c20

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
658658
self.r.define(parent, ident, TypeNS, imported_binding);
659659
}
660660

661-
ItemKind::GlobalAsm(..) => {}
662-
663661
ItemKind::Mod(..) if ident.name == kw::Invalid => {} // Crate root
664662

665663
ItemKind::Mod(..) => {
@@ -678,9 +676,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
678676
self.parent_scope.module = module;
679677
}
680678

681-
// Handled in `rustc_metadata::{native_libs,link_args}`
682-
ItemKind::ForeignMod(..) => {}
683-
684679
// These items live in the value namespace.
685680
ItemKind::Static(..) => {
686681
let res = Res::Def(DefKind::Static, self.r.definitions.local_def_id(item.id));
@@ -781,12 +776,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
781776
self.insert_field_names(item_def_id, field_names);
782777
}
783778

784-
ItemKind::Impl(.., ref impl_items) => {
785-
for impl_item in impl_items {
786-
self.resolve_visibility(&impl_item.vis);
787-
}
788-
}
789-
790779
ItemKind::Trait(..) => {
791780
let def_id = self.r.definitions.local_def_id(item.id);
792781

@@ -801,6 +790,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
801790
self.parent_scope.module = module;
802791
}
803792

793+
// These items do not add names to modules.
794+
ItemKind::Impl(..) | ItemKind::ForeignMod(..) | ItemKind::GlobalAsm(..) => {}
795+
804796
ItemKind::MacroDef(..) | ItemKind::Mac(_) => unreachable!(),
805797
}
806798
}
@@ -1134,7 +1126,6 @@ macro_rules! method {
11341126
}
11351127

11361128
impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
1137-
method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item);
11381129
method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
11391130
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);
11401131
method!(visit_ty: ast::Ty, ast::TyKind::Mac, walk_ty);
@@ -1218,6 +1209,15 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
12181209
visit::walk_trait_item(self, item);
12191210
}
12201211

1212+
fn visit_impl_item(&mut self, item: &'b ast::ImplItem) {
1213+
if let ast::ImplItemKind::Macro(..) = item.kind {
1214+
self.visit_invoc(item.id);
1215+
} else {
1216+
self.resolve_visibility(&item.vis);
1217+
visit::walk_impl_item(self, item);
1218+
}
1219+
}
1220+
12211221
fn visit_token(&mut self, t: Token) {
12221222
if let token::Interpolated(nt) = t.kind {
12231223
if let token::NtExpr(ref expr) = *nt {
Lines changed: 25 additions & 0 deletions
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() {}
Lines changed: 9 additions & 0 deletions
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)