Skip to content

Improvements to the dead code lint #17410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from Sep 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 9 additions & 46 deletions src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,12 @@ pub enum ExponentFormat {
/// Use exponential notation with the exponent having a base of 10 and the
/// exponent sign being `e` or `E`. For example, 1000 would be printed
/// 1e3.
ExpDec,
/// Use exponential notation with the exponent having a base of 2 and the
/// exponent sign being `p` or `P`. For example, 8 would be printed 1p3.
ExpBin,
ExpDec
}

/// The number of digits used for emitting the fractional part of a number, if
/// any.
pub enum SignificantDigits {
/// All calculable digits will be printed.
///
/// Note that bignums or fractions may cause a surprisingly large number
/// of digits to be printed.
DigAll,

/// At most the given number of digits will be printed, truncating any
/// trailing zeroes.
DigMax(uint),
Expand All @@ -53,17 +44,11 @@ pub enum SignificantDigits {

/// How to emit the sign of a number.
pub enum SignFormat {
/// No sign will be printed. The exponent sign will also be emitted.
SignNone,
/// `-` will be printed for negative values, but no sign will be emitted
/// for positive numbers.
SignNeg,
/// `+` will be printed for positive values, and `-` will be printed for
/// negative values.
SignAll,
SignNeg
}

static DIGIT_P_RADIX: uint = ('p' as uint) - ('a' as uint) + 11u;
static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;

/**
Expand Down Expand Up @@ -111,9 +96,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e'
=> fail!("float_to_str_bytes_common: radix {} incompatible with \
use of 'e' as decimal exponent", radix),
ExpBin if radix >= DIGIT_P_RADIX // binary exponent 'p'
=> fail!("float_to_str_bytes_common: radix {} incompatible with \
use of 'p' as binary exponent", radix),
_ => ()
}

Expand All @@ -123,16 +105,10 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
match num.classify() {
FPNaN => return f("NaN".as_bytes()),
FPInfinite if num > _0 => {
return match sign {
SignAll => return f("+inf".as_bytes()),
_ => return f("inf".as_bytes()),
};
return f("inf".as_bytes());
}
FPInfinite if num < _0 => {
return match sign {
SignNone => return f("inf".as_bytes()),
_ => return f("-inf".as_bytes()),
};
return f("-inf".as_bytes());
}
_ => {}
}
Expand All @@ -147,11 +123,10 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(

let (num, exp) = match exp_format {
ExpNone => (num, 0i32),
ExpDec | ExpBin if num == _0 => (num, 0i32),
ExpDec | ExpBin => {
ExpDec if num == _0 => (num, 0i32),
ExpDec => {
let (exp, exp_base) = match exp_format {
ExpDec => (num.abs().log10().floor(), cast::<f64, T>(10.0f64).unwrap()),
ExpBin => (num.abs().log2().floor(), cast::<f64, T>(2.0f64).unwrap()),
ExpNone => fail!("unreachable"),
};

Expand Down Expand Up @@ -185,21 +160,16 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(

// If limited digits, calculate one digit more for rounding.
let (limit_digits, digit_count, exact) = match digits {
DigAll => (false, 0u, false),
DigMax(count) => (true, count+1, false),
DigExact(count) => (true, count+1, true)
DigMax(count) => (true, count + 1, false),
DigExact(count) => (true, count + 1, true)
};

// Decide what sign to put in front
match sign {
SignNeg | SignAll if neg => {
SignNeg if neg => {
buf[end] = b'-';
end += 1;
}
SignAll => {
buf[end] = b'+';
end += 1;
}
_ => ()
}

Expand Down Expand Up @@ -329,8 +299,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
buf[end] = match exp_format {
ExpDec if exp_upper => 'E',
ExpDec if !exp_upper => 'e',
ExpBin if exp_upper => 'P',
ExpBin if !exp_upper => 'p',
_ => fail!("unreachable"),
} as u8;
end += 1;
Expand All @@ -356,11 +324,6 @@ pub fn float_to_str_bytes_common<T: Primitive + Float, U>(
fmt::write(&mut filler, args)
}, "{:-}", exp);
}
SignNone | SignAll => {
let _ = format_args!(|args| {
fmt::write(&mut filler, args)
}, "{}", exp);
}
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,6 @@ pub fn get_cc_prog(sess: &Session) -> String {
}.to_string()
}

pub fn get_ar_prog(sess: &Session) -> String {
match sess.opts.cg.ar {
Some(ref ar) => (*ar).clone(),
None => "ar".to_string()
}
}

pub fn remove(sess: &Session, path: &Path) {
match fs::unlink(path) {
Ok(..) => {}
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ register_diagnostics!(
E0102,
E0103,
E0104,
E0105,
E0106,
E0107,
E0108,
Expand Down Expand Up @@ -152,7 +151,6 @@ register_diagnostics!(
E0144,
E0145,
E0146,
E0147,
E0148,
E0151,
E0152,
Expand Down
26 changes: 6 additions & 20 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,11 +1269,6 @@ impl LintPass for UnusedMut {
}
}

enum Allocation {
VectorAllocation,
BoxAllocation
}

declare_lint!(UNNECESSARY_ALLOCATION, Warn,
"detects unnecessary allocations that can be eliminated")

Expand All @@ -1285,30 +1280,21 @@ impl LintPass for UnnecessaryAllocation {
}

fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
// Warn if boxing expressions are immediately borrowed.
let allocation = match e.node {
ast::ExprUnary(ast::UnUniq, _) |
ast::ExprUnary(ast::UnBox, _) => BoxAllocation,

match e.node {
ast::ExprUnary(ast::UnUniq, _) | ast::ExprUnary(ast::UnBox, _) => (),
_ => return
};
}

match cx.tcx.adjustments.borrow().find(&e.id) {
Some(adjustment) => {
match *adjustment {
ty::AdjustDerefRef(ty::AutoDerefRef { ref autoref, .. }) => {
match (allocation, autoref) {
(VectorAllocation, &Some(ty::AutoPtr(_, _, None))) => {
cx.span_lint(UNNECESSARY_ALLOCATION, e.span,
"unnecessary allocation, the sigil can be removed");
}
(BoxAllocation,
&Some(ty::AutoPtr(_, ast::MutImmutable, None))) => {
match autoref {
&Some(ty::AutoPtr(_, ast::MutImmutable, None)) => {
cx.span_lint(UNNECESSARY_ALLOCATION, e.span,
"unnecessary allocation, use & instead");
}
(BoxAllocation,
&Some(ty::AutoPtr(_, ast::MutMutable, None))) => {
&Some(ty::AutoPtr(_, ast::MutMutable, None)) => {
cx.span_lint(UNNECESSARY_ALLOCATION, e.span,
"unnecessary allocation, use &mut instead");
}
Expand Down
73 changes: 0 additions & 73 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,30 +662,6 @@ impl tr for MethodOrigin {
}
}

// ______________________________________________________________________
// Encoding and decoding vtable_res

pub fn encode_vtable_res(ecx: &e::EncodeContext,
rbml_w: &mut Encoder,
dr: &typeck::vtable_res) {
// can't autogenerate this code because automatic code of
// ty::t doesn't work, and there is no way (atm) to have
// hand-written encoding routines combine with auto-generated
// ones. perhaps we should fix this.
encode_vec_per_param_space(
rbml_w, dr,
|rbml_w, param_tables| encode_vtable_param_res(ecx, rbml_w,
param_tables))
}

pub fn encode_vtable_param_res(ecx: &e::EncodeContext,
rbml_w: &mut Encoder,
param_tables: &typeck::vtable_param_res) {
rbml_w.emit_from_vec(param_tables.as_slice(), |rbml_w, vtable_origin| {
Ok(encode_vtable_origin(ecx, rbml_w, vtable_origin))
}).unwrap()
}

pub fn encode_unboxed_closure_kind(ebml_w: &mut Encoder,
kind: ty::UnboxedClosureKind) {
use serialize::Encoder;
Expand Down Expand Up @@ -714,55 +690,6 @@ pub fn encode_unboxed_closure_kind(ebml_w: &mut Encoder,
}).unwrap()
}

pub fn encode_vtable_origin(ecx: &e::EncodeContext,
rbml_w: &mut Encoder,
vtable_origin: &typeck::vtable_origin) {
use serialize::Encoder;

rbml_w.emit_enum("vtable_origin", |rbml_w| {
match *vtable_origin {
typeck::vtable_static(def_id, ref substs, ref vtable_res) => {
rbml_w.emit_enum_variant("vtable_static", 0u, 3u, |rbml_w| {
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
Ok(rbml_w.emit_def_id(def_id))
});
rbml_w.emit_enum_variant_arg(1u, |rbml_w| {
Ok(rbml_w.emit_substs(ecx, substs))
});
rbml_w.emit_enum_variant_arg(2u, |rbml_w| {
Ok(encode_vtable_res(ecx, rbml_w, vtable_res))
})
})
}
typeck::vtable_param(pn, bn) => {
rbml_w.emit_enum_variant("vtable_param", 1u, 3u, |rbml_w| {
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
pn.encode(rbml_w)
});
rbml_w.emit_enum_variant_arg(1u, |rbml_w| {
rbml_w.emit_uint(bn)
})
})
}
typeck::vtable_unboxed_closure(def_id) => {
rbml_w.emit_enum_variant("vtable_unboxed_closure",
2u,
1u,
|rbml_w| {
rbml_w.emit_enum_variant_arg(0u, |rbml_w| {
Ok(rbml_w.emit_def_id(def_id))
})
})
}
typeck::vtable_error => {
rbml_w.emit_enum_variant("vtable_error", 3u, 3u, |_rbml_w| {
Ok(())
})
}
}
}).unwrap()
}

pub trait vtable_decoder_helpers {
fn read_vec_per_param_space<T>(&mut self,
f: |&mut Self| -> T)
Expand Down
Loading