Skip to content

Commit 9bcc46e

Browse files
authored
Rollup merge of rust-lang#106949 - compiler-errors:is-poly, r=BoxyUwU
ConstBlocks are poly if their substs are poly r? `@BoxyUwU` fixes rust-lang#106926
2 parents b90f629 + 9f6fef9 commit 9bcc46e

File tree

11 files changed

+89
-18
lines changed

11 files changed

+89
-18
lines changed

compiler/rustc_error_messages/locales/en-US/ty_utils.ftl

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ ty_utils_address_and_deref_not_supported = dereferencing or taking the address i
1010
1111
ty_utils_array_not_supported = array construction is not supported in generic constants
1212
13-
ty_utils_block_not_supported = blocks are not supported in generic constant
13+
ty_utils_block_not_supported = blocks are not supported in generic constants
1414
15-
ty_utils_never_to_any_not_supported = converting nevers to any is not supported in generic constant
15+
ty_utils_never_to_any_not_supported = converting nevers to any is not supported in generic constants
1616
1717
ty_utils_tuple_not_supported = tuple construction is not supported in generic constants
1818
19-
ty_utils_index_not_supported = indexing is not supported in generic constant
19+
ty_utils_index_not_supported = indexing is not supported in generic constants
2020
21-
ty_utils_field_not_supported = field access is not supported in generic constant
21+
ty_utils_field_not_supported = field access is not supported in generic constants
2222
23-
ty_utils_const_block_not_supported = const blocks are not supported in generic constant
23+
ty_utils_const_block_not_supported = const blocks are not supported in generic constants
2424
2525
ty_utils_adt_not_supported = struct/enum construction is not supported in generic constants
2626
@@ -44,4 +44,4 @@ ty_utils_control_flow_not_supported = control flow is not supported in generic c
4444
4545
ty_utils_inline_asm_not_supported = assembly is not supported in generic constants
4646
47-
ty_utils_operation_not_supported = unsupported operation in generic constant
47+
ty_utils_operation_not_supported = unsupported operation in generic constants

compiler/rustc_ty_utils/src/consts.rs

+42-2
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,53 @@ impl<'a, 'tcx> IsThirPolymorphic<'a, 'tcx> {
302302
}
303303

304304
match expr.kind {
305-
thir::ExprKind::NamedConst { substs, .. } => substs.has_non_region_param(),
305+
thir::ExprKind::NamedConst { substs, .. }
306+
| thir::ExprKind::ConstBlock { substs, .. } => substs.has_non_region_param(),
306307
thir::ExprKind::ConstParam { .. } => true,
307308
thir::ExprKind::Repeat { value, count } => {
308309
self.visit_expr(&self.thir()[value]);
309310
count.has_non_region_param()
310311
}
311-
_ => false,
312+
thir::ExprKind::Scope { .. }
313+
| thir::ExprKind::Box { .. }
314+
| thir::ExprKind::If { .. }
315+
| thir::ExprKind::Call { .. }
316+
| thir::ExprKind::Deref { .. }
317+
| thir::ExprKind::Binary { .. }
318+
| thir::ExprKind::LogicalOp { .. }
319+
| thir::ExprKind::Unary { .. }
320+
| thir::ExprKind::Cast { .. }
321+
| thir::ExprKind::Use { .. }
322+
| thir::ExprKind::NeverToAny { .. }
323+
| thir::ExprKind::Pointer { .. }
324+
| thir::ExprKind::Loop { .. }
325+
| thir::ExprKind::Let { .. }
326+
| thir::ExprKind::Match { .. }
327+
| thir::ExprKind::Block { .. }
328+
| thir::ExprKind::Assign { .. }
329+
| thir::ExprKind::AssignOp { .. }
330+
| thir::ExprKind::Field { .. }
331+
| thir::ExprKind::Index { .. }
332+
| thir::ExprKind::VarRef { .. }
333+
| thir::ExprKind::UpvarRef { .. }
334+
| thir::ExprKind::Borrow { .. }
335+
| thir::ExprKind::AddressOf { .. }
336+
| thir::ExprKind::Break { .. }
337+
| thir::ExprKind::Continue { .. }
338+
| thir::ExprKind::Return { .. }
339+
| thir::ExprKind::Array { .. }
340+
| thir::ExprKind::Tuple { .. }
341+
| thir::ExprKind::Adt(_)
342+
| thir::ExprKind::PlaceTypeAscription { .. }
343+
| thir::ExprKind::ValueTypeAscription { .. }
344+
| thir::ExprKind::Closure(_)
345+
| thir::ExprKind::Literal { .. }
346+
| thir::ExprKind::NonHirLiteral { .. }
347+
| thir::ExprKind::ZstLiteral { .. }
348+
| thir::ExprKind::StaticRef { .. }
349+
| thir::ExprKind::InlineAsm(_)
350+
| thir::ExprKind::ThreadLocalRef(_)
351+
| thir::ExprKind::Yield { .. } => false,
312352
}
313353
}
314354
fn pat_is_poly(&mut self, pat: &thir::Pat<'tcx>) -> bool {

tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error: overly complex generic constant
1010
--> $DIR/array-size-in-generic-struct-param.rs:19:15
1111
|
1212
LL | arr: [u8; CFG.arr_size],
13-
| ^^^^^^^^^^^^ field access is not supported in generic constant
13+
| ^^^^^^^^^^^^ field access is not supported in generic constants
1414
|
1515
= help: consider moving this anonymous constant into a `const` function
1616
= note: this operation may be supported in the future
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(inline_const, generic_const_exprs)]
2+
//~^ WARN the feature `generic_const_exprs` is incomplete
3+
4+
fn foo<T>() {
5+
let _ = [0u8; const { std::mem::size_of::<T>() }];
6+
//~^ ERROR: overly complex generic constant
7+
}
8+
9+
fn main() {
10+
foo::<i32>();
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/const-block-is-poly.rs:1:26
3+
|
4+
LL | #![feature(inline_const, generic_const_exprs)]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
error: overly complex generic constant
11+
--> $DIR/const-block-is-poly.rs:5:19
12+
|
13+
LL | let _ = [0u8; const { std::mem::size_of::<T>() }];
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ const blocks are not supported in generic constants
15+
|
16+
= help: consider moving this anonymous constant into a `const` function
17+
= note: this operation may be supported in the future
18+
19+
error: aborting due to previous error; 1 warning emitted
20+

tests/ui/const-generics/generic_const_exprs/let-bindings.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: overly complex generic constant
22
--> $DIR/let-bindings.rs:6:68
33
|
44
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
5-
| ^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constant
5+
| ^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constants
66
|
77
= help: consider moving this anonymous constant into a `const` function
88
= note: this operation may be supported in the future
@@ -11,7 +11,7 @@ error: overly complex generic constant
1111
--> $DIR/let-bindings.rs:6:35
1212
|
1313
LL | fn test<const N: usize>() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default {
14-
| ^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constant
14+
| ^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constants
1515
|
1616
= help: consider moving this anonymous constant into a `const` function
1717
= note: this operation may be supported in the future

tests/ui/const-generics/generic_const_exprs/unused_expr.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: overly complex generic constant
22
--> $DIR/unused_expr.rs:4:34
33
|
44
LL | fn add<const N: usize>() -> [u8; { N + 1; 5 }] {
5-
| ^^^^^^^^^^^^ blocks are not supported in generic constant
5+
| ^^^^^^^^^^^^ blocks are not supported in generic constants
66
|
77
= help: consider moving this anonymous constant into a `const` function
88
= note: this operation may be supported in the future
@@ -11,7 +11,7 @@ error: overly complex generic constant
1111
--> $DIR/unused_expr.rs:9:34
1212
|
1313
LL | fn div<const N: usize>() -> [u8; { N / 1; 5 }] {
14-
| ^^^^^^^^^^^^ blocks are not supported in generic constant
14+
| ^^^^^^^^^^^^ blocks are not supported in generic constants
1515
|
1616
= help: consider moving this anonymous constant into a `const` function
1717
= note: this operation may be supported in the future
@@ -20,7 +20,7 @@ error: overly complex generic constant
2020
--> $DIR/unused_expr.rs:16:38
2121
|
2222
LL | fn fn_call<const N: usize>() -> [u8; { foo(N); 5 }] {
23-
| ^^^^^^^^^^^^^ blocks are not supported in generic constant
23+
| ^^^^^^^^^^^^^ blocks are not supported in generic constants
2424
|
2525
= help: consider moving this anonymous constant into a `const` function
2626
= note: this operation may be supported in the future

tests/ui/const-generics/issues/issue-67945-2.full.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | | let x: Option<Box<Self>> = None;
88
LL | |
99
LL | | 0
1010
LL | | }],
11-
| |_____^ blocks are not supported in generic constant
11+
| |_____^ blocks are not supported in generic constants
1212
|
1313
= help: consider moving this anonymous constant into a `const` function
1414
= note: this operation may be supported in the future

tests/ui/const-generics/issues/issue-67945-3.full.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | | let x: Option<S> = None;
77
LL | |
88
LL | | 0
99
LL | | }],
10-
| |_____^ blocks are not supported in generic constant
10+
| |_____^ blocks are not supported in generic constants
1111
|
1212
= help: consider moving this anonymous constant into a `const` function
1313
= note: this operation may be supported in the future

tests/ui/const-generics/issues/issue-67945-4.full.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | | let x: Option<Box<S>> = None;
77
LL | |
88
LL | | 0
99
LL | | }],
10-
| |_____^ blocks are not supported in generic constant
10+
| |_____^ blocks are not supported in generic constants
1111
|
1212
= help: consider moving this anonymous constant into a `const` function
1313
= note: this operation may be supported in the future

tests/ui/const-generics/issues/issue-77357.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: overly complex generic constant
22
--> $DIR/issue-77357.rs:6:46
33
|
44
LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constant
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constants
66
|
77
= help: consider moving this anonymous constant into a `const` function
88
= note: this operation may be supported in the future

0 commit comments

Comments
 (0)