diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-29 20:12:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-29 20:12:34 +0200 |
| commit | c09b89ea327892ff281a6d3923ece76072c0d015 (patch) | |
| tree | 8924ec896b1182acfbdc5928deccfa4f3611a788 | |
| parent | 9a61146765b9979d744f21b0ba0a215ecdb06364 (diff) | |
| parent | bcfefe1c7e8de6c7b3ee79d402bb107303934e63 (diff) | |
| download | rust-c09b89ea327892ff281a6d3923ece76072c0d015.tar.gz rust-c09b89ea327892ff281a6d3923ece76072c0d015.zip | |
Rollup merge of #125705 - oli-obk:const_block_ice, r=compiler-errors
Reintroduce name resolution check for trying to access locals from an inline const fixes #125676 I removed this without replacement in https://github.com/rust-lang/rust/pull/124650 without considering the consequences
| -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 0655484ad85..bcdd6716cc3 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -4505,6 +4505,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`. |
