From fdaac4e48ea276a595a7cdd08f4801763dfbb6cf Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 16 Jan 2023 19:55:20 +0000 Subject: [PATCH 1/2] ConstBlocks are poly if their substs are poly --- compiler/rustc_ty_utils/src/consts.rs | 44 ++++++++++++++++++- .../const-block-is-poly.rs | 11 +++++ .../const-block-is-poly.stderr | 20 +++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 tests/ui/const-generics/generic_const_exprs/const-block-is-poly.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/const-block-is-poly.stderr diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index a9b4e1420ea..a9fbad55dac 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -302,13 +302,53 @@ impl<'a, 'tcx> IsThirPolymorphic<'a, 'tcx> { } match expr.kind { - thir::ExprKind::NamedConst { substs, .. } => substs.has_non_region_param(), + thir::ExprKind::NamedConst { substs, .. } + | thir::ExprKind::ConstBlock { substs, .. } => substs.has_non_region_param(), thir::ExprKind::ConstParam { .. } => true, thir::ExprKind::Repeat { value, count } => { self.visit_expr(&self.thir()[value]); count.has_non_region_param() } - _ => false, + thir::ExprKind::Scope { .. } + | thir::ExprKind::Box { .. } + | thir::ExprKind::If { .. } + | thir::ExprKind::Call { .. } + | thir::ExprKind::Deref { .. } + | thir::ExprKind::Binary { .. } + | thir::ExprKind::LogicalOp { .. } + | thir::ExprKind::Unary { .. } + | thir::ExprKind::Cast { .. } + | thir::ExprKind::Use { .. } + | thir::ExprKind::NeverToAny { .. } + | thir::ExprKind::Pointer { .. } + | thir::ExprKind::Loop { .. } + | thir::ExprKind::Let { .. } + | thir::ExprKind::Match { .. } + | thir::ExprKind::Block { .. } + | thir::ExprKind::Assign { .. } + | thir::ExprKind::AssignOp { .. } + | thir::ExprKind::Field { .. } + | thir::ExprKind::Index { .. } + | thir::ExprKind::VarRef { .. } + | thir::ExprKind::UpvarRef { .. } + | thir::ExprKind::Borrow { .. } + | thir::ExprKind::AddressOf { .. } + | thir::ExprKind::Break { .. } + | thir::ExprKind::Continue { .. } + | thir::ExprKind::Return { .. } + | thir::ExprKind::Array { .. } + | thir::ExprKind::Tuple { .. } + | thir::ExprKind::Adt(_) + | thir::ExprKind::PlaceTypeAscription { .. } + | thir::ExprKind::ValueTypeAscription { .. } + | thir::ExprKind::Closure(_) + | thir::ExprKind::Literal { .. } + | thir::ExprKind::NonHirLiteral { .. } + | thir::ExprKind::ZstLiteral { .. } + | thir::ExprKind::StaticRef { .. } + | thir::ExprKind::InlineAsm(_) + | thir::ExprKind::ThreadLocalRef(_) + | thir::ExprKind::Yield { .. } => false, } } fn pat_is_poly(&mut self, pat: &thir::Pat<'tcx>) -> bool { diff --git a/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.rs b/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.rs new file mode 100644 index 00000000000..7332a8f03c0 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.rs @@ -0,0 +1,11 @@ +#![feature(inline_const, generic_const_exprs)] +//~^ WARN the feature `generic_const_exprs` is incomplete + +fn foo() { + let _ = [0u8; const { std::mem::size_of::() }]; + //~^ ERROR: overly complex generic constant +} + +fn main() { + foo::(); +} diff --git a/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.stderr b/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.stderr new file mode 100644 index 00000000000..1513e491b9b --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.stderr @@ -0,0 +1,20 @@ +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/const-block-is-poly.rs:1:26 + | +LL | #![feature(inline_const, generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76560 for more information + = note: `#[warn(incomplete_features)]` on by default + +error: overly complex generic constant + --> $DIR/const-block-is-poly.rs:5:19 + | +LL | let _ = [0u8; const { std::mem::size_of::() }]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ const blocks are not supported in generic constant + | + = help: consider moving this anonymous constant into a `const` function + = note: this operation may be supported in the future + +error: aborting due to previous error; 1 warning emitted + From 9f6fef96571f52b3e4320cfcb906dfdc66eac1c3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 16 Jan 2023 20:21:29 +0000 Subject: [PATCH 2/2] Properly pluralize 'generic constants' --- .../rustc_error_messages/locales/en-US/ty_utils.ftl | 12 ++++++------ .../array-size-in-generic-struct-param.full.stderr | 2 +- .../generic_const_exprs/const-block-is-poly.stderr | 2 +- .../generic_const_exprs/let-bindings.stderr | 4 ++-- .../generic_const_exprs/unused_expr.stderr | 6 +++--- .../const-generics/issues/issue-67945-2.full.stderr | 2 +- .../const-generics/issues/issue-67945-3.full.stderr | 2 +- .../const-generics/issues/issue-67945-4.full.stderr | 2 +- tests/ui/const-generics/issues/issue-77357.stderr | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/ty_utils.ftl b/compiler/rustc_error_messages/locales/en-US/ty_utils.ftl index 1040ee1c97d..abe65a0e3fe 100644 --- a/compiler/rustc_error_messages/locales/en-US/ty_utils.ftl +++ b/compiler/rustc_error_messages/locales/en-US/ty_utils.ftl @@ -10,17 +10,17 @@ ty_utils_address_and_deref_not_supported = dereferencing or taking the address i ty_utils_array_not_supported = array construction is not supported in generic constants -ty_utils_block_not_supported = blocks are not supported in generic constant +ty_utils_block_not_supported = blocks are not supported in generic constants -ty_utils_never_to_any_not_supported = converting nevers to any is not supported in generic constant +ty_utils_never_to_any_not_supported = converting nevers to any is not supported in generic constants ty_utils_tuple_not_supported = tuple construction is not supported in generic constants -ty_utils_index_not_supported = indexing is not supported in generic constant +ty_utils_index_not_supported = indexing is not supported in generic constants -ty_utils_field_not_supported = field access is not supported in generic constant +ty_utils_field_not_supported = field access is not supported in generic constants -ty_utils_const_block_not_supported = const blocks are not supported in generic constant +ty_utils_const_block_not_supported = const blocks are not supported in generic constants ty_utils_adt_not_supported = struct/enum construction is not supported in generic constants @@ -44,4 +44,4 @@ ty_utils_control_flow_not_supported = control flow is not supported in generic c ty_utils_inline_asm_not_supported = assembly is not supported in generic constants -ty_utils_operation_not_supported = unsupported operation in generic constant +ty_utils_operation_not_supported = unsupported operation in generic constants diff --git a/tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr b/tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr index 041232e8690..1d10dfdf10c 100644 --- a/tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr +++ b/tests/ui/const-generics/generic_const_exprs/array-size-in-generic-struct-param.full.stderr @@ -10,7 +10,7 @@ error: overly complex generic constant --> $DIR/array-size-in-generic-struct-param.rs:19:15 | LL | arr: [u8; CFG.arr_size], - | ^^^^^^^^^^^^ field access is not supported in generic constant + | ^^^^^^^^^^^^ field access is not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future diff --git a/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.stderr b/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.stderr index 1513e491b9b..f2625990840 100644 --- a/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.stderr +++ b/tests/ui/const-generics/generic_const_exprs/const-block-is-poly.stderr @@ -11,7 +11,7 @@ error: overly complex generic constant --> $DIR/const-block-is-poly.rs:5:19 | LL | let _ = [0u8; const { std::mem::size_of::() }]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ const blocks are not supported in generic constant + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ const blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future diff --git a/tests/ui/const-generics/generic_const_exprs/let-bindings.stderr b/tests/ui/const-generics/generic_const_exprs/let-bindings.stderr index 5ebb4c3999c..823a4f8a185 100644 --- a/tests/ui/const-generics/generic_const_exprs/let-bindings.stderr +++ b/tests/ui/const-generics/generic_const_exprs/let-bindings.stderr @@ -2,7 +2,7 @@ error: overly complex generic constant --> $DIR/let-bindings.rs:6:68 | LL | fn test() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default { - | ^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constant + | ^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future @@ -11,7 +11,7 @@ error: overly complex generic constant --> $DIR/let-bindings.rs:6:35 | LL | fn test() -> [u8; { let x = N; N + 1 }] where [u8; { let x = N; N + 1 }]: Default { - | ^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constant + | ^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future diff --git a/tests/ui/const-generics/generic_const_exprs/unused_expr.stderr b/tests/ui/const-generics/generic_const_exprs/unused_expr.stderr index df73acf53de..265a3b9d233 100644 --- a/tests/ui/const-generics/generic_const_exprs/unused_expr.stderr +++ b/tests/ui/const-generics/generic_const_exprs/unused_expr.stderr @@ -2,7 +2,7 @@ error: overly complex generic constant --> $DIR/unused_expr.rs:4:34 | LL | fn add() -> [u8; { N + 1; 5 }] { - | ^^^^^^^^^^^^ blocks are not supported in generic constant + | ^^^^^^^^^^^^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future @@ -11,7 +11,7 @@ error: overly complex generic constant --> $DIR/unused_expr.rs:9:34 | LL | fn div() -> [u8; { N / 1; 5 }] { - | ^^^^^^^^^^^^ blocks are not supported in generic constant + | ^^^^^^^^^^^^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future @@ -20,7 +20,7 @@ error: overly complex generic constant --> $DIR/unused_expr.rs:16:38 | LL | fn fn_call() -> [u8; { foo(N); 5 }] { - | ^^^^^^^^^^^^^ blocks are not supported in generic constant + | ^^^^^^^^^^^^^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future diff --git a/tests/ui/const-generics/issues/issue-67945-2.full.stderr b/tests/ui/const-generics/issues/issue-67945-2.full.stderr index cce85772aa4..47429b7612f 100644 --- a/tests/ui/const-generics/issues/issue-67945-2.full.stderr +++ b/tests/ui/const-generics/issues/issue-67945-2.full.stderr @@ -8,7 +8,7 @@ LL | | let x: Option> = None; LL | | LL | | 0 LL | | }], - | |_____^ blocks are not supported in generic constant + | |_____^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future diff --git a/tests/ui/const-generics/issues/issue-67945-3.full.stderr b/tests/ui/const-generics/issues/issue-67945-3.full.stderr index d3d9452d316..98f9f83976a 100644 --- a/tests/ui/const-generics/issues/issue-67945-3.full.stderr +++ b/tests/ui/const-generics/issues/issue-67945-3.full.stderr @@ -7,7 +7,7 @@ LL | | let x: Option = None; LL | | LL | | 0 LL | | }], - | |_____^ blocks are not supported in generic constant + | |_____^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future diff --git a/tests/ui/const-generics/issues/issue-67945-4.full.stderr b/tests/ui/const-generics/issues/issue-67945-4.full.stderr index 9604eb35d02..c03d40a7bb8 100644 --- a/tests/ui/const-generics/issues/issue-67945-4.full.stderr +++ b/tests/ui/const-generics/issues/issue-67945-4.full.stderr @@ -7,7 +7,7 @@ LL | | let x: Option> = None; LL | | LL | | 0 LL | | }], - | |_____^ blocks are not supported in generic constant + | |_____^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future diff --git a/tests/ui/const-generics/issues/issue-77357.stderr b/tests/ui/const-generics/issues/issue-77357.stderr index 804c0ae5175..68b35a38b0f 100644 --- a/tests/ui/const-generics/issues/issue-77357.stderr +++ b/tests/ui/const-generics/issues/issue-77357.stderr @@ -2,7 +2,7 @@ error: overly complex generic constant --> $DIR/issue-77357.rs:6:46 | LL | fn bug<'a, T>() -> &'static dyn MyTrait<[(); { |x: &'a u32| { x }; 4 }]> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constant + | ^^^^^^^^^^^^^^^^^^^^^^^^^ blocks are not supported in generic constants | = help: consider moving this anonymous constant into a `const` function = note: this operation may be supported in the future