Unify validity checks into a single query
Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern. I am planning on adding a further initness to check, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one.
This commit is contained in:
parent
b869e84e58
commit
025d2a147f
11 changed files with 89 additions and 67 deletions
|
@ -4,8 +4,9 @@ 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::subst::{GenericArg, SubstsRef};
|
||||
use crate::ty::{self, layout::TyAndLayout, Ty, TyCtxt};
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::hir_id::{HirId, OwnerId};
|
||||
use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCacheSelector};
|
||||
|
@ -696,3 +697,24 @@ impl Key for HirId {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Key for (InitKind, ty::ParamEnvAnd<'tcx, Ty<'tcx>>) {
|
||||
type CacheSelector = DefaultCacheSelector<Self>;
|
||||
|
||||
// Just forward to `Ty<'tcx>`
|
||||
#[inline(always)]
|
||||
fn query_crate_is_local(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn default_span(&self, _: TyCtxt<'_>) -> Span {
|
||||
DUMMY_SP
|
||||
}
|
||||
|
||||
fn ty_adt_id(&self) -> Option<DefId> {
|
||||
match self.1.value.kind() {
|
||||
ty::Adt(adt, _) => Some(adt.did()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2173,12 +2173,8 @@ rustc_queries! {
|
|||
separate_provide_extern
|
||||
}
|
||||
|
||||
query permits_uninit_init(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> Result<bool, ty::layout::LayoutError<'tcx>> {
|
||||
desc { "checking to see if `{}` permits being left uninit", key.value }
|
||||
}
|
||||
|
||||
query permits_zero_init(key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> Result<bool, ty::layout::LayoutError<'tcx>> {
|
||||
desc { "checking to see if `{}` permits being left zeroed", key.value }
|
||||
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 compare_impl_const(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue