File tree 2 files changed +29
-4
lines changed
2 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -380,11 +380,19 @@ trait UnusedDelimLint {
380
380
) ;
381
381
382
382
fn is_expr_delims_necessary ( inner : & ast:: Expr , followed_by_block : bool ) -> bool {
383
- followed_by_block
384
- && match inner. kind {
385
- ExprKind :: Ret ( _ ) | ExprKind :: Break ( .. ) => true ,
386
- _ => parser :: contains_exterior_struct_lit ( & inner ) ,
383
+ // Prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`
384
+ let lhs_needs_parens = match & inner. kind {
385
+ ExprKind :: Binary ( _ , lhs , _rhs ) => {
386
+ !rustc_ast :: util :: classify :: expr_requires_semi_to_be_stmt ( & * lhs )
387
387
}
388
+ _ => false ,
389
+ } ;
390
+ lhs_needs_parens
391
+ || ( followed_by_block
392
+ && match inner. kind {
393
+ ExprKind :: Ret ( _) | ExprKind :: Break ( ..) => true ,
394
+ _ => parser:: contains_exterior_struct_lit ( & inner) ,
395
+ } )
388
396
}
389
397
390
398
fn emit_unused_delims_expr (
Original file line number Diff line number Diff line change
1
+ // check-pass
2
+ // Make sure unused parens lint doesn't emit a false positive.
3
+ // See https://github.com/rust-lang/rust/issues/71290 for details.
4
+
5
+ fn x ( ) -> u8 {
6
+ ( { 0 } ) + 1
7
+ }
8
+
9
+ fn y ( ) -> u8 {
10
+ ( { 0 } + 1 )
11
+ }
12
+
13
+ pub fn foo ( a : bool , b : bool ) -> u8 {
14
+ ( if a { 1 } else { 0 } + if b { 1 } else { 0 } )
15
+ }
16
+
17
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments