2013-04-09 00:31:10 -05:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Exercise the unused_unsafe attribute in some positive and negative cases
|
|
|
|
|
|
|
|
#[deny(unused_unsafe)];
|
|
|
|
|
2013-05-09 16:14:42 -05:00
|
|
|
mod foo {
|
2013-07-18 21:08:57 -05:00
|
|
|
extern {
|
2013-05-09 16:14:42 -05:00
|
|
|
pub fn bar();
|
|
|
|
}
|
2013-04-23 10:11:50 -05:00
|
|
|
}
|
2013-04-09 00:31:10 -05:00
|
|
|
|
2013-11-19 18:34:19 -06:00
|
|
|
fn callback<T>(_f: || -> T) -> T { fail!() }
|
2013-04-23 10:11:50 -05:00
|
|
|
unsafe fn unsf() {}
|
2013-04-09 00:31:10 -05:00
|
|
|
|
2013-04-23 01:06:47 -05:00
|
|
|
fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
|
|
|
|
fn bad2() { unsafe { bad1() } } //~ ERROR: unnecessary `unsafe` block
|
2013-04-23 10:11:50 -05:00
|
|
|
unsafe fn bad3() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
|
2013-11-21 19:23:21 -06:00
|
|
|
fn bad4() { unsafe { callback(||{}) } } //~ ERROR: unnecessary `unsafe` block
|
2013-04-23 10:11:50 -05:00
|
|
|
unsafe fn bad5() { unsafe { unsf() } } //~ ERROR: unnecessary `unsafe` block
|
|
|
|
fn bad6() {
|
2013-05-24 21:35:29 -05:00
|
|
|
unsafe { // don't put the warning here
|
|
|
|
unsafe { //~ ERROR: unnecessary `unsafe` block
|
2013-04-23 10:11:50 -05:00
|
|
|
unsf()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unsafe fn bad7() {
|
|
|
|
unsafe { //~ ERROR: unnecessary `unsafe` block
|
|
|
|
unsafe { //~ ERROR: unnecessary `unsafe` block
|
|
|
|
unsf()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-09 00:31:10 -05:00
|
|
|
|
2013-04-23 10:11:50 -05:00
|
|
|
unsafe fn good0() { unsf() }
|
|
|
|
fn good1() { unsafe { unsf() } }
|
2013-04-09 00:31:10 -05:00
|
|
|
fn good2() {
|
|
|
|
/* bug uncovered when implementing warning about unused unsafe blocks. Be
|
|
|
|
sure that when purity is inherited that the source of the unsafe-ness
|
|
|
|
is tracked correctly */
|
|
|
|
unsafe {
|
2013-10-21 15:08:31 -05:00
|
|
|
unsafe fn what() -> ~[~str] { fail!() }
|
2013-04-09 00:31:10 -05:00
|
|
|
|
2013-11-21 19:23:21 -06:00
|
|
|
callback(|| {
|
2013-04-09 00:31:10 -05:00
|
|
|
what();
|
2013-11-21 19:23:21 -06:00
|
|
|
});
|
2013-04-09 00:31:10 -05:00
|
|
|
}
|
|
|
|
}
|
2013-08-14 20:41:40 -05:00
|
|
|
|
2013-04-23 10:11:50 -05:00
|
|
|
unsafe fn good3() { foo::bar() }
|
|
|
|
fn good4() { unsafe { foo::bar() } }
|
2013-04-09 00:31:10 -05:00
|
|
|
|
2013-04-20 14:51:29 -05:00
|
|
|
#[allow(unused_unsafe)] fn allowed() { unsafe {} }
|
2013-04-09 00:31:10 -05:00
|
|
|
|
2013-04-23 10:11:50 -05:00
|
|
|
fn main() {}
|