Remove unused Display implementation for consts

This commit is contained in:
mcarton 2016-02-07 18:14:03 +01:00
parent 34812e82d0
commit d27aa960b6

View file

@ -6,12 +6,10 @@ use rustc::middle::def::PathResolution;
use rustc::middle::def::Def;
use rustc_front::hir::*;
use syntax::ptr::P;
use std::char;
use std::cmp::PartialOrd;
use std::cmp::Ordering::{self, Greater, Less, Equal};
use std::rc::Rc;
use std::ops::Deref;
use std::fmt;
use syntax::ast::Lit_;
use syntax::ast::LitIntType;
@ -173,90 +171,6 @@ impl PartialOrd for Constant {
}
}
fn format_byte(fmt: &mut fmt::Formatter, b: u8) -> fmt::Result {
if b == b'\\' {
write!(fmt, "\\\\")
} else if 0x20 <= b && b <= 0x7e {
write!(fmt, "{}", char::from_u32(b as u32).expect("all u8 are valid char"))
} else if b == 0x0a {
write!(fmt, "\\n")
} else if b == 0x0d {
write!(fmt, "\\r")
} else {
write!(fmt, "\\x{:02x}", b)
}
}
impl fmt::Display for Constant {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
Constant::Str(ref s, _) => write!(fmt, "{:?}", s),
Constant::Byte(ref b) => {
write!(fmt, "b'")
.and_then(|_| format_byte(fmt, *b))
.and_then(|_| write!(fmt, "'"))
}
Constant::Binary(ref bs) => {
try!(write!(fmt, "b\""));
for b in bs.iter() {
try!(format_byte(fmt, *b));
}
write!(fmt, "\"")
}
Constant::Char(ref c) => write!(fmt, "'{}'", c),
Constant::Int(ref i, ref ity) => {
let (sign, suffix) = match *ity {
LitIntType::SignedIntLit(ref sity, ref sign) => {
(if let Sign::Minus = *sign {
"-"
} else {
""
},
sity.ty_to_string())
}
LitIntType::UnsignedIntLit(ref uity) => ("", uity.ty_to_string()),
LitIntType::UnsuffixedIntLit(ref sign) => {
(if let Sign::Minus = *sign {
"-"
} else {
""
},
"".into())
}
};
write!(fmt, "{}{}{}", sign, i, suffix)
}
Constant::Float(ref s, ref fw) => {
let suffix = match *fw {
FloatWidth::Fw32 => "f32",
FloatWidth::Fw64 => "f64",
FloatWidth::FwAny => "",
};
write!(fmt, "{}{}", s, suffix)
}
Constant::Bool(ref b) => write!(fmt, "{}", b),
Constant::Repeat(ref c, ref n) => write!(fmt, "[{}; {}]", c, n),
Constant::Vec(ref v) => {
write!(fmt,
"[{}]",
v.iter()
.map(|i| format!("{}", i))
.collect::<Vec<_>>()
.join(", "))
}
Constant::Tuple(ref t) => {
write!(fmt,
"({})",
t.iter()
.map(|i| format!("{}", i))
.collect::<Vec<_>>()
.join(", "))
}
}
}
}
fn lit_to_constant(lit: &Lit_) -> Constant {
match *lit {
Lit_::LitStr(ref is, style) => Constant::Str(is.to_string(), style),