From 1e42bb606d9abcfa22ee248e3a8598f813632418 Mon Sep 17 00:00:00 2001 From: bohan Date: Thu, 20 Jun 2024 19:44:36 +0800 Subject: [PATCH] collect attrs in const block expr --- compiler/rustc_resolve/src/def_collector.rs | 3 +++ tests/ui/resolve/path-attr-in-const-block.rs | 9 +++++++++ tests/ui/resolve/path-attr-in-const-block.stderr | 8 ++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/ui/resolve/path-attr-in-const-block.rs create mode 100644 tests/ui/resolve/path-attr-in-const-block.stderr diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index fb6e55f2b7bdf..60789c083133f 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -343,6 +343,9 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> { self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span) } ExprKind::ConstBlock(ref constant) => { + for attr in &expr.attrs { + visit::walk_attribute(self, attr); + } let def = self.create_def( constant.id, kw::Empty, diff --git a/tests/ui/resolve/path-attr-in-const-block.rs b/tests/ui/resolve/path-attr-in-const-block.rs new file mode 100644 index 0000000000000..076511d26d6d3 --- /dev/null +++ b/tests/ui/resolve/path-attr-in-const-block.rs @@ -0,0 +1,9 @@ +// issue#126516 +// issue#126647 + +fn main() { + const { + #![path = foo!()] + //~^ ERROR: cannot find macro `foo` in this scope + } +} diff --git a/tests/ui/resolve/path-attr-in-const-block.stderr b/tests/ui/resolve/path-attr-in-const-block.stderr new file mode 100644 index 0000000000000..8f9e58157c809 --- /dev/null +++ b/tests/ui/resolve/path-attr-in-const-block.stderr @@ -0,0 +1,8 @@ +error: cannot find macro `foo` in this scope + --> $DIR/path-attr-in-const-block.rs:6:19 + | +LL | #![path = foo!()] + | ^^^ + +error: aborting due to 1 previous error +