Unify all validity check intrinsics
Also merges the inhabitedness check into the query to further unify the code paths.
This commit is contained in:
parent
49b9cc5139
commit
5f593da4e6
11 changed files with 118 additions and 162 deletions
|
@ -4,7 +4,7 @@ use crate::infer::canonical::Canonical;
|
|||
use crate::mir;
|
||||
use crate::traits;
|
||||
use crate::ty::fast_reject::SimplifiedType;
|
||||
use crate::ty::layout::{InitKind, TyAndLayout};
|
||||
use crate::ty::layout::{TyAndLayout, ValidityRequirement};
|
||||
use crate::ty::subst::{GenericArg, SubstsRef};
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
|
@ -698,7 +698,7 @@ impl Key for HirId {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Key for (InitKind, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) {
|
||||
impl<'tcx> Key for (ValidityRequirement, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
// Just forward to `Ty<'tcx>`
|
||||
|
|
|
@ -2173,8 +2173,8 @@ rustc_queries! {
|
|||
separate_provide_extern
|
||||
}
|
||||
|
||||
query check_validity_of_init(key: (InitKind, ty::ParamEnvAnd<'tcx, Ty<'tcx>>)) -> Result<bool, ty::layout::LayoutError<'tcx>> {
|
||||
desc { "checking to see if `{}` permits being left {}", key.1.value, key.0 }
|
||||
query check_validity_requirement(key: (ValidityRequirement, ty::ParamEnvAnd<'tcx, Ty<'tcx>>)) -> Result<bool, ty::layout::LayoutError<'tcx>> {
|
||||
desc { "checking validity requirement for `{}`: {}", key.1.value, key.0 }
|
||||
}
|
||||
|
||||
query compare_impl_const(
|
||||
|
|
|
@ -7,6 +7,7 @@ use rustc_hir as hir;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_session::config::OptLevel;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::call::FnAbi;
|
||||
use rustc_target::abi::*;
|
||||
|
@ -172,16 +173,29 @@ pub const MAX_SIMD_LANES: u64 = 1 << 0xF;
|
|||
/// Used in `might_permit_raw_init` to indicate the kind of initialisation
|
||||
/// that is checked to be valid
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
|
||||
pub enum InitKind {
|
||||
pub enum ValidityRequirement {
|
||||
Inhabited,
|
||||
Zero,
|
||||
UninitMitigated0x01Fill,
|
||||
}
|
||||
|
||||
impl fmt::Display for InitKind {
|
||||
impl ValidityRequirement {
|
||||
pub fn from_intrinsic(intrinsic: Symbol) -> Option<Self> {
|
||||
match intrinsic {
|
||||
sym::assert_inhabited => Some(Self::Inhabited),
|
||||
sym::assert_zero_valid => Some(Self::Zero),
|
||||
sym::assert_mem_uninitialized_valid => Some(Self::UninitMitigated0x01Fill),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ValidityRequirement {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Zero => f.write_str("zeroed"),
|
||||
Self::UninitMitigated0x01Fill => f.write_str("filled with 0x01"),
|
||||
Self::Inhabited => f.write_str("is inhabited"),
|
||||
Self::Zero => f.write_str("allows being left zeroed"),
|
||||
Self::UninitMitigated0x01Fill => f.write_str("allows being filled with 0x01"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ use crate::traits::specialization_graph;
|
|||
use crate::traits::{self, ImplSource};
|
||||
use crate::ty::context::TyCtxtFeed;
|
||||
use crate::ty::fast_reject::SimplifiedType;
|
||||
use crate::ty::layout::InitKind;
|
||||
use crate::ty::layout::ValidityRequirement;
|
||||
use crate::ty::subst::{GenericArg, SubstsRef};
|
||||
use crate::ty::util::AlwaysRequiresDrop;
|
||||
use crate::ty::GeneratorDiagnosticData;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue