unnecessary_allocation,
missing_doc,
+ unreachable_code,
}
pub fn level_to_str(lv: level) -> &'static str {
desc: "detects missing documentation for public members",
default: allow
}),
+
+ ("unreachable_code",
+ LintSpec {
+ lint: unreachable_code,
+ desc: "detects unreachable code",
+ default: warn
+ }),
];
/*
use middle::const_eval;
use middle::pat_util::pat_id_map;
use middle::pat_util;
+use middle::lint::unreachable_code;
use middle::ty::{FnSig, VariantInfo_};
use middle::ty::{ty_param_bounds_and_ty, ty_param_substs_and_ty};
use middle::ty::{substs, param_ty};
let mut any_err = false;
for blk.node.stmts.each |s| {
check_stmt(fcx, *s);
- let s_ty = fcx.node_ty(ast_util::stmt_id(*s));
+ let s_id = ast_util::stmt_id(*s);
+ let s_ty = fcx.node_ty(s_id);
if last_was_bot && !warned && match s.node {
ast::stmt_decl(@codemap::spanned { node: ast::decl_local(_),
_}, _) |
}
_ => false
} {
- fcx.ccx.tcx.sess.span_warn(s.span, "unreachable statement");
+ fcx.ccx.tcx.sess.add_lint(unreachable_code, s_id, s.span,
+ ~"unreachable statement");
warned = true;
}
if ty::type_is_bot(s_ty) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-
-fn f(caller: &str) {
- debug!(caller);
- let x: uint = 0u32; // induce type error //~ ERROR mismatched types
-}
+#[deny(unreachable_code)];
fn main() {
- return f("main");
- debug!("Paul is dead"); //~ WARNING unreachable
+ return;
+ debug!("Paul is dead"); //~ ERROR: unreachable
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[deny(unreachable_code)];
+#[allow(unused_variable)];
+
fn fail_len(v: ~[int]) -> uint {
- let mut i = fail!();
+ let mut i = 3;
+ fail!();
for v.each |x| { i += 1u; }
- //~^ WARNING unreachable statement
- //~^^ ERROR the type of this value must be known
+ //~^ ERROR: unreachable statement
return i;
}
fn main() {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[deny(unreachable_code)];
+
fn g() -> ! { fail!(); }
fn f() -> ! {
- return 42i; //~ ERROR expected `!` but found `int`
- g(); //~ WARNING unreachable statement
+ return g();
+ g(); //~ ERROR: unreachable statement
}
fn main() { }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#[deny(unreachable_code)];
+
fn f() -> ! {
- return 42i; //~ ERROR expected `!` but found `int`
- fail!(); //~ WARNING unreachable statement
+ return fail!();
+ fail!(); //~ ERROR: unreachable statement
}
fn main() { }
while 1 != 2 {
break;
- x = 0; //~ WARNING unreachable statement
+ x = 0;
}
debug!(x); //~ ERROR use of possibly uninitialized variable: `x`
loop {
break;
- x = 0; //~ WARNING unreachable statement
+ x = 0;
}
debug!(x); //~ ERROR use of possibly uninitialized variable: `x`
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-// error-pattern:unreachable statement
+#[deny(unreachable_code)];
+#[allow(unused_variable)];
+
fn main() {
loop{}
- // red herring to make sure compilation fails
- error!(42 == 'c');
+
+ let a = 3; //~ ERROR: unreachable statement
}