]> git.lizzy.rs Git - rust.git/blob - tests/ui/lint/unused_braces.rs
Auto merge of #106884 - clubby789:fieldless-enum-debug, r=michaelwoerister
[rust.git] / tests / ui / lint / unused_braces.rs
1 // check-pass
2 // run-rustfix
3
4 #![warn(unused_braces, unused_parens)]
5 #![allow(unreachable_code, unused_unsafe)] // for rustfix
6
7 fn consume<T>(_: T) {}
8
9 fn main() {
10     let _ = (7);
11     //~^WARN unnecessary parentheses
12
13     // Do not emit a lint in these cases,
14     // as we have to be careful with
15     // `ref` patterns.
16     {
17         let _ = { 7 };
18
19         if let 7 = { 7 } { }
20
21         match { 7 } {
22             _ => (),
23         }
24     }
25
26     if { true } {
27         //~^ WARN unnecessary braces
28     }
29
30     while { false } {
31         //~^ WARN unnecessary braces
32     }
33
34     let _: [u8; { 3 }];
35     //~^ WARN unnecessary braces
36
37     consume({ 7 });
38     //~^ WARN unnecessary braces
39
40     // Do not emit lint for multiline blocks.
41     let _ = {
42         7
43     };
44
45     // Do not emit lint for unsafe blocks.
46     let _ = unsafe { 7 };
47
48     // Do not emit lint, as the `{` would then
49     // be parsed as part of the `return`.
50     if { return } {
51
52     }
53
54     // regression test for https://github.com/rust-lang/rust/issues/106899
55     return { println!("!") };
56     //~^ WARN unnecessary braces
57 }