about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_resolve/src/late.rs5
-rw-r--r--tests/ui/inline-const/referencing_local_variables.rs6
-rw-r--r--tests/ui/inline-const/referencing_local_variables.stderr11
3 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs
index 08326d1ef57..98dc507d863 100644
--- a/compiler/rustc_resolve/src/late.rs
+++ b/compiler/rustc_resolve/src/late.rs
@@ -4502,6 +4502,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
                 self.visit_expr(elem);
                 self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::Yes));
             }
+            ExprKind::ConstBlock(ref expr) => {
+                self.resolve_anon_const_manual(false, AnonConstKind::InlineConst, |this| {
+                    this.visit_expr(expr)
+                });
+            }
             ExprKind::Index(ref elem, ref idx, _) => {
                 self.resolve_expr(elem, Some(expr));
                 self.visit_expr(idx);
diff --git a/tests/ui/inline-const/referencing_local_variables.rs b/tests/ui/inline-const/referencing_local_variables.rs
new file mode 100644
index 00000000000..f9f0fef07f0
--- /dev/null
+++ b/tests/ui/inline-const/referencing_local_variables.rs
@@ -0,0 +1,6 @@
+const fn test_me<T>(a: usize) -> usize {
+    const { a }
+    //~^ ERROR:  attempt to use a non-constant value in a constant
+}
+
+fn main() {}
diff --git a/tests/ui/inline-const/referencing_local_variables.stderr b/tests/ui/inline-const/referencing_local_variables.stderr
new file mode 100644
index 00000000000..4a0a5406602
--- /dev/null
+++ b/tests/ui/inline-const/referencing_local_variables.stderr
@@ -0,0 +1,11 @@
+error[E0435]: attempt to use a non-constant value in a constant
+  --> $DIR/referencing_local_variables.rs:2:13
+   |
+LL | const fn test_me<T>(a: usize) -> usize {
+   |                     - this would need to be a `const`
+LL |     const { a }
+   |             ^
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0435`.