Skip to content

Commit

Permalink
Remove (lots of) dead code
Browse files Browse the repository at this point in the history
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
  rust-lang/compiler-team#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.
  • Loading branch information
jyn514 committed Mar 28, 2021
1 parent 785aeac commit 441dc36
Show file tree
Hide file tree
Showing 74 changed files with 60 additions and 1,298 deletions.
20 changes: 0 additions & 20 deletions compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,26 +236,6 @@ impl<T> TypedArena<T> {
start_ptr
}

/// Allocates a slice of objects that are copied into the `TypedArena`, returning a mutable
/// reference to it. Will panic if passed a zero-sized types.
///
/// Panics:
///
/// - Zero-sized types
/// - Zero-length slices
#[inline]
pub fn alloc_slice(&self, slice: &[T]) -> &mut [T]
where
T: Copy,
{
unsafe {
let len = slice.len();
let start_ptr = self.alloc_raw_slice(len);
slice.as_ptr().copy_to_nonoverlapping(start_ptr, len);
slice::from_raw_parts_mut(start_ptr, len)
}
}

#[inline]
pub fn alloc_from_iter<I: IntoIterator<Item = T>>(&self, iter: I) -> &mut [T] {
assert!(mem::size_of::<T>() != 0);
Expand Down
64 changes: 0 additions & 64 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,6 @@ pub enum Mutability {
}

impl Mutability {
/// Returns `MutMutable` only if both `self` and `other` are mutable.
pub fn and(self, other: Self) -> Self {
match self {
Mutability::Mut => other,
Mutability::Not => Mutability::Not,
}
}

pub fn invert(self) -> Self {
match self {
Mutability::Mut => Mutability::Not,
Expand Down Expand Up @@ -1722,13 +1714,6 @@ impl FloatTy {
FloatTy::F64 => sym::f64,
}
}

pub fn bit_width(self) -> u64 {
match self {
FloatTy::F32 => 32,
FloatTy::F64 => 64,
}
}
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
Expand Down Expand Up @@ -1764,29 +1749,6 @@ impl IntTy {
IntTy::I128 => sym::i128,
}
}

pub fn bit_width(&self) -> Option<u64> {
Some(match *self {
IntTy::Isize => return None,
IntTy::I8 => 8,
IntTy::I16 => 16,
IntTy::I32 => 32,
IntTy::I64 => 64,
IntTy::I128 => 128,
})
}

pub fn normalize(&self, target_width: u32) -> Self {
match self {
IntTy::Isize => match target_width {
16 => IntTy::I16,
32 => IntTy::I32,
64 => IntTy::I64,
_ => unreachable!(),
},
_ => *self,
}
}
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
Expand Down Expand Up @@ -1822,29 +1784,6 @@ impl UintTy {
UintTy::U128 => sym::u128,
}
}

pub fn bit_width(&self) -> Option<u64> {
Some(match *self {
UintTy::Usize => return None,
UintTy::U8 => 8,
UintTy::U16 => 16,
UintTy::U32 => 32,
UintTy::U64 => 64,
UintTy::U128 => 128,
})
}

pub fn normalize(&self, target_width: u32) -> Self {
match self {
UintTy::Usize => match target_width {
16 => UintTy::U16,
32 => UintTy::U32,
64 => UintTy::U64,
_ => unreachable!(),
},
_ => *self,
}
}
}

/// A constraint on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
Expand Down Expand Up @@ -2215,9 +2154,6 @@ pub struct FnDecl {
}

impl FnDecl {
pub fn get_self(&self) -> Option<ExplicitSelf> {
self.inputs.get(0).and_then(Param::to_self)
}
pub fn has_self(&self) -> bool {
self.inputs.get(0).map_or(false, Param::is_self)
}
Expand Down
40 changes: 1 addition & 39 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,7 @@ impl NestedMetaItem {
self.meta_item().map_or(false, |meta_item| meta_item.is_word())
}

/// Returns `true` if `self` is a `MetaItem` and the meta item is a `ValueString`.
pub fn is_value_str(&self) -> bool {
self.value_str().is_some()
}

/// Returns `true` if `self` is a `MetaItem` and the meta item is a list.
pub fn is_meta_item_list(&self) -> bool {
self.meta_item_list().is_some()
}

/// See [`MetaItem::name_value_literal_span`].
pub fn name_value_literal_span(&self) -> Option<Span> {
self.meta_item()?.name_value_literal_span()
}
Expand Down Expand Up @@ -165,31 +156,6 @@ impl Attribute {
false
}
}

pub fn is_meta_item_list(&self) -> bool {
self.meta_item_list().is_some()
}

/// Indicates if the attribute is a `ValueString`.
pub fn is_value_str(&self) -> bool {
self.value_str().is_some()
}

/// This is used in case you want the value span instead of the whole attribute. Example:
///
/// ```text
/// #[doc(alias = "foo")]
/// ```
///
/// In here, it'll return a span for `"foo"`.
pub fn name_value_literal_span(&self) -> Option<Span> {
match self.kind {
AttrKind::Normal(ref item, _) => {
item.meta(self.span).and_then(|meta| meta.name_value_literal_span())
}
AttrKind::DocComment(..) => None,
}
}
}

impl MetaItem {
Expand Down Expand Up @@ -236,10 +202,6 @@ impl MetaItem {
self.path == name
}

pub fn is_value_str(&self) -> bool {
self.value_str().is_some()
}

/// This is used in case you want the value span instead of the whole attribute. Example:
///
/// ```text
Expand Down
20 changes: 0 additions & 20 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ impl TokenTree {
}
}

pub fn joint(self) -> TokenStream {
TokenStream::new(vec![(self, Spacing::Joint)])
}

pub fn token(kind: TokenKind, span: Span) -> TokenTree {
TokenTree::Token(Token::new(kind, span))
}
Expand Down Expand Up @@ -278,14 +274,6 @@ impl TokenStream {
self.0.len()
}

pub fn span(&self) -> Option<Span> {
match &**self.0 {
[] => None,
[(tt, _)] => Some(tt.span()),
[(tt_start, _), .., (tt_end, _)] => Some(tt_start.span().to(tt_end.span())),
}
}

pub fn from_streams(mut streams: SmallVec<[TokenStream; 2]>) -> TokenStream {
match streams.len() {
0 => TokenStream::default(),
Expand Down Expand Up @@ -325,10 +313,6 @@ impl TokenStream {
}
}

pub fn trees_ref(&self) -> CursorRef<'_> {
CursorRef::new(self)
}

pub fn trees(&self) -> Cursor {
self.clone().into_trees()
}
Expand Down Expand Up @@ -427,10 +411,6 @@ pub struct CursorRef<'t> {
}

impl<'t> CursorRef<'t> {
fn new(stream: &TokenStream) -> CursorRef<'_> {
CursorRef { stream, index: 0 }
}

fn next_with_spacing(&mut self) -> Option<&'t TreeAndSpacing> {
self.stream.0.get(self.index).map(|tree| {
self.index += 1;
Expand Down
24 changes: 0 additions & 24 deletions compiler/rustc_ast_pretty/src/pprust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ pub fn token_to_string(token: &Token) -> String {
State::new().token_to_string(token)
}

pub fn token_to_string_ext(token: &Token, convert_dollar_crate: bool) -> String {
State::new().token_to_string_ext(token, convert_dollar_crate)
}

pub fn ty_to_string(ty: &ast::Ty) -> String {
State::new().ty_to_string(ty)
}
Expand All @@ -50,18 +46,10 @@ pub fn tts_to_string(tokens: &TokenStream) -> String {
State::new().tts_to_string(tokens)
}

pub fn stmt_to_string(stmt: &ast::Stmt) -> String {
State::new().stmt_to_string(stmt)
}

pub fn item_to_string(i: &ast::Item) -> String {
State::new().item_to_string(i)
}

pub fn generic_params_to_string(generic_params: &[ast::GenericParam]) -> String {
State::new().generic_params_to_string(generic_params)
}

pub fn path_to_string(p: &ast::Path) -> String {
State::new().path_to_string(p)
}
Expand All @@ -74,26 +62,14 @@ pub fn vis_to_string(v: &ast::Visibility) -> String {
State::new().vis_to_string(v)
}

pub fn block_to_string(blk: &ast::Block) -> String {
State::new().block_to_string(blk)
}

pub fn meta_list_item_to_string(li: &ast::NestedMetaItem) -> String {
State::new().meta_list_item_to_string(li)
}

pub fn attr_item_to_string(ai: &ast::AttrItem) -> String {
State::new().attr_item_to_string(ai)
}

pub fn attribute_to_string(attr: &ast::Attribute) -> String {
State::new().attribute_to_string(attr)
}

pub fn param_to_string(arg: &ast::Param) -> String {
State::new().param_to_string(arg)
}

pub fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
State::new().to_string(f)
}
4 changes: 0 additions & 4 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,10 +2292,6 @@ impl<'a> State<'a> {
}
}

pub fn print_usize(&mut self, i: usize) {
self.s.word(i.to_string())
}

crate fn print_name(&mut self, name: Symbol) {
self.s.word(name.to_string());
self.ann.post(self, AnnNode::Name(&name))
Expand Down
Loading

0 comments on commit 441dc36

Please sign in to comment.