Rollup merge of #67236 - petrochenkov:docerr2, r=matthewjasper
resolve: Always resolve visibilities on impl items Fixes https://github.com/rust-lang/rust/issues/64705. Similarly to https://github.com/rust-lang/rust/pull/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
This commit is contained in:
commit
0f286e855f
3 changed files with 46 additions and 12 deletions
|
|
@ -647,8 +647,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
self.r.define(parent, ident, TypeNS, imported_binding);
|
||||
}
|
||||
|
||||
ItemKind::GlobalAsm(..) => {}
|
||||
|
||||
ItemKind::Mod(..) if ident.name == kw::Invalid => {} // Crate root
|
||||
|
||||
ItemKind::Mod(..) => {
|
||||
|
|
@ -667,9 +665,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
self.parent_scope.module = module;
|
||||
}
|
||||
|
||||
// Handled in `rustc_metadata::{native_libs,link_args}`
|
||||
ItemKind::ForeignMod(..) => {}
|
||||
|
||||
// These items live in the value namespace.
|
||||
ItemKind::Static(..) => {
|
||||
let res = Res::Def(DefKind::Static, self.r.definitions.local_def_id(item.id));
|
||||
|
|
@ -765,12 +760,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
self.insert_field_names_local(def_id, vdata);
|
||||
}
|
||||
|
||||
ItemKind::Impl(.., ref impl_items) => {
|
||||
for impl_item in impl_items {
|
||||
self.resolve_visibility(&impl_item.vis);
|
||||
}
|
||||
}
|
||||
|
||||
ItemKind::Trait(..) => {
|
||||
let def_id = self.r.definitions.local_def_id(item.id);
|
||||
|
||||
|
|
@ -785,6 +774,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
|||
self.parent_scope.module = module;
|
||||
}
|
||||
|
||||
// These items do not add names to modules.
|
||||
ItemKind::Impl(..) | ItemKind::ForeignMod(..) | ItemKind::GlobalAsm(..) => {}
|
||||
|
||||
ItemKind::MacroDef(..) | ItemKind::Mac(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
@ -1118,7 +1110,6 @@ macro_rules! method {
|
|||
}
|
||||
|
||||
impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
|
||||
method!(visit_impl_item: ast::ImplItem, ast::ImplItemKind::Macro, walk_impl_item);
|
||||
method!(visit_expr: ast::Expr, ast::ExprKind::Mac, walk_expr);
|
||||
method!(visit_pat: ast::Pat, ast::PatKind::Mac, walk_pat);
|
||||
method!(visit_ty: ast::Ty, ast::TyKind::Mac, walk_ty);
|
||||
|
|
@ -1202,6 +1193,15 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
|
|||
visit::walk_trait_item(self, item);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, item: &'b ast::ImplItem) {
|
||||
if let ast::ImplItemKind::Macro(..) = item.kind {
|
||||
self.visit_invoc(item.id);
|
||||
} else {
|
||||
self.resolve_visibility(&item.vis);
|
||||
visit::walk_impl_item(self, item);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_token(&mut self, t: Token) {
|
||||
if let token::Interpolated(nt) = t.kind {
|
||||
if let token::NtExpr(ref expr) = *nt {
|
||||
|
|
|
|||
25
src/test/ui/resolve/impl-items-vis-unresolved.rs
Normal file
25
src/test/ui/resolve/impl-items-vis-unresolved.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
// Visibilities on impl items expanded from macros are resolved (issue #64705).
|
||||
|
||||
macro_rules! perftools_inline {
|
||||
($($item:tt)*) => (
|
||||
$($item)*
|
||||
);
|
||||
}
|
||||
|
||||
mod state {
|
||||
pub struct RawFloatState;
|
||||
impl RawFloatState {
|
||||
perftools_inline! {
|
||||
pub(super) fn new() {} // OK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RawFloatState;
|
||||
impl RawFloatState {
|
||||
perftools_inline! {
|
||||
pub(super) fn new() {} //~ ERROR failed to resolve: there are too many initial `super`s
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
9
src/test/ui/resolve/impl-items-vis-unresolved.stderr
Normal file
9
src/test/ui/resolve/impl-items-vis-unresolved.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0433]: failed to resolve: there are too many initial `super`s.
|
||||
--> $DIR/impl-items-vis-unresolved.rs:21:13
|
||||
|
|
||||
LL | pub(super) fn new() {}
|
||||
| ^^^^^ there are too many initial `super`s.
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0433`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue