This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -1095,17 +1095,21 @@ impl UnusedDelimLint for UnusedBraces {
10951095 // ```
10961096 // - the block has no attribute and was not created inside a macro
10971097 // - if the block is an `anon_const`, the inner expr must be a literal
1098- // (do not lint `struct A<const N: usize>; let _: A<{ 2 + 3 }>;`)
1099- //
1098+ // not created by a macro, i.e. do not lint on:
1099+ // ```
1100+ // struct A<const N: usize>;
1101+ // let _: A<{ 2 + 3 }>;
1102+ // let _: A<{produces_literal!()}>;
1103+ // ```
11001104 // FIXME(const_generics): handle paths when #67075 is fixed.
11011105 if let [ stmt] = inner. stmts . as_slice ( ) {
11021106 if let ast:: StmtKind :: Expr ( ref expr) = stmt. kind {
11031107 if !Self :: is_expr_delims_necessary ( expr, followed_by_block, false )
11041108 && ( ctx != UnusedDelimsCtx :: AnonConst
1105- || matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) ) )
1109+ || ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
1110+ && !expr. span . from_expansion ( ) ) )
11061111 && !cx. sess ( ) . source_map ( ) . is_multiline ( value. span )
11071112 && value. attrs . is_empty ( )
1108- && !expr. span . from_expansion ( )
11091113 && !value. span . from_expansion ( )
11101114 && !inner. span . from_expansion ( )
11111115 {
Original file line number Diff line number Diff line change @@ -50,4 +50,8 @@ fn main() {
5050 if { return } {
5151
5252 }
53+
54+ // regression test for https://github.com/rust-lang/rust/issues/106899
55+ return println!("!");
56+ //~^ WARN unnecessary braces
5357}
Original file line number Diff line number Diff line change @@ -50,4 +50,8 @@ fn main() {
5050 if { return } {
5151
5252 }
53+
54+ // regression test for https://github.com/rust-lang/rust/issues/106899
55+ return { println ! ( "!" ) } ;
56+ //~^ WARN unnecessary braces
5357}
Original file line number Diff line number Diff line change @@ -68,5 +68,17 @@ LL - consume({ 7 });
6868LL + consume(7);
6969 |
7070
71- warning: 5 warnings emitted
71+ warning: unnecessary braces around `return` value
72+ --> $DIR/unused_braces.rs:55:12
73+ |
74+ LL | return { println!("!") };
75+ | ^^ ^^
76+ |
77+ help: remove these braces
78+ |
79+ LL - return { println!("!") };
80+ LL + return println!("!");
81+ |
82+
83+ warning: 6 warnings emitted
7284
You can’t perform that action at this time.
0 commit comments