From d0625a380b03e83fcfc2f0230986186992d13c71 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Mon, 24 Jun 2019 18:14:53 +0200 Subject: [PATCH] Allow usage_of_ty_tykind only in sty and in some special cases --- src/librustc/ty/codec.rs | 2 ++ src/librustc/ty/context.rs | 3 +++ src/librustc/ty/flags.rs | 2 ++ src/librustc/ty/mod.rs | 37 ++++++++++++++++++------------------- src/librustc/ty/sty.rs | 2 ++ 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/librustc/ty/codec.rs b/src/librustc/ty/codec.rs index 224f7d5f28dc3..26e7cc9004d4e 100644 --- a/src/librustc/ty/codec.rs +++ b/src/librustc/ty/codec.rs @@ -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(decoder: &mut D) -> Result, D::Error> where diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 28399ed5439f7..a00eed3fdda95 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -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> 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) diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index 8d7e7e16e85cb..411b18e043a20 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -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 | diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 796b2b3c1a1c8..90c18a7e364ea 100644 --- a/src/librustc/ty/mod.rs +++ b/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::*; @@ -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, } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 8bfbd8b854b03..5d17080a9b2bc 100644 --- a/src/librustc/ty/sty.rs +++ b/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;