diff options
| author | Michael Goulet <michael@errs.io> | 2023-02-13 21:07:46 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-02-14 01:03:06 +0000 |
| commit | 087a0136d01d0ee05d4e8c5e91f2e01978244a67 (patch) | |
| tree | 732dfdecbfdfffb6075d43398a935d2d8da98d97 /compiler/rustc_const_eval/src | |
| parent | 0b439b119b8d49450bddbbea317afeb0d4166f70 (diff) | |
| download | rust-087a0136d01d0ee05d4e8c5e91f2e01978244a67.tar.gz rust-087a0136d01d0ee05d4e8c5e91f2e01978244a67.zip | |
Don't ICE in might_permit_raw_init if reference is polymorphic
Diffstat (limited to 'compiler/rustc_const_eval/src')
| -rw-r--r-- | compiler/rustc_const_eval/src/util/might_permit_raw_init.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_const_eval/src/util/might_permit_raw_init.rs b/compiler/rustc_const_eval/src/util/might_permit_raw_init.rs index 48961b7aac6..a2db98683b5 100644 --- a/compiler/rustc_const_eval/src/util/might_permit_raw_init.rs +++ b/compiler/rustc_const_eval/src/util/might_permit_raw_init.rs @@ -1,5 +1,5 @@ use rustc_middle::ty::layout::{LayoutCx, LayoutOf, TyAndLayout}; -use rustc_middle::ty::{ParamEnv, TyCtxt}; +use rustc_middle::ty::{ParamEnv, TyCtxt, TypeVisitable}; use rustc_session::Limit; use rustc_target::abi::{Abi, FieldsShape, InitKind, Scalar, Variants}; @@ -108,7 +108,12 @@ fn might_permit_raw_init_lax<'tcx>( // Special magic check for references and boxes (i.e., special pointer types). if let Some(pointee) = this.ty.builtin_deref(false) { - let pointee = cx.layout_of(pointee.ty).expect("need to be able to compute layouts"); + let Ok(pointee) = cx.layout_of(pointee.ty) else { + // Reference is too polymorphic, it has a layout but the pointee does not. + // So we must assume that there may be some substitution that is valid. + assert!(pointee.ty.needs_subst()); + return true; + }; // We need to ensure that the LLVM attributes `aligned` and `dereferenceable(size)` are satisfied. if pointee.align.abi.bytes() > 1 { // 0x01-filling is not aligned. |
