Skip to content

Don't warn about unsafe functions which don't need to be unsafe #5978

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 1 commit into from
Apr 20, 2013
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
13 changes: 1 addition & 12 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),

Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/test/compile-fail/unused-unsafe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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() { }