diff options
| author | Lukas Markeffsky <@> | 2025-02-21 18:00:56 +0100 |
|---|---|---|
| committer | Lukas Markeffsky <@> | 2025-02-21 20:32:34 +0100 |
| commit | a825e37fe4dba0e8b33ed05611ba130d396a5509 (patch) | |
| tree | 51b9c231fb6671073d0ca3f06072792f2ada4536 /compiler/rustc_ty_utils/src/layout.rs | |
| parent | 71e06b9c59d6af50fdc55aed75620493d29baf98 (diff) | |
| download | rust-a825e37fe4dba0e8b33ed05611ba130d396a5509.tar.gz rust-a825e37fe4dba0e8b33ed05611ba130d396a5509.zip | |
layout_of: put back not-so-unreachable case
Diffstat (limited to 'compiler/rustc_ty_utils/src/layout.rs')
| -rw-r--r-- | compiler/rustc_ty_utils/src/layout.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index b6a14d147ca..c8b3c8a796f 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -147,12 +147,25 @@ fn extract_const_value<'tcx>( ) -> Result<ty::Value<'tcx>, &'tcx LayoutError<'tcx>> { match ct.kind() { ty::ConstKind::Value(cv) => Ok(cv), - ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_) => { + ty::ConstKind::Param(_) | ty::ConstKind::Expr(_) => { if !ct.has_param() { bug!("failed to normalize const, but it is not generic: {ct:?}"); } Err(error(cx, LayoutError::TooGeneric(ty))) } + ty::ConstKind::Unevaluated(_) => { + let err = if ct.has_param() { + LayoutError::TooGeneric(ty) + } else { + // This case is reachable with unsatisfiable predicates and GCE (which will + // cause anon consts to inherit the unsatisfiable predicates). For example + // if we have an unsatisfiable `u8: Trait` bound, then it's not a compile + // error to mention `[u8; <u8 as Trait>::CONST]`, but we can't compute its + // layout. + LayoutError::Unknown(ty) + }; + Err(error(cx, err)) + } ty::ConstKind::Infer(_) | ty::ConstKind::Bound(..) | ty::ConstKind::Placeholder(_) |
