Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jun 7, 2024
1 parent 4546947 commit cb297a1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 42 deletions.
19 changes: 16 additions & 3 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{Determinacy, ExternPreludeEntry, Finalize, Module, ModuleKind, Modul
use crate::{NameBinding, NameBindingKind, ParentScope, PathResult, ResolutionError};
use crate::{Resolver, ResolverArenas, Segment, ToNameBinding, Used, VisResolutionError};

use rustc_ast::visit::{self, AssocCtxt, Visitor};
use rustc_ast::visit::{self, AssocCtxt, Visitor, WalkItemKind};
use rustc_ast::{self as ast, AssocItem, AssocItemKind, MetaItemKind, StmtKind};
use rustc_ast::{Block, ForeignItem, ForeignItemKind, Impl, Item, ItemKind, NodeId};
use rustc_attr as attr;
Expand Down Expand Up @@ -1312,7 +1312,17 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
_ => {
let orig_macro_rules_scope = self.parent_scope.macro_rules;
self.build_reduced_graph_for_item(item);
visit::walk_item(self, item);
match item.kind {
ItemKind::Mod(..) => {
// Visit attributes after items for backward compatibility.
// This way they can use `macro_rules` defined later.
self.visit_vis(&item.vis);
self.visit_ident(item.ident);
item.kind.walk(item, AssocCtxt::Trait, self);
visit::walk_list!(self, visit_attribute, &item.attrs);
}
_ => visit::walk_item(self, item),
}
match item.kind {
ItemKind::Mod(..) if self.contains_macro_use(&item.attrs) => {
self.parent_scope.macro_rules
Expand Down Expand Up @@ -1502,7 +1512,10 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
if krate.is_placeholder {
self.visit_invoc_in_module(krate.id);
} else {
visit::walk_crate(self, krate);
// Visit attributes after items for backward compatibility.
// This way they can use `macro_rules` defined later.
visit::walk_list!(self, visit_item, &krate.items);
visit::walk_list!(self, visit_attribute, &krate.attrs);
self.contains_macro_use(&krate.attrs);
}
}
Expand Down
13 changes: 8 additions & 5 deletions tests/ui/attributes/key-value-expansion-scope.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![doc = in_root!()] //~ ERROR cannot find macro `in_root` in this scope
#![doc = in_root!()] // ERROR cannot find macro `in_root` in this scope
#![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
#![doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape` in this scope
#![doc = in_mod_escape!()] // ERROR cannot find macro `in_mod_escape` in this scope
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope

#[doc = in_root!()] //~ ERROR cannot find macro `in_root` in this scope
Expand All @@ -16,8 +16,9 @@ fn before() {

macro_rules! in_root { () => { "" } }

#[doc = in_mod!()]
mod macros_stay {
#![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
#![doc = in_mod!()] // ERROR cannot find macro `in_mod` in this scope

macro_rules! in_mod { () => { "" } }

Expand All @@ -28,8 +29,9 @@ mod macros_stay {
}

#[macro_use]
#[doc = in_mod_escape!()]
mod macros_escape {
#![doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape` in this scope
#![doc = in_mod_escape!()] // ERROR cannot find macro `in_mod_escape` in this scope

macro_rules! in_mod_escape { () => { "" } }

Expand All @@ -39,8 +41,9 @@ mod macros_escape {
}
}

#[doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
fn block() {
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope

macro_rules! in_block { () => { "" } }

Expand Down
44 changes: 10 additions & 34 deletions tests/ui/attributes/key-value-expansion-scope.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
error: cannot find macro `in_root` in this scope
--> $DIR/key-value-expansion-scope.rs:1:10
|
LL | #![doc = in_root!()]
| ^^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_mod` in this scope
--> $DIR/key-value-expansion-scope.rs:2:10
|
Expand All @@ -14,14 +6,6 @@ LL | #![doc = in_mod!()]
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_mod_escape` in this scope
--> $DIR/key-value-expansion-scope.rs:3:10
|
LL | #![doc = in_mod_escape!()]
| ^^^^^^^^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_block` in this scope
--> $DIR/key-value-expansion-scope.rs:4:10
|
Expand Down Expand Up @@ -94,61 +78,53 @@ LL | #![doc = in_block!()]
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_mod` in this scope
--> $DIR/key-value-expansion-scope.rs:20:14
|
LL | #![doc = in_mod!()]
| ^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_mod_escape` in this scope
--> $DIR/key-value-expansion-scope.rs:32:14
error: cannot find macro `in_block` in this scope
--> $DIR/key-value-expansion-scope.rs:44:9
|
LL | #![doc = in_mod_escape!()]
| ^^^^^^^^^^^^^
LL | #[doc = in_block!()]
| ^^^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_block` in this scope
--> $DIR/key-value-expansion-scope.rs:43:14
--> $DIR/key-value-expansion-scope.rs:46:14
|
LL | #![doc = in_block!()]
| ^^^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_mod` in this scope
--> $DIR/key-value-expansion-scope.rs:54:9
--> $DIR/key-value-expansion-scope.rs:57:9
|
LL | #[doc = in_mod!()]
| ^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_block` in this scope
--> $DIR/key-value-expansion-scope.rs:56:9
--> $DIR/key-value-expansion-scope.rs:59:9
|
LL | #[doc = in_block!()]
| ^^^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_mod` in this scope
--> $DIR/key-value-expansion-scope.rs:59:14
--> $DIR/key-value-expansion-scope.rs:62:14
|
LL | #![doc = in_mod!()]
| ^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: cannot find macro `in_block` in this scope
--> $DIR/key-value-expansion-scope.rs:61:14
--> $DIR/key-value-expansion-scope.rs:64:14
|
LL | #![doc = in_block!()]
| ^^^^^^^^
|
= help: have you added the `#[macro_use]` on the module/import?

error: aborting due to 19 previous errors
error: aborting due to 16 previous errors

0 comments on commit cb297a1

Please sign in to comment.