@@ -309,33 +309,32 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
309309fn check_for_bindings_named_the_same_as_variants ( cx : & MatchVisitor , pat : & Pat ) {
310310 pat. walk ( |p| {
311311 if let PatKind :: Binding ( _, _, ident, None ) = p. node {
312- let bm = * cx. tables
313- . pat_binding_modes ( )
314- . get ( p. hir_id )
315- . expect ( "missing binding mode" ) ;
316-
317- if bm != ty:: BindByValue ( hir:: MutImmutable ) {
318- // Nothing to check.
319- return true ;
320- }
321- let pat_ty = cx. tables . pat_ty ( p) ;
322- if let ty:: TyAdt ( edef, _) = pat_ty. sty {
323- if edef. is_enum ( ) && edef. variants . iter ( ) . any ( |variant| {
324- variant. name == ident. name && variant. ctor_kind == CtorKind :: Const
325- } ) {
326- let ty_path = cx. tcx . item_path_str ( edef. did ) ;
327- let mut err = struct_span_warn ! ( cx. tcx. sess, p. span, E0170 ,
328- "pattern binding `{}` is named the same as one \
329- of the variants of the type `{}`",
330- ident, ty_path) ;
331- err. span_suggestion_with_applicability (
332- p. span ,
333- "to match on the variant, qualify the path" ,
334- format ! ( "{}::{}" , ty_path, ident) ,
335- Applicability :: MachineApplicable
336- ) ;
337- err. emit ( ) ;
312+ if let Some ( & bm) = cx. tables . pat_binding_modes ( ) . get ( p. hir_id ) {
313+ if bm != ty:: BindByValue ( hir:: MutImmutable ) {
314+ // Nothing to check.
315+ return true ;
316+ }
317+ let pat_ty = cx. tables . pat_ty ( p) ;
318+ if let ty:: TyAdt ( edef, _) = pat_ty. sty {
319+ if edef. is_enum ( ) && edef. variants . iter ( ) . any ( |variant| {
320+ variant. name == ident. name && variant. ctor_kind == CtorKind :: Const
321+ } ) {
322+ let ty_path = cx. tcx . item_path_str ( edef. did ) ;
323+ let mut err = struct_span_warn ! ( cx. tcx. sess, p. span, E0170 ,
324+ "pattern binding `{}` is named the same as one \
325+ of the variants of the type `{}`",
326+ ident, ty_path) ;
327+ err. span_suggestion_with_applicability (
328+ p. span ,
329+ "to match on the variant, qualify the path" ,
330+ format ! ( "{}::{}" , ty_path, ident) ,
331+ Applicability :: MachineApplicable
332+ ) ;
333+ err. emit ( ) ;
334+ }
338335 }
336+ } else {
337+ cx. tcx . sess . delay_span_bug ( p. span , "missing binding mode" ) ;
339338 }
340339 }
341340 true
0 commit comments