Skip to content

Commit d7791f4

Browse files
committed
Remove unused code from rustc_middle
1 parent f243a2a commit d7791f4

File tree

12 files changed

+7
-214
lines changed

12 files changed

+7
-214
lines changed

compiler/rustc_middle/src/middle/privacy.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! which are available for use externally when compiled as a library.
44
55
use rustc_data_structures::fx::FxHashMap;
6-
use rustc_hir::def_id::DefIdSet;
76
use rustc_hir::HirId;
87
use rustc_macros::HashStable;
98
use std::fmt;
@@ -59,7 +58,3 @@ impl<Id: Hash + Eq + fmt::Debug> fmt::Debug for AccessLevels<Id> {
5958
fmt::Debug::fmt(&self.map, f)
6059
}
6160
}
62-
63-
/// A set containing all exported definitions from external crates.
64-
/// The set does not contain any entries from local crates.
65-
pub type ExternalExports = DefIdSet;

compiler/rustc_middle/src/mir/interpret/value.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ impl<'tcx> ConstValue<'tcx> {
5656
}
5757
}
5858

59-
pub fn try_to_str_slice(&self) -> Option<&'tcx str> {
60-
if let ConstValue::Slice { data, start, end } = *self {
61-
std::str::from_utf8(data.inspect_with_uninit_and_ptr_outside_interpreter(start..end))
62-
.ok()
63-
} else {
64-
None
65-
}
66-
}
67-
6859
pub fn try_to_bits(&self, size: Size) -> Option<u128> {
6960
self.try_to_scalar()?.to_bits(size).ok()
7061
}

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/mir/index.html
44
55
use crate::mir::coverage::{CodeRegion, CoverageKind};
6-
use crate::mir::interpret::{Allocation, ConstValue, GlobalAlloc, Scalar};
6+
use crate::mir::interpret::{Allocation, GlobalAlloc, Scalar};
77
use crate::mir::visit::MirVisitable;
88
use crate::ty::adjustment::PointerCast;
99
use crate::ty::codec::{TyDecoder, TyEncoder};
@@ -460,17 +460,6 @@ impl<'tcx> Body<'tcx> {
460460
}
461461
}
462462

463-
/// Checks if `sub` is a sub scope of `sup`
464-
pub fn is_sub_scope(&self, mut sub: SourceScope, sup: SourceScope) -> bool {
465-
while sub != sup {
466-
match self.source_scopes[sub].parent_scope {
467-
None => return false,
468-
Some(p) => sub = p,
469-
}
470-
}
471-
true
472-
}
473-
474463
/// Returns the return type; it always return first element from `local_decls` array.
475464
#[inline]
476465
pub fn return_ty(&self) -> Ty<'tcx> {
@@ -1978,45 +1967,6 @@ impl<'tcx> Operand<'tcx> {
19781967
})
19791968
}
19801969

1981-
/// Convenience helper to make a `Scalar` from the given `Operand`, assuming that `Operand`
1982-
/// wraps a constant literal value. Panics if this is not the case.
1983-
pub fn scalar_from_const(operand: &Operand<'tcx>) -> Scalar {
1984-
match operand {
1985-
Operand::Constant(constant) => match constant.literal.val.try_to_scalar() {
1986-
Some(scalar) => scalar,
1987-
_ => panic!("{:?}: Scalar value expected", constant.literal.val),
1988-
},
1989-
_ => panic!("{:?}: Constant expected", operand),
1990-
}
1991-
}
1992-
1993-
/// Convenience helper to make a literal-like constant from a given `&str` slice.
1994-
/// Since this is used to synthesize MIR, assumes `user_ty` is None.
1995-
pub fn const_from_str(tcx: TyCtxt<'tcx>, val: &str, span: Span) -> Operand<'tcx> {
1996-
let tcx = tcx;
1997-
let allocation = Allocation::from_byte_aligned_bytes(val.as_bytes());
1998-
let allocation = tcx.intern_const_alloc(allocation);
1999-
let const_val = ConstValue::Slice { data: allocation, start: 0, end: val.len() };
2000-
let ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, tcx.types.str_);
2001-
Operand::Constant(box Constant {
2002-
span,
2003-
user_ty: None,
2004-
literal: ty::Const::from_value(tcx, const_val, ty),
2005-
})
2006-
}
2007-
2008-
/// Convenience helper to make a `ConstValue` from the given `Operand`, assuming that `Operand`
2009-
/// wraps a constant value (such as a `&str` slice). Panics if this is not the case.
2010-
pub fn value_from_const(operand: &Operand<'tcx>) -> ConstValue<'tcx> {
2011-
match operand {
2012-
Operand::Constant(constant) => match constant.literal.val.try_to_value() {
2013-
Some(const_value) => const_value,
2014-
_ => panic!("{:?}: ConstValue expected", constant.literal.val),
2015-
},
2016-
_ => panic!("{:?}: Constant expected", operand),
2017-
}
2018-
}
2019-
20201970
pub fn to_copy(&self) -> Self {
20211971
match *self {
20221972
Operand::Copy(_) | Operand::Constant(_) => self.clone(),
@@ -2413,10 +2363,6 @@ impl<'tcx> UserTypeProjections {
24132363
self.contents.is_empty()
24142364
}
24152365

2416-
pub fn from_projections(projs: impl Iterator<Item = (UserTypeProjection, Span)>) -> Self {
2417-
UserTypeProjections { contents: projs.collect() }
2418-
}
2419-
24202366
pub fn projections_and_spans(
24212367
&self,
24222368
) -> impl Iterator<Item = &(UserTypeProjection, Span)> + ExactSizeIterator {

compiler/rustc_middle/src/mir/query.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,6 @@ pub struct CoverageInfo {
413413
/// For more information on why this is needed, consider looking
414414
/// at the docs for `WithOptConstParam` itself.
415415
impl<'tcx> TyCtxt<'tcx> {
416-
#[inline]
417-
pub fn mir_borrowck_opt_const_arg(
418-
self,
419-
def: ty::WithOptConstParam<LocalDefId>,
420-
) -> &'tcx BorrowCheckResult<'tcx> {
421-
if let Some(param_did) = def.const_param_did {
422-
self.mir_borrowck_const_arg((def.did, param_did))
423-
} else {
424-
self.mir_borrowck(def.did)
425-
}
426-
}
427-
428416
#[inline]
429417
pub fn mir_const_qualif_opt_const_arg(
430418
self,

compiler/rustc_middle/src/mir/visit.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,16 +1186,6 @@ impl PlaceContext {
11861186
)
11871187
}
11881188

1189-
/// Returns `true` if this place context represents a storage live marker.
1190-
pub fn is_storage_live_marker(&self) -> bool {
1191-
matches!(self, PlaceContext::NonUse(NonUseContext::StorageLive))
1192-
}
1193-
1194-
/// Returns `true` if this place context represents a storage dead marker.
1195-
pub fn is_storage_dead_marker(&self) -> bool {
1196-
matches!(self, PlaceContext::NonUse(NonUseContext::StorageDead))
1197-
}
1198-
11991189
/// Returns `true` if this place context represents a use that potentially changes the value.
12001190
pub fn is_mutating_use(&self) -> bool {
12011191
matches!(self, PlaceContext::MutatingUse(..))

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,6 @@ pub trait TyDecoder<'tcx>: Decoder {
182182
where
183183
F: FnOnce(&mut Self) -> Result<Ty<'tcx>, Self::Error>;
184184

185-
fn cached_predicate_for_shorthand<F>(
186-
&mut self,
187-
shorthand: usize,
188-
or_insert_with: F,
189-
) -> Result<ty::Predicate<'tcx>, Self::Error>
190-
where
191-
F: FnOnce(&mut Self) -> Result<ty::Predicate<'tcx>, Self::Error>;
192-
193185
fn with_position<F, R>(&mut self, pos: usize, f: F) -> R
194186
where
195187
F: FnOnce(&mut Self) -> R;

compiler/rustc_middle/src/ty/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,6 @@ impl<'tcx> TypeckResults<'tcx> {
534534
self.node_type(pat.hir_id)
535535
}
536536

537-
pub fn pat_ty_opt(&self, pat: &hir::Pat<'_>) -> Option<Ty<'tcx>> {
538-
self.node_type_opt(pat.hir_id)
539-
}
540-
541537
// Returns the type of an expression as a monotype.
542538
//
543539
// NB (1): This is the PRE-ADJUSTMENT TYPE for the expression. That is, in

compiler/rustc_middle/src/ty/fold.rs

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
9797
fn has_infer_types_or_consts(&self) -> bool {
9898
self.has_type_flags(TypeFlags::HAS_TY_INFER | TypeFlags::HAS_CT_INFER)
9999
}
100-
fn has_infer_consts(&self) -> bool {
101-
self.has_type_flags(TypeFlags::HAS_CT_INFER)
102-
}
103100
fn needs_infer(&self) -> bool {
104101
self.has_type_flags(TypeFlags::NEEDS_INFER)
105102
}
@@ -113,9 +110,6 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
113110
fn needs_subst(&self) -> bool {
114111
self.has_type_flags(TypeFlags::NEEDS_SUBST)
115112
}
116-
fn has_re_placeholders(&self) -> bool {
117-
self.has_type_flags(TypeFlags::HAS_RE_PLACEHOLDER)
118-
}
119113
/// "Free" regions in this context means that it has any region
120114
/// that is not (a) erased or (b) late-bound.
121115
fn has_free_regions(&self) -> bool {
@@ -719,21 +713,15 @@ impl<'tcx> TyCtxt<'tcx> {
719713
// vars. See comment on `shift_vars_through_binders` method in
720714
// `subst.rs` for more details.
721715

722-
enum Direction {
723-
In,
724-
Out,
725-
}
726-
727716
struct Shifter<'tcx> {
728717
tcx: TyCtxt<'tcx>,
729718
current_index: ty::DebruijnIndex,
730719
amount: u32,
731-
direction: Direction,
732720
}
733721

734722
impl Shifter<'tcx> {
735-
pub fn new(tcx: TyCtxt<'tcx>, amount: u32, direction: Direction) -> Self {
736-
Shifter { tcx, current_index: ty::INNERMOST, amount, direction }
723+
pub fn new(tcx: TyCtxt<'tcx>, amount: u32) -> Self {
724+
Shifter { tcx, current_index: ty::INNERMOST, amount }
737725
}
738726
}
739727

@@ -755,13 +743,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
755743
if self.amount == 0 || debruijn < self.current_index {
756744
r
757745
} else {
758-
let debruijn = match self.direction {
759-
Direction::In => debruijn.shifted_in(self.amount),
760-
Direction::Out => {
761-
assert!(debruijn.as_u32() >= self.amount);
762-
debruijn.shifted_out(self.amount)
763-
}
764-
};
746+
let debruijn = debruijn.shifted_in(self.amount);
765747
let shifted = ty::ReLateBound(debruijn, br);
766748
self.tcx.mk_region(shifted)
767749
}
@@ -776,13 +758,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
776758
if self.amount == 0 || debruijn < self.current_index {
777759
ty
778760
} else {
779-
let debruijn = match self.direction {
780-
Direction::In => debruijn.shifted_in(self.amount),
781-
Direction::Out => {
782-
assert!(debruijn.as_u32() >= self.amount);
783-
debruijn.shifted_out(self.amount)
784-
}
785-
};
761+
let debruijn = debruijn.shifted_in(self.amount);
786762
self.tcx.mk_ty(ty::Bound(debruijn, bound_ty))
787763
}
788764
}
@@ -796,13 +772,7 @@ impl TypeFolder<'tcx> for Shifter<'tcx> {
796772
if self.amount == 0 || debruijn < self.current_index {
797773
ct
798774
} else {
799-
let debruijn = match self.direction {
800-
Direction::In => debruijn.shifted_in(self.amount),
801-
Direction::Out => {
802-
assert!(debruijn.as_u32() >= self.amount);
803-
debruijn.shifted_out(self.amount)
804-
}
805-
};
775+
let debruijn = debruijn.shifted_in(self.amount);
806776
self.tcx.mk_const(ty::Const { val: ty::ConstKind::Bound(debruijn, bound_ct), ty })
807777
}
808778
} else {
@@ -830,16 +800,7 @@ where
830800
{
831801
debug!("shift_vars(value={:?}, amount={})", value, amount);
832802

833-
value.fold_with(&mut Shifter::new(tcx, amount, Direction::In))
834-
}
835-
836-
pub fn shift_out_vars<'tcx, T>(tcx: TyCtxt<'tcx>, value: &T, amount: u32) -> T
837-
where
838-
T: TypeFoldable<'tcx>,
839-
{
840-
debug!("shift_out_vars(value={:?}, amount={})", value, amount);
841-
842-
value.fold_with(&mut Shifter::new(tcx, amount, Direction::Out))
803+
value.fold_with(&mut Shifter::new(tcx, amount))
843804
}
844805

845806
/// An "escaping var" is a bound var whose binder is not part of `t`. A bound var can be a

compiler/rustc_middle/src/ty/inhabitedness/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,6 @@ impl<'tcx> TyCtxt<'tcx> {
104104
// ```
105105
ty.uninhabited_from(self, param_env).contains(self, module)
106106
}
107-
108-
pub fn is_ty_uninhabited_from_any_module(
109-
self,
110-
ty: Ty<'tcx>,
111-
param_env: ty::ParamEnv<'tcx>,
112-
) -> bool {
113-
!ty.uninhabited_from(self, param_env).is_empty()
114-
}
115107
}
116108

117109
impl<'tcx> AdtDef {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub use self::Variance::*;
77

88
use crate::hir::exports::ExportMap;
99
use crate::ich::StableHashingContext;
10-
use crate::infer::canonical::Canonical;
1110
use crate::middle::cstore::CrateStoreDyn;
1211
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
1312
use crate::mir::interpret::ErrorHandled;
@@ -656,8 +655,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TyS<'tcx> {
656655
#[rustc_diagnostic_item = "Ty"]
657656
pub type Ty<'tcx> = &'tcx TyS<'tcx>;
658657

659-
pub type CanonicalTy<'tcx> = Canonical<'tcx, Ty<'tcx>>;
660-
661658
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)]
662659
pub struct UpvarPath {
663660
pub hir_id: hir::HirId,
@@ -767,10 +764,6 @@ pub enum IntVarValue {
767764
pub struct FloatVarValue(pub ast::FloatTy);
768765

769766
impl ty::EarlyBoundRegion {
770-
pub fn to_bound_region(&self) -> ty::BoundRegion {
771-
ty::BoundRegion::BrNamed(self.def_id, self.name)
772-
}
773-
774767
/// Does this early bound region have a name? Early bound regions normally
775768
/// always have names except when using anonymous lifetimes (`'_`).
776769
pub fn has_name(&self) -> bool {
@@ -821,14 +814,6 @@ impl GenericParamDef {
821814
bug!("cannot convert a non-lifetime parameter def to an early bound region")
822815
}
823816
}
824-
825-
pub fn to_bound_region(&self) -> ty::BoundRegion {
826-
if let GenericParamDefKind::Lifetime = self.kind {
827-
self.to_early_bound_region_data().to_bound_region()
828-
} else {
829-
bug!("cannot convert a non-lifetime parameter def to an early bound region")
830-
}
831-
}
832817
}
833818

834819
#[derive(Default)]
@@ -1003,22 +988,6 @@ impl<'tcx> GenericPredicates<'tcx> {
1003988
instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| p));
1004989
instantiated.spans.extend(self.predicates.iter().map(|(_, s)| s));
1005990
}
1006-
1007-
pub fn instantiate_supertrait(
1008-
&self,
1009-
tcx: TyCtxt<'tcx>,
1010-
poly_trait_ref: &ty::PolyTraitRef<'tcx>,
1011-
) -> InstantiatedPredicates<'tcx> {
1012-
assert_eq!(self.parent, None);
1013-
InstantiatedPredicates {
1014-
predicates: self
1015-
.predicates
1016-
.iter()
1017-
.map(|(pred, _)| pred.subst_supertrait(tcx, poly_trait_ref))
1018-
.collect(),
1019-
spans: self.predicates.iter().map(|(_, sp)| *sp).collect(),
1020-
}
1021-
}
1022991
}
1023992

1024993
#[derive(Debug)]
@@ -1303,7 +1272,6 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
13031272
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)]
13041273
#[derive(HashStable, TypeFoldable)]
13051274
pub struct OutlivesPredicate<A, B>(pub A, pub B); // `A: B`
1306-
pub type PolyOutlivesPredicate<A, B> = ty::Binder<OutlivesPredicate<A, B>>;
13071275
pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>;
13081276
pub type TypeOutlivesPredicate<'tcx> = OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>;
13091277
pub type PolyRegionOutlivesPredicate<'tcx> = ty::Binder<RegionOutlivesPredicate<'tcx>>;

0 commit comments

Comments
 (0)