ConstBlocks are poly if their substs are poly

This commit is contained in:
Michael Goulet 2023-01-16 19:55:20 +00:00
parent 481725984b
commit fdaac4e48e
3 changed files with 73 additions and 2 deletions

View File

@ -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 {

View File

@ -0,0 +1,11 @@
#![feature(inline_const, generic_const_exprs)]
//~^ WARN the feature `generic_const_exprs` is incomplete
fn foo<T>() {
let _ = [0u8; const { std::mem::size_of::<T>() }];
//~^ ERROR: overly complex generic constant
}
fn main() {
foo::<i32>();
}

View File

@ -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 <https://github.com/rust-lang/rust/issues/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::<T>() }];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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