diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-04-20 15:51:29 -0400 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-04-20 15:52:05 -0400 |
| commit | 3c2a44b60f472827884c868c527debbd7e61b054 (patch) | |
| tree | eb658152105447f882e87170d3fb41c7cdd31753 | |
| parent | 2b09267b762398a3c851ecfd55d5d01aee906352 (diff) | |
| download | rust-3c2a44b60f472827884c868c527debbd7e61b054.tar.gz rust-3c2a44b60f472827884c868c527debbd7e61b054.zip | |
Don't warn about unsafe functions which don't need to be unsafe
| -rw-r--r-- | src/librustc/middle/lint.rs | 13 | ||||
| -rw-r--r-- | src/test/compile-fail/unused-unsafe.rs | 7 |
2 files changed, 3 insertions, 17 deletions
diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 39144d46c83..9087afe5969 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -260,7 +260,7 @@ pub fn get_lint_dict() -> LintDict { (~"unused_unsafe", LintSpec { lint: unused_unsafe, - desc: "unnecessary use of an \"unsafe\" block or function", + desc: "unnecessary use of an \"unsafe\" block", default: warn }), @@ -958,17 +958,6 @@ fn check_fn(tcx: ty::ctxt, fk: &visit::fn_kind, decl: &ast::fn_decl, _body: &ast::blk, span: span, id: ast::node_id) { debug!("lint check_fn fk=%? id=%?", fk, id); - // Check for an 'unsafe fn' which doesn't need to be unsafe - match *fk { - visit::fk_item_fn(_, _, ast::unsafe_fn, _) => { - if !tcx.used_unsafe.contains(&id) { - tcx.sess.span_lint(unused_unsafe, id, id, span, - ~"unnecessary \"unsafe\" function"); - } - } - _ => () - } - // Check for deprecated modes match *fk { // don't complain about blocks, since they tend to get their modes diff --git a/src/test/compile-fail/unused-unsafe.rs b/src/test/compile-fail/unused-unsafe.rs index 368a0fbe9be..b29148cd3bc 100644 --- a/src/test/compile-fail/unused-unsafe.rs +++ b/src/test/compile-fail/unused-unsafe.rs @@ -18,9 +18,7 @@ fn callback<T>(_f: &fn() -> T) -> T { fail!() } fn bad1() { unsafe {} } //~ ERROR: unnecessary "unsafe" block fn bad2() { unsafe { bad1() } } //~ ERROR: unnecessary "unsafe" block -unsafe fn bad3() {} //~ ERROR: unnecessary "unsafe" function -unsafe fn bad4() { unsafe {} } //~ ERROR: unnecessary "unsafe" function - //~^ ERROR: unnecessary "unsafe" block +unsafe fn bad4() { unsafe {} } //~ ERROR: unnecessary "unsafe" block fn bad5() { unsafe { do callback {} } } //~ ERROR: unnecessary "unsafe" block unsafe fn good0() { libc::exit(1) } @@ -38,7 +36,6 @@ fn good2() { } } -#[allow(unused_unsafe)] unsafe fn allowed0() {} -#[allow(unused_unsafe)] fn allowed1() { unsafe {} } +#[allow(unused_unsafe)] fn allowed() { unsafe {} } fn main() { } |
