1
Fork 0

Remove (lots of) dead code

Found with https://github.com/est31/warnalyzer.

Dubious changes:
- Is anyone else using rustc_apfloat? I feel weird completely deleting
  x87 support.
- Maybe some of the dead code in rustc_data_structures, in case someone
  wants to use it in the future?
- Don't change rustc_serialize

  I plan to scrap most of the json module in the near future (see
  https://github.com/rust-lang/compiler-team/issues/418) and fixing the
  tests needed more work than I expected.

TODO: check if any of the comments on the deleted code should be kept.
This commit is contained in:
Joshua Nelson 2021-03-16 01:50:34 -04:00
parent 785aeac521
commit 441dc3640a
74 changed files with 60 additions and 1298 deletions

View file

@ -550,24 +550,6 @@ impl<'hir> Map<'hir> {
ParentHirIterator { current_id, map: self }
}
/// Checks if the node is an argument. An argument is a local variable whose
/// immediate parent is an item or a closure.
pub fn is_argument(&self, id: HirId) -> bool {
match self.find(id) {
Some(Node::Binding(_)) => (),
_ => return false,
}
matches!(
self.find(self.get_parent_node(id)),
Some(
Node::Item(_)
| Node::TraitItem(_)
| Node::ImplItem(_)
| Node::Expr(Expr { kind: ExprKind::Closure(..), .. }),
)
)
}
/// Checks if the node is left-hand side of an assignment.
pub fn is_lhs(&self, id: HirId) -> bool {
match self.find(self.get_parent_node(id)) {
@ -779,17 +761,6 @@ impl<'hir> Map<'hir> {
}
}
pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData<'hir> {
match self.find(id) {
Some(
Node::Ctor(vd)
| Node::Item(Item { kind: ItemKind::Struct(vd, _) | ItemKind::Union(vd, _), .. }),
) => vd,
Some(Node::Variant(variant)) => &variant.data,
_ => bug!("expected struct or variant, found {}", self.node_to_string(id)),
}
}
pub fn expect_variant(&self, id: HirId) -> &'hir Variant<'hir> {
match self.find(id) {
Some(Node::Variant(variant)) => variant,

View file

@ -119,11 +119,6 @@ impl<'a> StableHashingContext<'a> {
Self::new_with_or_without_spans(sess, krate, definitions, cstore, always_ignore_spans)
}
#[inline]
pub fn sess(&self) -> &'a Session {
self.sess
}
#[inline]
pub fn while_hashing_hir_bodies<F: FnOnce(&mut Self)>(&mut self, hash_bodies: bool, f: F) {
let prev_hash_bodies = self.hash_bodies;

View file

@ -228,20 +228,12 @@ impl Certainty {
Certainty::Ambiguous => false,
}
}
pub fn is_ambiguous(&self) -> bool {
!self.is_proven()
}
}
impl<'tcx, R> QueryResponse<'tcx, R> {
pub fn is_proven(&self) -> bool {
self.certainty.is_proven()
}
pub fn is_ambiguous(&self) -> bool {
!self.is_proven()
}
}
impl<'tcx, R> Canonical<'tcx, QueryResponse<'tcx, R>> {

View file

@ -97,13 +97,6 @@ impl<'tcx> ConstVariableValue<'tcx> {
ConstVariableValue::Known { value } => Some(value),
}
}
pub fn is_unknown(&self) -> bool {
match *self {
ConstVariableValue::Unknown { .. } => true,
ConstVariableValue::Known { .. } => false,
}
}
}
#[derive(Copy, Clone, Debug)]

View file

@ -430,6 +430,8 @@ impl ScopeTree {
/// Returns `true` if `subscope` is equal to or is lexically nested inside `superscope`, and
/// `false` otherwise.
///
/// Used by clippy.
pub fn is_subscope_of(&self, subscope: Scope, superscope: Scope) -> bool {
let mut s = subscope;
debug!("is_subscope_of({:?}, {:?})", subscope, superscope);

View file

@ -29,12 +29,6 @@ pub enum StabilityLevel {
Stable,
}
impl StabilityLevel {
pub fn from_attr_level(level: &attr::StabilityLevel) -> Self {
if level.is_stable() { Stable } else { Unstable }
}
}
/// An entry in the `depr_map`.
#[derive(Clone, HashStable, Debug)]
pub struct DeprecationEntry {

View file

@ -117,17 +117,9 @@ impl CoverageKind {
}
}
pub fn is_counter(&self) -> bool {
matches!(self, Self::Counter { .. })
}
pub fn is_expression(&self) -> bool {
matches!(self, Self::Expression { .. })
}
pub fn is_unreachable(&self) -> bool {
*self == Self::Unreachable
}
}
impl Debug for CoverageKind {

View file

@ -307,16 +307,6 @@ impl<'tcx, Tag> Scalar<Tag> {
.unwrap_or_else(|| bug!("Signed value {:#x} does not fit in {} bits", i, size.bits()))
}
#[inline]
pub fn from_i8(i: i8) -> Self {
Self::from_int(i, Size::from_bits(8))
}
#[inline]
pub fn from_i16(i: i16) -> Self {
Self::from_int(i, Size::from_bits(16))
}
#[inline]
pub fn from_i32(i: i32) -> Self {
Self::from_int(i, Size::from_bits(32))

View file

@ -379,24 +379,6 @@ impl<'tcx> Body<'tcx> {
}
}
/// Returns an iterator over all temporaries.
#[inline]
pub fn temps_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
if self.local_decls[local].is_user_variable() { None } else { Some(local) }
})
}
/// Returns an iterator over all user-declared locals.
#[inline]
pub fn vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
self.local_decls[local].is_user_variable().then_some(local)
})
}
/// Returns an iterator over all user-declared mutable locals.
#[inline]
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {

View file

@ -264,10 +264,6 @@ impl<'a, 'tcx> ReversePostorder<'a, 'tcx> {
ReversePostorder { body, blocks, idx: len }
}
pub fn reset(&mut self) {
self.idx = self.blocks.len();
}
}
pub fn reverse_postorder<'a, 'tcx>(body: &'a Body<'tcx>) -> ReversePostorder<'a, 'tcx> {

View file

@ -1247,12 +1247,6 @@ impl PlaceContext {
matches!(self, PlaceContext::MutatingUse(..))
}
/// Returns `true` if this place context represents a use that does not change the value.
#[inline]
pub fn is_nonmutating_use(&self) -> bool {
matches!(self, PlaceContext::NonMutatingUse(..))
}
/// Returns `true` if this place context represents a use.
#[inline]
pub fn is_use(&self) -> bool {

View file

@ -44,24 +44,12 @@ pub mod type_op {
pub b: Ty<'tcx>,
}
impl<'tcx> Eq<'tcx> {
pub fn new(a: Ty<'tcx>, b: Ty<'tcx>) -> Self {
Self { a, b }
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
pub struct Subtype<'tcx> {
pub sub: Ty<'tcx>,
pub sup: Ty<'tcx>,
}
impl<'tcx> Subtype<'tcx> {
pub fn new(sub: Ty<'tcx>, sup: Ty<'tcx>) -> Self {
Self { sub, sup }
}
}
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, HashStable, TypeFoldable, Lift)]
pub struct ProvePredicate<'tcx> {
pub predicate: Predicate<'tcx>,

View file

@ -6,7 +6,6 @@ use crate::ty;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_span::Span;
use super::{Ty, TyCtxt};
@ -113,14 +112,6 @@ impl<'tcx> ClosureKind {
// This is the initial value used when doing upvar inference.
pub const LATTICE_BOTTOM: ClosureKind = ClosureKind::Fn;
pub fn trait_did(&self, tcx: TyCtxt<'tcx>) -> DefId {
match *self {
ClosureKind::Fn => tcx.require_lang_item(LangItem::Fn, None),
ClosureKind::FnMut => tcx.require_lang_item(LangItem::FnMut, None),
ClosureKind::FnOnce => tcx.require_lang_item(LangItem::FnOnce, None),
}
}
/// Returns `true` if a type that impls this closure kind
/// must also implement `other`.
pub fn extends(self, other: ty::ClosureKind) -> bool {
@ -377,12 +368,4 @@ impl BorrowKind {
UniqueImmBorrow => hir::Mutability::Mut,
}
}
pub fn to_user_str(&self) -> &'static str {
match *self {
MutBorrow => "mutable",
ImmBorrow => "immutable",
UniqueImmBorrow => "uniquely immutable",
}
}
}

View file

@ -188,7 +188,7 @@ pub trait TyDecoder<'tcx>: Decoder {
}
#[inline]
pub fn decode_arena_allocable<'tcx, D, T: ArenaAllocatable<'tcx> + Decodable<D>>(
fn decode_arena_allocable<'tcx, D, T: ArenaAllocatable<'tcx> + Decodable<D>>(
decoder: &mut D,
) -> Result<&'tcx T, D::Error>
where
@ -198,7 +198,7 @@ where
}
#[inline]
pub fn decode_arena_allocable_slice<'tcx, D, T: ArenaAllocatable<'tcx> + Decodable<D>>(
fn decode_arena_allocable_slice<'tcx, D, T: ArenaAllocatable<'tcx> + Decodable<D>>(
decoder: &mut D,
) -> Result<&'tcx [T], D::Error>
where

View file

@ -14,7 +14,7 @@ use crate::middle::stability;
use crate::mir::interpret::{self, Allocation, ConstValue, Scalar};
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
use crate::traits;
use crate::ty::query::{self, OnDiskCache, TyCtxtAt};
use crate::ty::query::{self, OnDiskCache};
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts};
use crate::ty::TyKind::*;
use crate::ty::{
@ -2288,11 +2288,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_ptr(TypeAndMut { ty, mutbl: hir::Mutability::Not })
}
#[inline]
pub fn mk_nil_ptr(self) -> Ty<'tcx> {
self.mk_imm_ptr(self.mk_unit())
}
#[inline]
pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
self.mk_ty(Array(ty, ty::Const::from_usize(self, n)))
@ -2655,21 +2650,6 @@ impl<'tcx> TyCtxt<'tcx> {
}
}
impl TyCtxtAt<'tcx> {
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
#[track_caller]
pub fn ty_error(self) -> Ty<'tcx> {
self.tcx.ty_error_with_message(self.span, "TyKind::Error constructed but no error reported")
}
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to
/// ensure it gets used.
#[track_caller]
pub fn ty_error_with_message(self, msg: &str) -> Ty<'tcx> {
self.tcx.ty_error_with_message(self.span, msg)
}
}
pub trait InternAs<T: ?Sized, R> {
type Output;
fn intern_with<F>(self, f: F) -> Self::Output

View file

@ -618,22 +618,12 @@ pub struct ProjectionPredicate<'tcx> {
pub type PolyProjectionPredicate<'tcx> = Binder<ProjectionPredicate<'tcx>>;
impl<'tcx> PolyProjectionPredicate<'tcx> {
/// Returns the `DefId` of the associated item being projected.
pub fn item_def_id(&self) -> DefId {
self.skip_binder().projection_ty.item_def_id
}
/// Returns the `DefId` of the trait of the associated item being projected.
#[inline]
pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId {
self.skip_binder().projection_ty.trait_def_id(tcx)
}
#[inline]
pub fn projection_self_ty(&self) -> Binder<Ty<'tcx>> {
self.map_bound(|predicate| predicate.projection_ty.self_ty())
}
/// Get the [PolyTraitRef] required for this projection to be well formed.
/// Note that for generic associated types the predicates of the associated
/// type also need to be checked.
@ -1039,10 +1029,6 @@ impl WithOptConstParam<DefId> {
None
}
pub fn expect_local(self) -> WithOptConstParam<LocalDefId> {
self.as_local().unwrap()
}
pub fn is_local(self) -> bool {
self.did.is_local()
}
@ -1222,11 +1208,6 @@ pub trait WithConstness: Sized {
ConstnessAnd { constness, value: self }
}
#[inline]
fn with_const(self) -> ConstnessAnd<Self> {
self.with_constness(Constness::Const)
}
#[inline]
fn without_const(self) -> ConstnessAnd<Self> {
self.with_constness(Constness::NotConst)

View file

@ -977,22 +977,6 @@ impl<T> Binder<T> {
Binder(value)
}
/// Wraps `value` in a binder without actually binding any currently
/// unbound variables.
///
/// Note that this will shift all debrujin indices of escaping bound variables
/// by 1 to avoid accidential captures.
pub fn wrap_nonbinding(tcx: TyCtxt<'tcx>, value: T) -> Binder<T>
where
T: TypeFoldable<'tcx>,
{
if value.has_escaping_bound_vars() {
Binder::bind(super::fold::shift_vars(tcx, value, 1))
} else {
Binder::dummy(value)
}
}
/// Skips the binder and returns the "bound" value. This is a
/// risky thing to do because it's easy to get confused about
/// De Bruijn indices and the like. It is usually better to
@ -1074,20 +1058,6 @@ impl<T> Binder<T> {
{
Binder(f(self.0, u.0))
}
/// Splits the contents into two things that share the same binder
/// level as the original, returning two distinct binders.
///
/// `f` should consider bound regions at depth 1 to be free, and
/// anything it produces with bound regions at depth 1 will be
/// bound in the resulting return values.
pub fn split<U, V, F>(self, f: F) -> (Binder<U>, Binder<V>)
where
F: FnOnce(T) -> (U, V),
{
let (u, v) = f(self.0);
(Binder(u), Binder(v))
}
}
impl<T> Binder<Option<T>> {
@ -1157,18 +1127,6 @@ pub struct GenSig<'tcx> {
pub type PolyGenSig<'tcx> = Binder<GenSig<'tcx>>;
impl<'tcx> PolyGenSig<'tcx> {
pub fn resume_ty(&self) -> ty::Binder<Ty<'tcx>> {
self.map_bound_ref(|sig| sig.resume_ty)
}
pub fn yield_ty(&self) -> ty::Binder<Ty<'tcx>> {
self.map_bound_ref(|sig| sig.yield_ty)
}
pub fn return_ty(&self) -> ty::Binder<Ty<'tcx>> {
self.map_bound_ref(|sig| sig.return_ty)
}
}
/// Signature of a function type, which we have arbitrarily
/// decided to use to refer to the input/output types.
///
@ -1248,10 +1206,6 @@ impl<'tcx> ParamTy {
ParamTy { index, name }
}
pub fn for_self() -> ParamTy {
ParamTy::new(0, kw::SelfUpper)
}
pub fn for_def(def: &ty::GenericParamDef) -> ParamTy {
ParamTy::new(def.index, def.name)
}
@ -1269,7 +1223,7 @@ pub struct ParamConst {
pub name: Symbol,
}
impl<'tcx> ParamConst {
impl ParamConst {
pub fn new(index: u32, name: Symbol) -> ParamConst {
ParamConst { index, name }
}
@ -1277,10 +1231,6 @@ impl<'tcx> ParamConst {
pub fn for_def(def: &ty::GenericParamDef) -> ParamConst {
ParamConst::new(def.index, def.name)
}
pub fn to_const(self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
tcx.mk_const_param(self.index, self.name, ty)
}
}
pub type Region<'tcx> = &'tcx RegionKind;
@ -1580,35 +1530,6 @@ impl RegionKind {
}
}
/// Adjusts any De Bruijn indices so as to make `to_binder` the
/// innermost binder. That is, if we have something bound at `to_binder`,
/// it will now be bound at INNERMOST. This is an appropriate thing to do
/// when moving a region out from inside binders:
///
/// ```
/// for<'a> fn(for<'b> for<'c> fn(&'a u32), _)
/// // Binder: D3 D2 D1 ^^
/// ```
///
/// Here, the region `'a` would have the De Bruijn index D3,
/// because it is the bound 3 binders out. However, if we wanted
/// to refer to that region `'a` in the second argument (the `_`),
/// those two binders would not be in scope. In that case, we
/// might invoke `shift_out_to_binder(D3)`. This would adjust the
/// De Bruijn index of `'a` to D1 (the innermost binder).
///
/// If we invoke `shift_out_to_binder` and the region is in fact
/// bound by one of the binders we are shifting out of, that is an
/// error (and should fail an assertion failure).
pub fn shifted_out_to_binder(&self, to_binder: ty::DebruijnIndex) -> RegionKind {
match *self {
ty::ReLateBound(debruijn, r) => {
ty::ReLateBound(debruijn.shifted_out_to_binder(to_binder), r)
}
r => r,
}
}
pub fn type_flags(&self) -> TypeFlags {
let mut flags = TypeFlags::empty();