]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/span/lint-unused-unsafe.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Exercise the unused_unsafe attribute in some positive and negative cases
14 #![deny(unused_unsafe)]
23 fn callback
<T
, F
>(_f
: F
) -> T
where F
: FnOnce() -> T { panic!() }
26 fn bad1() { unsafe {}
} //~ ERROR: unnecessary `unsafe` block
27 fn bad2() { unsafe { bad1() }
} //~ ERROR: unnecessary `unsafe` block
28 unsafe fn bad3() { unsafe {}
} //~ ERROR: unnecessary `unsafe` block
29 fn bad4() { unsafe { callback(||{}
) } } //~ ERROR: unnecessary `unsafe` block
30 unsafe fn bad5() { unsafe { unsf() }
} //~ ERROR: unnecessary `unsafe` block
32 unsafe { // don't put the warning here
33 unsafe { //~ ERROR: unnecessary `unsafe` block
39 unsafe { //~ ERROR: unnecessary `unsafe` block
40 unsafe { //~ ERROR: unnecessary `unsafe` block
46 unsafe fn good0() { unsf() }
47 fn good1() { unsafe { unsf() }
}
49 /* bug uncovered when implementing warning about unused unsafe blocks. Be
50 sure that when purity is inherited that the source of the unsafe-ness
51 is tracked correctly */
53 unsafe fn what() -> Vec
<String
> { panic!() }
61 unsafe fn good3() { foo::bar() }
62 fn good4() { unsafe { foo::bar() }
}
64 #[allow(unused_unsafe)] fn allowed() { unsafe {} }