diff options
| author | bors <bors@rust-lang.org> | 2022-04-05 16:46:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-05 16:46:13 +0000 |
| commit | f262ca12aac76152c4b46cefcf8300f0249a5eb2 (patch) | |
| tree | 50b8a31fd3869a4c0805e26f6a6f2127c9a82988 /compiler/rustc_lint/src | |
| parent | d4c7839f73e4a84c75e8708adaafb9fafcb668f0 (diff) | |
| parent | d57b7559090266fc0db2616bcfe8286739ee131d (diff) | |
| download | rust-f262ca12aac76152c4b46cefcf8300f0249a5eb2.tar.gz rust-f262ca12aac76152c4b46cefcf8300f0249a5eb2.zip | |
Auto merge of #94527 - oli-obk:undef_scalars, r=nagisa,erikdesjardin
Let CTFE to handle partially uninitialized unions without marking the entire value as uninitialized. follow up to #94411 To fix https://github.com/rust-lang/rust/issues/69488 and by extension fix https://github.com/rust-lang/rust/issues/94371, we should stop treating types like `MaybeUninit<usize>` as something that the `Scalar` type in the interpreter engine can represent. So we add a new field to `abi::Primitive` that records whether the primitive is nested in a union cc `@RalfJung` r? `@ghost`
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/types.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 14ac30987b3..437104d1aaf 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -12,7 +12,7 @@ use rustc_middle::ty::{self, AdtKind, DefIdTree, Ty, TyCtxt, TypeFoldable}; use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::{Span, Symbol, DUMMY_SP}; -use rustc_target::abi::Abi; +use rustc_target::abi::{Abi, WrappingRange}; use rustc_target::abi::{Integer, TagEncoding, Variants}; use rustc_target::spec::abi::Abi as SpecAbi; @@ -796,14 +796,18 @@ crate fn repr_nullable_ptr<'tcx>( // Return the nullable type this Option-like enum can be safely represented with. let field_ty_abi = &cx.layout_of(field_ty).unwrap().abi; if let Abi::Scalar(field_ty_scalar) = field_ty_abi { - match (field_ty_scalar.valid_range.start, field_ty_scalar.valid_range.end) { - (0, x) if x == field_ty_scalar.value.size(&cx.tcx).unsigned_int_max() - 1 => { + match field_ty_scalar.valid_range(cx) { + WrappingRange { start: 0, end } + if end == field_ty_scalar.size(&cx.tcx).unsigned_int_max() - 1 => + { return Some(get_nullable_type(cx, field_ty).unwrap()); } - (1, _) => { + WrappingRange { start: 1, .. } => { return Some(get_nullable_type(cx, field_ty).unwrap()); } - (start, end) => unreachable!("Unhandled start and end range: ({}, {})", start, end), + WrappingRange { start, end } => { + unreachable!("Unhandled start and end range: ({}, {})", start, end) + } }; } } @@ -1342,7 +1346,7 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences { return }; - let tag_size = tag.value.size(&cx.tcx).bytes(); + let tag_size = tag.size(&cx.tcx).bytes(); debug!( "enum `{}` is {} bytes large with layout:\n{:#?}", |
