File tree 4 files changed +29
-5
lines changed
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 {
1095
1095
// ```
1096
1096
// - the block has no attribute and was not created inside a macro
1097
1097
// - 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
+ // ```
1100
1104
// FIXME(const_generics): handle paths when #67075 is fixed.
1101
1105
if let [ stmt] = inner. stmts . as_slice ( ) {
1102
1106
if let ast:: StmtKind :: Expr ( ref expr) = stmt. kind {
1103
1107
if !Self :: is_expr_delims_necessary ( expr, followed_by_block, false )
1104
1108
&& ( ctx != UnusedDelimsCtx :: AnonConst
1105
- || matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) ) )
1109
+ || ( matches ! ( expr. kind, ast:: ExprKind :: Lit ( _) )
1110
+ && !expr. span . from_expansion ( ) ) )
1106
1111
&& !cx. sess ( ) . source_map ( ) . is_multiline ( value. span )
1107
1112
&& value. attrs . is_empty ( )
1108
- && !expr. span . from_expansion ( )
1109
1113
&& !value. span . from_expansion ( )
1110
1114
&& !inner. span . from_expansion ( )
1111
1115
{
Original file line number Diff line number Diff line change @@ -50,4 +50,8 @@ fn main() {
50
50
if { return } {
51
51
52
52
}
53
+
54
+ // regression test for https://github.com/rust-lang/rust/issues/106899
55
+ return println!("!");
56
+ //~^ WARN unnecessary braces
53
57
}
Original file line number Diff line number Diff line change @@ -50,4 +50,8 @@ fn main() {
50
50
if { return } {
51
51
52
52
}
53
+
54
+ // regression test for https://github.com/rust-lang/rust/issues/106899
55
+ return { println ! ( "!" ) } ;
56
+ //~^ WARN unnecessary braces
53
57
}
Original file line number Diff line number Diff line change @@ -68,5 +68,17 @@ LL - consume({ 7 });
68
68
LL + consume(7);
69
69
|
70
70
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
72
84
You can’t perform that action at this time.
0 commit comments