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
+