Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow usage_of_ty_tykind only in sty
and in some special cases
  • Loading branch information
flip1995 committed Jun 24, 2019
1 parent 8e087cd commit d0625a3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/librustc/ty/codec.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/ty/context.rs
Expand Up @@ -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>,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/flags.rs
Expand Up @@ -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);
Expand Down Expand Up @@ -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 |
Expand Down
37 changes: 18 additions & 19 deletions src/librustc/ty/mod.rs
@@ -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::*;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/sty.rs
@@ -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;
Expand Down

0 comments on commit d0625a3

Please sign in to comment.