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

@ -87,6 +87,7 @@ impl DefPathTable {
hash
}
/// Used by librustdoc for fake DefIds.
pub fn num_def_ids(&self) -> usize {
self.index_to_key.len()
}
@ -319,12 +320,6 @@ impl Definitions {
self.table.def_path_hash(id.local_def_index)
}
#[inline]
pub fn def_path_hash_to_def_id(&self, def_path_hash: DefPathHash) -> LocalDefId {
let local_def_index = self.table.def_path_hash_to_index[&def_path_hash];
LocalDefId { local_def_index }
}
/// Returns the path from the crate root to `index`. The root
/// nodes are not included in the path (i.e., this will be an
/// empty vector for the crate root). For an inlined item, this

View file

@ -1,5 +1,5 @@
// ignore-tidy-filelength
use crate::def::{CtorKind, DefKind, Namespace, Res};
use crate::def::{CtorKind, DefKind, Res};
use crate::def_id::DefId;
crate use crate::hir_id::HirId;
use crate::{itemlikevisit, LangItem};
@ -2118,15 +2118,6 @@ pub enum ImplItemKind<'hir> {
TyAlias(&'hir Ty<'hir>),
}
impl ImplItemKind<'_> {
pub fn namespace(&self) -> Namespace {
match self {
ImplItemKind::TyAlias(..) => Namespace::TypeNS,
ImplItemKind::Const(..) | ImplItemKind::Fn(..) => Namespace::ValueNS,
}
}
}
// The name of the associated type for `Fn` return types.
pub const FN_OUTPUT_NAME: Symbol = sym::Output;
@ -2215,6 +2206,9 @@ impl PrimTy {
Self::Str,
];
/// [`PrimTy::name`], but returns a &str instead of a symbol.
///
/// Used by rustdoc.
pub fn name_str(self) -> &'static str {
match self {
PrimTy::Int(i) => i.name_str(),

View file

@ -1,5 +1,4 @@
use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
use rustc_index::vec::IndexVec;
use std::fmt;
/// Uniquely identifies a node in the HIR of the current crate. It is
@ -62,69 +61,3 @@ pub const CRATE_HIR_ID: HirId = HirId {
owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
local_id: ItemLocalId::from_u32(0),
};
#[derive(Clone, Default, Debug, Encodable, Decodable)]
pub struct HirIdVec<T> {
map: IndexVec<LocalDefId, IndexVec<ItemLocalId, T>>,
}
impl<T> HirIdVec<T> {
pub fn push_owner(&mut self, id: LocalDefId) {
self.map.ensure_contains_elem(id, IndexVec::new);
}
pub fn push(&mut self, id: HirId, value: T) {
if id.local_id == ItemLocalId::from_u32(0) {
self.push_owner(id.owner);
}
let submap = &mut self.map[id.owner];
let _ret_id = submap.push(value);
debug_assert_eq!(_ret_id, id.local_id);
}
pub fn push_sparse(&mut self, id: HirId, value: T)
where
T: Default,
{
self.map.ensure_contains_elem(id.owner, IndexVec::new);
let submap = &mut self.map[id.owner];
let i = id.local_id.index();
let len = submap.len();
if i >= len {
submap.extend(std::iter::repeat_with(T::default).take(i - len + 1));
}
submap[id.local_id] = value;
}
pub fn get(&self, id: HirId) -> Option<&T> {
self.map.get(id.owner)?.get(id.local_id)
}
pub fn get_owner(&self, id: LocalDefId) -> &IndexVec<ItemLocalId, T> {
&self.map[id]
}
pub fn iter(&self) -> impl Iterator<Item = &T> {
self.map.iter().flat_map(|la| la.iter())
}
pub fn iter_enumerated(&self) -> impl Iterator<Item = (HirId, &T)> {
self.map.iter_enumerated().flat_map(|(owner, la)| {
la.iter_enumerated().map(move |(local_id, attr)| (HirId { owner, local_id }, attr))
})
}
}
impl<T> std::ops::Index<HirId> for HirIdVec<T> {
type Output = T;
fn index(&self, id: HirId) -> &T {
&self.map[id.owner][id.local_id]
}
}
impl<T> std::ops::IndexMut<HirId> for HirIdVec<T> {
fn index_mut(&mut self, id: HirId) -> &mut T {
&mut self.map[id.owner][id.local_id]
}
}

View file

@ -89,26 +89,6 @@ impl hir::Pat<'_> {
})
}
/// Checks if the pattern contains any patterns that bind something to
/// an ident, e.g., `foo`, or `Foo(foo)` or `foo @ Bar(..)`.
pub fn contains_bindings(&self) -> bool {
self.satisfies(|p| matches!(p.kind, PatKind::Binding(..)))
}
/// Checks if the pattern satisfies the given predicate on some sub-pattern.
fn satisfies(&self, pred: impl Fn(&hir::Pat<'_>) -> bool) -> bool {
let mut satisfies = false;
self.walk_short(|p| {
if pred(p) {
satisfies = true;
false // Found one, can short circuit now.
} else {
true
}
});
satisfies
}
pub fn simple_ident(&self) -> Option<Ident> {
match self.kind {
PatKind::Binding(