diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-05-29 08:28:44 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2024-05-29 08:28:44 +0000 |
| commit | bcfefe1c7e8de6c7b3ee79d402bb107303934e63 (patch) | |
| tree | 866271c58b755a89fb1bab4e0633eb30401213af | |
| parent | 7717a306b2678ba9ece19b723c76a6b3a89ba931 (diff) | |
| download | rust-bcfefe1c7e8de6c7b3ee79d402bb107303934e63.tar.gz rust-bcfefe1c7e8de6c7b3ee79d402bb107303934e63.zip | |
Reintroduce name resolution check for trying to access locals from an inline const
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 5 | ||||
| -rw-r--r-- | tests/ui/inline-const/referencing_local_variables.rs | 6 | ||||
| -rw-r--r-- | tests/ui/inline-const/referencing_local_variables.stderr | 11 |
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`. |
