File tree 6 files changed +134
-0
lines changed
6 files changed +134
-0
lines changed Original file line number Diff line number Diff line change
1
+ // check-pass
2
+ #![ warn( unused_braces) ]
3
+
4
+ #![ feature( const_generics) ]
5
+ //~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
6
+
7
+ struct A < const N : usize > ;
8
+
9
+ fn main ( ) {
10
+ let _: A < 7 > ; // ok
11
+ let _: A < { 7 } > ; //~ WARN unnecessary braces
12
+ let _: A < { 3 + 5 } > ; // ok
13
+ }
Original file line number Diff line number Diff line change
1
+ warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2
+ --> $DIR/unused_braces.rs:4:12
3
+ |
4
+ LL | #![feature(const_generics)]
5
+ | ^^^^^^^^^^^^^^
6
+ |
7
+ = note: `#[warn(incomplete_features)]` on by default
8
+
9
+ warning: unnecessary braces around const expression
10
+ --> $DIR/unused_braces.rs:11:14
11
+ |
12
+ LL | let _: A<{ 7 }>;
13
+ | ^^^^^ help: remove these braces
14
+ |
15
+ note: the lint level is defined here
16
+ --> $DIR/unused_braces.rs:2:9
17
+ |
18
+ LL | #![warn(unused_braces)]
19
+ | ^^^^^^^^^^^^^
20
+
Original file line number Diff line number Diff line change
1
+ // check-pass
2
+ #![ warn( unused_braces, unused_parens) ]
3
+
4
+ fn main ( ) {
5
+ let _ = ( 7 ) ;
6
+ //~^WARN unnecessary parentheses
7
+
8
+ let _ = { 7 } ;
9
+ //~^ WARN unnecessary braces
10
+
11
+ if let 7 = { 7 } {
12
+ //~^ WARN unnecessary braces
13
+ }
14
+
15
+ let _: [ u8 ; { 3 } ] ;
16
+ //~^ WARN unnecessary braces
17
+
18
+ // do not emit error for multiline blocks.
19
+ let _ = {
20
+ 7
21
+ } ;
22
+
23
+ // do not emit error for unsafe blocks.
24
+ let _ = unsafe { 7 } ;
25
+
26
+ // do not emit error, as the `{` would then
27
+ // be parsed as part of the `return`.
28
+ if { return } {
29
+
30
+ }
31
+ }
Original file line number Diff line number Diff line change
1
+ warning: unnecessary parentheses around assigned value
2
+ --> $DIR/unused_braces.rs:5:13
3
+ |
4
+ LL | let _ = (7);
5
+ | ^^^ help: remove these parentheses
6
+ |
7
+ note: the lint level is defined here
8
+ --> $DIR/unused_braces.rs:2:24
9
+ |
10
+ LL | #![warn(unused_braces, unused_parens)]
11
+ | ^^^^^^^^^^^^^
12
+
13
+ warning: unnecessary braces around assigned value
14
+ --> $DIR/unused_braces.rs:8:13
15
+ |
16
+ LL | let _ = { 7 };
17
+ | ^^^^^ help: remove these braces
18
+ |
19
+ note: the lint level is defined here
20
+ --> $DIR/unused_braces.rs:2:9
21
+ |
22
+ LL | #![warn(unused_braces, unused_parens)]
23
+ | ^^^^^^^^^^^^^
24
+
25
+ warning: unnecessary braces around `let` head expression
26
+ --> $DIR/unused_braces.rs:11:16
27
+ |
28
+ LL | if let 7 = { 7 } {
29
+ | ^^^^^ help: remove these braces
30
+
31
+ warning: unnecessary braces around const expression
32
+ --> $DIR/unused_braces.rs:15:17
33
+ |
34
+ LL | let _: [u8; { 3 }];
35
+ | ^^^^^ help: remove these braces
36
+
Original file line number Diff line number Diff line change
1
+ // check-pass
2
+ #![ warn( unused_braces) ]
3
+
4
+ // changing `&{ expr }` to `&expr` changes the semantic of the program
5
+ // so we should not warn this case
6
+
7
+ #[ repr( packed) ]
8
+ struct A {
9
+ a : u8 ,
10
+ b : u32 ,
11
+ }
12
+
13
+ fn main ( ) {
14
+ let a = A {
15
+ a : 42 ,
16
+ b : 1729 ,
17
+ } ;
18
+
19
+ let _ = & { a. b } ;
20
+ let _ = { a. b } ;
21
+ //~^ WARN unnecessary braces
22
+ }
Original file line number Diff line number Diff line change
1
+ warning: unnecessary braces around assigned value
2
+ --> $DIR/unused_parens_borrow.rs:20:13
3
+ |
4
+ LL | let _ = { a.b };
5
+ | ^^^^^^^ help: remove these braces
6
+ |
7
+ note: the lint level is defined here
8
+ --> $DIR/unused_parens_borrow.rs:2:9
9
+ |
10
+ LL | #![warn(unused_braces)]
11
+ | ^^^^^^^^^^^^^
12
+
You can’t perform that action at this time.
0 commit comments