@@ -315,47 +315,43 @@ fn check_for_bindings_named_same_as_variants(
315
315
rf : RefutableFlag ,
316
316
) {
317
317
pat. walk_always ( |p| {
318
- if let hir:: PatKind :: Binding ( _, _, ident, None ) = p. kind {
319
- if let Some ( ty:: BindByValue ( hir:: Mutability :: Not ) ) =
318
+ if let hir:: PatKind :: Binding ( _, _, ident, None ) = p. kind
319
+ && let Some ( ty:: BindByValue ( hir:: Mutability :: Not ) ) =
320
320
cx. typeck_results . extract_binding_mode ( cx. tcx . sess , p. hir_id , p. span )
321
- {
322
- let pat_ty = cx. typeck_results . pat_ty ( p) . peel_refs ( ) ;
323
- if let ty:: Adt ( edef, _) = pat_ty. kind ( ) {
324
- if edef. is_enum ( )
325
- && edef. variants . iter ( ) . any ( |variant| {
326
- variant. ident ( cx. tcx ) == ident && variant. ctor_kind == CtorKind :: Const
327
- } )
328
- {
329
- let variant_count = edef. variants . len ( ) ;
330
- cx. tcx . struct_span_lint_hir (
331
- BINDINGS_WITH_VARIANT_NAME ,
332
- p. hir_id ,
321
+ && let pat_ty = cx. typeck_results . pat_ty ( p) . peel_refs ( )
322
+ && let ty:: Adt ( edef, _) = pat_ty. kind ( )
323
+ && edef. is_enum ( )
324
+ && edef. variants . iter ( ) . any ( |variant| {
325
+ variant. ident ( cx. tcx ) == ident && variant. ctor_kind == CtorKind :: Const
326
+ } )
327
+ {
328
+ let variant_count = edef. variants . len ( ) ;
329
+ cx. tcx . struct_span_lint_hir (
330
+ BINDINGS_WITH_VARIANT_NAME ,
331
+ p. hir_id ,
332
+ p. span ,
333
+ |lint| {
334
+ let ty_path = cx. tcx . def_path_str ( edef. did ) ;
335
+ let mut err = lint. build ( & format ! (
336
+ "pattern binding `{}` is named the same as one \
337
+ of the variants of the type `{}`",
338
+ ident, ty_path
339
+ ) ) ;
340
+ err. code ( error_code ! ( E0170 ) ) ;
341
+ // If this is an irrefutable pattern, and there's > 1 variant,
342
+ // then we can't actually match on this. Applying the below
343
+ // suggestion would produce code that breaks on `check_irrefutable`.
344
+ if rf == Refutable || variant_count == 1 {
345
+ err. span_suggestion (
333
346
p. span ,
334
- |lint| {
335
- let ty_path = cx. tcx . def_path_str ( edef. did ) ;
336
- let mut err = lint. build ( & format ! (
337
- "pattern binding `{}` is named the same as one \
338
- of the variants of the type `{}`",
339
- ident, ty_path
340
- ) ) ;
341
- err. code ( error_code ! ( E0170 ) ) ;
342
- // If this is an irrefutable pattern, and there's > 1 variant,
343
- // then we can't actually match on this. Applying the below
344
- // suggestion would produce code that breaks on `check_irrefutable`.
345
- if rf == Refutable || variant_count == 1 {
346
- err. span_suggestion (
347
- p. span ,
348
- "to match on the variant, qualify the path" ,
349
- format ! ( "{}::{}" , ty_path, ident) ,
350
- Applicability :: MachineApplicable ,
351
- ) ;
352
- }
353
- err. emit ( ) ;
354
- } ,
355
- )
347
+ "to match on the variant, qualify the path" ,
348
+ format ! ( "{}::{}" , ty_path, ident) ,
349
+ Applicability :: MachineApplicable ,
350
+ ) ;
356
351
}
357
- }
358
- }
352
+ err. emit ( ) ;
353
+ } ,
354
+ )
359
355
}
360
356
} ) ;
361
357
}
@@ -622,10 +618,8 @@ fn maybe_point_at_variant<'a, 'p: 'a, 'tcx: 'a>(
622
618
let mut covered = vec ! [ ] ;
623
619
for pattern in patterns {
624
620
if let Variant ( variant_index) = pattern. ctor ( ) {
625
- if let ty:: Adt ( this_def, _) = pattern. ty ( ) . kind ( ) {
626
- if this_def. did != def. did {
627
- continue ;
628
- }
621
+ if let ty:: Adt ( this_def, _) = pattern. ty ( ) . kind ( ) && this_def. did != def. did {
622
+ continue ;
629
623
}
630
624
let sp = def. variants [ * variant_index] . ident ( cx. tcx ) . span ;
631
625
if covered. contains ( & sp) {
0 commit comments