]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/lint-unused-unsafe-thir.rs
Auto merge of #98051 - davidtwco:split-dwarf-stabilization, r=wesleywiser
[rust.git] / src / test / ui / span / lint-unused-unsafe-thir.rs
1 // FIXME: This file is tracking old lint behavior that's still unchanged in the
2 // unstable -Zthir-unsafeck implementation. See lint-unused-unsafe.rs for more details.
3 //
4 // Exercise the unused_unsafe attribute in some positive and negative cases
5
6 // compile-flags: -Zthir-unsafeck
7
8 #![allow(dead_code)]
9 #![deny(unused_unsafe)]
10
11
12 mod foo {
13     extern "C" {
14         pub fn bar();
15     }
16 }
17
18 fn callback<T, F>(_f: F) -> T where F: FnOnce() -> T { panic!() }
19 unsafe fn unsf() {}
20
21 fn bad1() { unsafe {} }                  //~ ERROR: unnecessary `unsafe` block
22 fn bad2() { unsafe { bad1() } }          //~ ERROR: unnecessary `unsafe` block
23 unsafe fn bad3() { unsafe {} }           //~ ERROR: unnecessary `unsafe` block
24 fn bad4() { unsafe { callback(||{}) } }  //~ ERROR: unnecessary `unsafe` block
25 unsafe fn bad5() { unsafe { unsf() } }
26 fn bad6() {
27     unsafe {                             // don't put the warning here
28         unsafe {                         //~ ERROR: unnecessary `unsafe` block
29             unsf()
30         }
31     }
32 }
33 unsafe fn bad7() {
34     unsafe {
35         unsafe {                         //~ ERROR: unnecessary `unsafe` block
36             unsf()
37         }
38     }
39 }
40
41 unsafe fn good0() { unsf() }
42 fn good1() { unsafe { unsf() } }
43 fn good2() {
44     /* bug uncovered when implementing warning about unused unsafe blocks. Be
45        sure that when purity is inherited that the source of the unsafe-ness
46        is tracked correctly */
47     unsafe {
48         unsafe fn what() -> Vec<String> { panic!() }
49
50         callback(|| {
51             what();
52         });
53     }
54 }
55
56 unsafe fn good3() { foo::bar() }
57 fn good4() { unsafe { foo::bar() } }
58
59 #[allow(unused_unsafe)] fn allowed() { unsafe {} }
60
61 fn main() {}