File tree Expand file tree Collapse file tree 6 files changed +58
-3
lines changed
rustc_ast_pretty/src/pprust
rustc_borrowck/src/diagnostics
rustc_mir_build/src/thir/pattern Expand file tree Collapse file tree 6 files changed +58
-3
lines changed Original file line number Diff line number Diff line change @@ -377,7 +377,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
377377
378378 fn print_string ( & mut self , st : & str , style : ast:: StrStyle ) {
379379 let st = match style {
380- ast:: StrStyle :: Cooked => ( format ! ( "\" {}\" " , st. escape_debug( ) ) ) ,
380+ ast:: StrStyle :: Cooked => format ! ( "\" {}\" " , st. escape_debug( ) ) ,
381381 ast:: StrStyle :: Raw ( n) => {
382382 format ! ( "r{delim}\" {string}\" {delim}" , delim = "#" . repeat( n as usize ) , string = st)
383383 }
Original file line number Diff line number Diff line change @@ -839,7 +839,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
839839 hir:: Node :: Expr ( hir:: Expr {
840840 kind : hir:: ExprKind :: Closure ( & hir:: Closure { fn_decl_span, .. } ) ,
841841 ..
842- } ) => ( tcx. sess . source_map ( ) . end_point ( fn_decl_span) ) ,
842+ } ) => tcx. sess . source_map ( ) . end_point ( fn_decl_span) ,
843843 _ => self . body . span ,
844844 } ;
845845
Original file line number Diff line number Diff line change @@ -396,6 +396,7 @@ enum UnusedDelimsCtx {
396396 LetScrutineeExpr ,
397397 ArrayLenExpr ,
398398 AnonConst ,
399+ MatchArmExpr ,
399400}
400401
401402impl From < UnusedDelimsCtx > for & ' static str {
@@ -414,6 +415,7 @@ impl From<UnusedDelimsCtx> for &'static str {
414415 UnusedDelimsCtx :: BlockRetValue => "block return value" ,
415416 UnusedDelimsCtx :: LetScrutineeExpr => "`let` scrutinee expression" ,
416417 UnusedDelimsCtx :: ArrayLenExpr | UnusedDelimsCtx :: AnonConst => "const expression" ,
418+ UnusedDelimsCtx :: MatchArmExpr => "match arm expression" ,
417419 }
418420 }
419421}
@@ -805,6 +807,18 @@ impl EarlyLintPass for UnusedParens {
805807 }
806808 return ;
807809 }
810+ ExprKind :: Match ( ref _expr, ref arm) => {
811+ for a in arm {
812+ self . check_unused_delims_expr (
813+ cx,
814+ & a. body ,
815+ UnusedDelimsCtx :: MatchArmExpr ,
816+ false ,
817+ None ,
818+ None ,
819+ ) ;
820+ }
821+ }
808822 _ => { }
809823 }
810824
Original file line number Diff line number Diff line change @@ -617,7 +617,7 @@ impl SplitVarLenSlice {
617617 // The only admissible fixed-length slice is one of the array size. Whether `max_slice`
618618 // is fixed-length or variable-length, it will be the only relevant slice to output
619619 // here.
620- Some ( _) => ( 0 ..0 ) , // empty range
620+ Some ( _) => 0 ..0 , // empty range
621621 // We cover all arities in the range `(self.arity..infinity)`. We split that range into
622622 // two: lengths smaller than `max_slice.arity()` are treated independently as
623623 // fixed-lengths slices, and lengths above are captured by `max_slice`.
Original file line number Diff line number Diff line change 1+ #[ deny( unused) ]
2+ pub fn broken ( x : Option < ( ) > ) -> i32 {
3+ match x {
4+ Some ( ( ) ) => ( 1 ) , //~ ERROR unnecessary parentheses around match arm expression
5+ None => ( 2 ) , //~ ERROR unnecessary parentheses around match arm expression
6+ }
7+ }
8+
9+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: unnecessary parentheses around match arm expression
2+ --> $DIR/issue-92751.rs:4:21
3+ |
4+ LL | Some(()) => (1),
5+ | ^ ^
6+ |
7+ note: the lint level is defined here
8+ --> $DIR/issue-92751.rs:1:8
9+ |
10+ LL | #[deny(unused)]
11+ | ^^^^^^
12+ = note: `#[deny(unused_parens)]` implied by `#[deny(unused)]`
13+ help: remove these parentheses
14+ |
15+ LL - Some(()) => (1),
16+ LL + Some(()) => 1,
17+ |
18+
19+ error: unnecessary parentheses around match arm expression
20+ --> $DIR/issue-92751.rs:5:17
21+ |
22+ LL | None => (2),
23+ | ^ ^
24+ |
25+ help: remove these parentheses
26+ |
27+ LL - None => (2),
28+ LL + None => 2,
29+ |
30+
31+ error: aborting due to 2 previous errors
32+
You can’t perform that action at this time.
0 commit comments