Remove unused code from rustc_middle

This commit is contained in:
est31 2020-10-09 11:20:28 +02:00
parent f243a2ad90
commit d7791f485b
12 changed files with 7 additions and 214 deletions

View File

@ -3,7 +3,6 @@
//! which are available for use externally when compiled as a library.
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefIdSet;
use rustc_hir::HirId;
use rustc_macros::HashStable;
use std::fmt;
@ -59,7 +58,3 @@ impl<Id: Hash + Eq + fmt::Debug> fmt::Debug for AccessLevels<Id> {
fmt::Debug::fmt(&self.map, f)
}
}
/// A set containing all exported definitions from external crates.
/// The set does not contain any entries from local crates.
pub type ExternalExports = DefIdSet;

View File

@ -56,15 +56,6 @@ impl<'tcx> ConstValue<'tcx> {
}
}
pub fn try_to_str_slice(&self) -> Option<&'tcx str> {
if let ConstValue::Slice { data, start, end } = *self {
std::str::from_utf8(data.inspect_with_uninit_and_ptr_outside_interpreter(start..end))
.ok()
} else {
None
}
}
pub fn try_to_bits(&self, size: Size) -> Option<u128> {
self.try_to_scalar()?.to_bits(size).ok()
}

View File

@ -3,7 +3,7 @@
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html
use crate::mir::coverage::{CodeRegion, CoverageKind};
use crate::mir::interpret::{Allocation, ConstValue, GlobalAlloc, Scalar};
use crate::mir::interpret::{Allocation, GlobalAlloc, Scalar};
use crate::mir::visit::MirVisitable;
use crate::ty::adjustment::PointerCast;
use crate::ty::codec::{TyDecoder, TyEncoder};
@ -460,17 +460,6 @@ impl<'tcx> Body<'tcx> {
}
}
/// Checks if `sub` is a sub scope of `sup`
pub fn is_sub_scope(&self, mut sub: SourceScope, sup: SourceScope) -> bool {
while sub != sup {
match self.source_scopes[sub].parent_scope {
None => return false,
Some(p) => sub = p,
}
}
true
}
/// Returns the return type; it always return first element from `local_decls` array.
#[inline]
pub fn return_ty(&self) -> Ty<'tcx> {
@ -1978,45 +1967,6 @@ impl<'tcx> Operand<'tcx> {
})
}
/// Convenience helper to make a `Scalar` from the given `Operand`, assuming that `Operand`
/// wraps a constant literal value. Panics if this is not the case.
pub fn scalar_from_const(operand: &Operand<'tcx>) -> Scalar {
match operand {
Operand::Constant(constant) => match constant.literal.val.try_to_scalar() {
Some(scalar) => scalar,
_ => panic!("{:?}: Scalar value expected", constant.literal.val),
},
_ => panic!("{:?}: Constant expected", operand),
}
}
/// Convenience helper to make a literal-like constant from a given `&str` slice.
/// Since this is used to synthesize MIR, assumes `user_ty` is None.
pub fn const_from_str(tcx: TyCtxt<'tcx>, val: &str, span: Span) -> Operand<'tcx> {
let tcx = tcx;
let allocation = Allocation::from_byte_aligned_bytes(val.as_bytes());
let allocation = tcx.intern_const_alloc(allocation);
let const_val = ConstValue::Slice { data: allocation, start: 0, end: val.len() };
let ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, tcx.types.str_);
Operand::Constant(box Constant {
span,
user_ty: None,
literal: ty::Const::from_value(tcx, const_val, ty),
})
}
/// Convenience helper to make a `ConstValue` from the given `Operand`, assuming that `Operand`
/// wraps a constant value (such as a `&str` slice). Panics if this is not the case.
pub fn value_from_const(operand: &Operand<'tcx>) -> ConstValue<'tcx> {
match operand {
Operand::Constant(constant) => match constant.literal.val.try_to_value() {
Some(const_value) => const_value,
_ => panic!("{:?}: ConstValue expected", constant.literal.val),
},
_ => panic!("{:?}: Constant expected", operand),
}
}
pub fn to_copy(&self) -> Self {
match *self {
Operand::Copy(_) | Operand::Constant(_) => self.clone(),
@ -2413,10 +2363,6 @@ impl<'tcx> UserTypeProjections {
self.contents.is_empty()
}
pub fn from_projections(projs: impl Iterator<Item = (UserTypeProjection, Span)>) -> Self {
UserTypeProjections { contents: projs.collect() }
}
pub fn projections_and_spans(
&self,
) -> impl Iterator<Item = &(UserTypeProjection, Span)> + ExactSizeIterator {

View File

@ -413,18 +413,6 @@ pub struct CoverageInfo {
/// For more information on why this is needed, consider looking
/// at the docs for `WithOptConstParam` itself.
impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mir_borrowck_opt_const_arg(
self,
def: ty::WithOptConstParam<LocalDefId>,
) -> &'tcx BorrowCheckResult<'tcx> {
if let Some(param_did) = def.const_param_did {
self.mir_borrowck_const_arg((def.did, param_did))
} else {
self.mir_borrowck(def.did)
}
}
#[inline]
pub fn mir_const_qualif_opt_const_arg(
self,

View File

@ -1186,16 +1186,6 @@ impl PlaceContext {
)
}
/// Returns `true` if this place context represents a storage live marker.
pub fn is_storage_live_marker(&self) -> bool {
matches!(self, PlaceContext::NonUse(NonUseContext::StorageLive))
}
/// Returns `true` if this place context represents a storage dead marker.
pub fn is_storage_dead_marker(&self) -> bool {
matches!(self, PlaceContext::NonUse(NonUseContext::StorageDead))
}
/// Returns `true` if this place context represents a use that potentially changes the value.
pub fn is_mutating_use(&self) -> bool {
matches!(self, PlaceContext::MutatingUse(..))

View File

@ -182,14 +182,6 @@ pub trait TyDecoder<'tcx>: Decoder {
where
F: FnOnce(&mut Self) -> Result<Ty<'tcx>, Self::Error>;
fn cached_predicate_for_shorthand<F>(
&mut self,
shorthand: usize,
or_insert_with: F,
) -> Result<ty::Predicate<'tcx>, Self::Error>
where
F: FnOnce(&mut Self) -> Result<ty::Predicate<'tcx>, Self::Error>;
fn with_position<F, R>(&mut self, pos: usize, f: F) -> R
where
F: FnOnce(&mut Self) -> R;

View File

@ -534,10 +534,6 @@ impl<'tcx> TypeckResults<'tcx> {
self.node_type(pat.hir_id)
}
pub fn pat_ty_opt(&self, pat: &hir::Pat<'_>) -> Option<Ty<'tcx>> {
self.node_type_opt(pat.hir_id)
}
// Returns the type of an expression as a monotype.
//
// NB (1): This is the PRE-ADJUSTMENT TYPE for the expression. That is, in

View File

@ -97,9 +97,6 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
fn has_infer_types_or_consts(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_INFER | TypeFlags::HAS_CT_INFER)
}
fn has_infer_consts(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_CT_INFER)
}
fn needs_infer(&self) -> bool {
self.has_type_flags(TypeFlags::NEEDS_INFER)
}
@ -113,9 +110,6 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
fn needs_subst(&self) -> bool {
self.has_type_flags(TypeFlags::NEEDS_SUBST)
}
fn has_re_placeholders(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_RE_PLACEHOLDER)
}
/// "Free" regions in this context means that it has any region
/// that is not (a) erased or (b) late-bound.
fn has_free_regions(&self) -> bool {
@ -719,21 +713,15 @@ impl<'tcx> TyCtxt<'tcx> {
// vars. See comment on `shift_vars_through_binders` method in
// `subst.rs` for more details.
enum Direction {
In,
Out,
}
struct Shifter<'tcx> {
tcx: TyCtxt<'tcx>,
current_index: ty::DebruijnIndex,
amount: u32,
direction: Direction,
}
impl Shifter<'tcx> {
pub fn new(tcx: TyCtxt<'tcx>, amount: u32, direction: Direction) -> Self {
Shifter { tcx, current_index: ty::INNERMOST, amount, direction }
pub fn new(tcx: TyCtxt<'tcx>, amount: u32) -> Self {
Shifter { tcx, current_index: ty::INNERMOST, amount }
}
}
@ -755,13 +743,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
if self.amount == 0 || debruijn < self.current_index {
r
} else {
let debruijn = match self.direction {
Direction::In => debruijn.shifted_in(self.amount),
Direction::Out => {
assert!(debruijn.as_u32() >= self.amount);
debruijn.shifted_out(self.amount)
}
};
let debruijn = debruijn.shifted_in(self.amount);
let shifted = ty::ReLateBound(debruijn, br);
self.tcx.mk_region(shifted)
}
@ -776,13 +758,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
if self.amount == 0 || debruijn < self.current_index {
ty
} else {
let debruijn = match self.direction {
Direction::In => debruijn.shifted_in(self.amount),
Direction::Out => {
assert!(debruijn.as_u32() >= self.amount);
debruijn.shifted_out(self.amount)
}
};
let debruijn = debruijn.shifted_in(self.amount);
self.tcx.mk_ty(ty::Bound(debruijn, bound_ty))
}
}
@ -796,13 +772,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
if self.amount == 0 || debruijn < self.current_index {
ct
} else {
let debruijn = match self.direction {
Direction::In => debruijn.shifted_in(self.amount),
Direction::Out => {
assert!(debruijn.as_u32() >= self.amount);
debruijn.shifted_out(self.amount)
}
};
let debruijn = debruijn.shifted_in(self.amount);
self.tcx.mk_const(ty::Const { val: ty::ConstKind::Bound(debruijn, bound_ct), ty })
}
} else {
@ -830,16 +800,7 @@ where
{
debug!("shift_vars(value={:?}, amount={})", value, amount);
value.fold_with(&mut Shifter::new(tcx, amount, Direction::In))
}
pub fn shift_out_vars<'tcx, T>(tcx: TyCtxt<'tcx>, value: &T, amount: u32) -> T
where
T: TypeFoldable<'tcx>,
{
debug!("shift_out_vars(value={:?}, amount={})", value, amount);
value.fold_with(&mut Shifter::new(tcx, amount, Direction::Out))
value.fold_with(&mut Shifter::new(tcx, amount))
}
/// An "escaping var" is a bound var whose binder is not part of `t`. A bound var can be a

View File

@ -104,14 +104,6 @@ impl<'tcx> TyCtxt<'tcx> {
// ```
ty.uninhabited_from(self, param_env).contains(self, module)
}
pub fn is_ty_uninhabited_from_any_module(
self,
ty: Ty<'tcx>,
param_env: ty::ParamEnv<'tcx>,
) -> bool {
!ty.uninhabited_from(self, param_env).is_empty()
}
}
impl<'tcx> AdtDef {

View File

@ -7,7 +7,6 @@ pub use self::Variance::*;
use crate::hir::exports::ExportMap;
use crate::ich::StableHashingContext;
use crate::infer::canonical::Canonical;
use crate::middle::cstore::CrateStoreDyn;
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
use crate::mir::interpret::ErrorHandled;
@ -656,8 +655,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TyS<'tcx> {
#[rustc_diagnostic_item = "Ty"]
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
pub type CanonicalTy<'tcx> = Canonical<'tcx, Ty<'tcx>>;
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
pub struct UpvarPath {
pub hir_id: hir::HirId,
@ -767,10 +764,6 @@ pub enum IntVarValue {
pub struct FloatVarValue(pub ast::FloatTy);
impl ty::EarlyBoundRegion {
pub fn to_bound_region(&self) -> ty::BoundRegion {
ty::BoundRegion::BrNamed(self.def_id, self.name)
}
/// Does this early bound region have a name? Early bound regions normally
/// always have names except when using anonymous lifetimes (`'_`).
pub fn has_name(&self) -> bool {
@ -821,14 +814,6 @@ impl GenericParamDef {
bug!("cannot convert a non-lifetime parameter def to an early bound region")
}
}
pub fn to_bound_region(&self) -> ty::BoundRegion {
if let GenericParamDefKind::Lifetime = self.kind {
self.to_early_bound_region_data().to_bound_region()
} else {
bug!("cannot convert a non-lifetime parameter def to an early bound region")
}
}
}
#[derive(Default)]
@ -1003,22 +988,6 @@ impl<'tcx> GenericPredicates<'tcx> {
instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p));
instantiated.spans.extend(self.predicates.iter().map(|(_, s)| s));
}
pub fn instantiate_supertrait(
&self,
tcx: TyCtxt<'tcx>,
poly_trait_ref: &ty::PolyTraitRef<'tcx>,
) -> InstantiatedPredicates<'tcx> {
assert_eq!(self.parent, None);
InstantiatedPredicates {
predicates: self
.predicates
.iter()
.map(|(pred, _)| pred.subst_supertrait(tcx, poly_trait_ref))
.collect(),
spans: self.predicates.iter().map(|(_, sp)| *sp).collect(),
}
}
}
#[derive(Debug)]
@ -1303,7 +1272,6 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
#[derive(HashStable, TypeFoldable)]
pub struct OutlivesPredicate<A, B>(pub A, pub B); // `A: B`
pub type PolyOutlivesPredicate<A, B> = ty::Binder<OutlivesPredicate<A, B>>;
pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>;
pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>;
pub type PolyRegionOutlivesPredicate<'tcx> = ty::Binder<RegionOutlivesPredicate<'tcx>>;

View File

@ -601,29 +601,6 @@ impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> {
Ok(ty)
}
fn cached_predicate_for_shorthand<F>(
&mut self,
shorthand: usize,
or_insert_with: F,
) -> Result<ty::Predicate<'tcx>, Self::Error>
where
F: FnOnce(&mut Self) -> Result<ty::Predicate<'tcx>, Self::Error>,
{
let tcx = self.tcx();
let cache_key =
ty::CReaderCacheKey { cnum: CrateNum::ReservedForIncrCompCache, pos: shorthand };
if let Some(&pred) = tcx.pred_rcache.borrow().get(&cache_key) {
return Ok(pred);
}
let pred = or_insert_with(self)?;
// This may overwrite the entry, but it should overwrite with the same value.
tcx.pred_rcache.borrow_mut().insert_same(cache_key, pred);
Ok(pred)
}
fn with_position<F, R>(&mut self, pos: usize, f: F) -> R
where
F: FnOnce(&mut Self) -> R,

View File

@ -1,6 +1,5 @@
// Type substitutions.
use crate::infer::canonical::Canonical;
use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use crate::ty::sty::{ClosureSubsts, GeneratorSubsts};
@ -648,8 +647,6 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
}
}
pub type CanonicalUserSubsts<'tcx> = Canonical<'tcx, UserSubsts<'tcx>>;
/// Stores the user-given substs to reach some fully qualified path
/// (e.g., `<T>::Item` or `<T as Trait>::Item`).
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]