Skip to content

Commit b8e3faa

Browse files
authored
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
2 parents 31e6c26 + bcfefe1 commit b8e3faa

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

compiler/rustc_resolve/src/late.rs

+5
Original file line numberDiff line numberDiff line change
@@ -4505,6 +4505,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
45054505
self.visit_expr(elem);
45064506
self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::Yes));
45074507
}
4508+
ExprKind::ConstBlock(ref expr) => {
4509+
self.resolve_anon_const_manual(false, AnonConstKind::InlineConst, |this| {
4510+
this.visit_expr(expr)
4511+
});
4512+
}
45084513
ExprKind::Index(ref elem, ref idx, _) => {
45094514
self.resolve_expr(elem, Some(expr));
45104515
self.visit_expr(idx);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const fn test_me<T>(a: usize) -> usize {
2+
const { a }
3+
//~^ ERROR: attempt to use a non-constant value in a constant
4+
}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0435]: attempt to use a non-constant value in a constant
2+
--> $DIR/referencing_local_variables.rs:2:13
3+
|
4+
LL | const fn test_me<T>(a: usize) -> usize {
5+
| - this would need to be a `const`
6+
LL | const { a }
7+
| ^
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0435`.

0 commit comments

Comments
 (0)