Skip to content

Commit

Permalink
Unrolled build for rust-lang#125705
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#125705 - oli-obk:const_block_ice, r=compiler-errors

Reintroduce name resolution check for trying to access locals from an inline const

fixes rust-lang#125676

I removed this without replacement in rust-lang#124650 without considering the consequences
  • Loading branch information
rust-timer committed May 29, 2024
2 parents e9b7aa0 + bcfefe1 commit cfab26c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/inline-const/referencing_local_variables.rs
Original file line number Diff line number Diff line change
@@ -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() {}
11 changes: 11 additions & 0 deletions tests/ui/inline-const/referencing_local_variables.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit cfab26c

Please sign in to comment.