Allow usage_of_ty_tykind only in sty

and in some special cases
This commit is contained in:
flip1995 2019-06-24 18:14:53 +02:00
parent 8e087cdd98
commit d0625a380b
No known key found for this signature in database
GPG Key ID: 693086869D506637
5 changed files with 27 additions and 19 deletions

View File

@ -27,6 +27,7 @@ pub trait EncodableWithShorthand: Clone + Eq + Hash {
fn variant(&self) -> &Self::Variant;
}
#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
impl<'tcx> EncodableWithShorthand for Ty<'tcx> {
type Variant = ty::TyKind<'tcx>;
fn variant(&self) -> &Self::Variant {
@ -159,6 +160,7 @@ where
Ok(decoder.map_encoded_cnum_to_current(cnum))
}
#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
#[inline]
pub fn decode_ty<D>(decoder: &mut D) -> Result<Ty<'tcx>, D::Error>
where

View File

@ -135,6 +135,7 @@ impl<'tcx> CtxtInterners<'tcx> {
}
/// Intern a type
#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
#[inline(never)]
fn intern_ty(
local: &CtxtInterners<'tcx>,
@ -2195,6 +2196,7 @@ impl<'tcx> Hash for Interned<'tcx, TyS<'tcx>> {
}
}
#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
fn borrow<'a>(&'a self) -> &'a TyKind<'tcx> {
&self.0.sty
@ -2429,6 +2431,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_fn_ptr(converted_sig)
}
#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
#[inline]
pub fn mk_ty(&self, st: TyKind<'tcx>) -> Ty<'tcx> {
CtxtInterners::intern_ty(&self.interners, &self.global_interners, st)

View File

@ -18,6 +18,7 @@ impl FlagComputation {
}
}
#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
pub fn for_sty(st: &ty::TyKind<'_>) -> FlagComputation {
let mut result = FlagComputation::new();
result.add_sty(st);
@ -61,6 +62,7 @@ impl FlagComputation {
} // otherwise, this binder captures nothing
}
#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
fn add_sty(&mut self, st: &ty::TyKind<'_>) {
match st {
&ty::Bool |

View File

@ -1,7 +1,5 @@
// ignore-tidy-filelength
#![cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
pub use self::Variance::*;
pub use self::AssocItemContainer::*;
pub use self::BorrowKind::*;
@ -484,6 +482,7 @@ bitflags! {
}
}
#[cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
pub struct TyS<'tcx> {
pub sty: TyKind<'tcx>,
pub flags: TypeFlags,
@ -541,29 +540,29 @@ impl<'tcx> Hash for TyS<'tcx> {
impl<'tcx> TyS<'tcx> {
pub fn is_primitive_ty(&self) -> bool {
match self.sty {
TyKind::Bool |
TyKind::Char |
TyKind::Int(_) |
TyKind::Uint(_) |
TyKind::Float(_) |
TyKind::Infer(InferTy::IntVar(_)) |
TyKind::Infer(InferTy::FloatVar(_)) |
TyKind::Infer(InferTy::FreshIntTy(_)) |
TyKind::Infer(InferTy::FreshFloatTy(_)) => true,
TyKind::Ref(_, x, _) => x.is_primitive_ty(),
Bool |
Char |
Int(_) |
Uint(_) |
Float(_) |
Infer(InferTy::IntVar(_)) |
Infer(InferTy::FloatVar(_)) |
Infer(InferTy::FreshIntTy(_)) |
Infer(InferTy::FreshFloatTy(_)) => true,
Ref(_, x, _) => x.is_primitive_ty(),
_ => false,
}
}
pub fn is_suggestable(&self) -> bool {
match self.sty {
TyKind::Opaque(..) |
TyKind::FnDef(..) |
TyKind::FnPtr(..) |
TyKind::Dynamic(..) |
TyKind::Closure(..) |
TyKind::Infer(..) |
TyKind::Projection(..) => false,
Opaque(..) |
FnDef(..) |
FnPtr(..) |
Dynamic(..) |
Closure(..) |
Infer(..) |
Projection(..) => false,
_ => true,
}
}

View File

@ -1,5 +1,7 @@
//! This module contains `TyKind` and its major components.
#![cfg_attr(not(bootstrap), allow(rustc::usage_of_ty_tykind))]
use crate::hir;
use crate::hir::def_id::DefId;
use crate::infer::canonical::Canonical;