@@ -14,7 +14,7 @@ use rustc_infer::infer;
14
14
use rustc_infer:: infer:: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
15
15
use rustc_middle:: mir:: interpret:: ErrorHandled ;
16
16
use rustc_middle:: ty:: { self , Adt , BindingMode , Ty , TypeVisitableExt } ;
17
- use rustc_session:: lint:: builtin :: NON_EXHAUSTIVE_OMITTED_PATTERNS ;
17
+ use rustc_session:: lint;
18
18
use rustc_span:: edit_distance:: find_best_match_for_name;
19
19
use rustc_span:: hygiene:: DesugaringKind ;
20
20
use rustc_span:: source_map:: Spanned ;
@@ -600,8 +600,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
600
600
601
601
// Determine the binding mode...
602
602
let bm = match ba {
603
- hir:: BindingAnnotation :: NONE => def_bm,
604
- _ => BindingMode :: convert ( ba) ,
603
+ hir:: BindingAnnotation ( ast:: ByRef :: No , hir:: Mutability :: Not ) => def_bm,
604
+ hir:: BindingAnnotation ( ast:: ByRef :: No , mutbl @ hir:: Mutability :: Mut ) => {
605
+ if let BindingMode :: BindByReference ( _) = def_bm {
606
+ // `mut x` resets the binding mode.
607
+ self . tcx . emit_spanned_lint (
608
+ lint:: builtin:: DEREFERENCING_MUT_BINDING ,
609
+ pat. hir_id ,
610
+ pat. span ,
611
+ errors:: DereferencingMutBinding { span : pat. span } ,
612
+ ) ;
613
+ }
614
+ BindingMode :: BindByValue ( mutbl)
615
+ }
616
+ hir:: BindingAnnotation ( ast:: ByRef :: Yes , mutbl) => BindingMode :: BindByReference ( mutbl) ,
605
617
} ;
606
618
// ...and store it in a side table:
607
619
self . inh . typeck_results . borrow_mut ( ) . pat_binding_modes_mut ( ) . insert ( pat. hir_id , bm) ;
@@ -1838,7 +1850,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1838
1850
& unmentioned_fields. iter ( ) . map ( |( _, i) | i) . collect :: < Vec < _ > > ( ) ,
1839
1851
) ;
1840
1852
1841
- self . tcx . struct_span_lint_hir ( NON_EXHAUSTIVE_OMITTED_PATTERNS , pat. hir_id , pat. span , "some fields are not explicitly listed" , |lint| {
1853
+ self . tcx . struct_span_lint_hir ( lint :: builtin :: NON_EXHAUSTIVE_OMITTED_PATTERNS , pat. hir_id , pat. span , "some fields are not explicitly listed" , |lint| {
1842
1854
lint. span_label ( pat. span , format ! ( "field{} {} not listed" , rustc_errors:: pluralize!( unmentioned_fields. len( ) ) , joined_patterns) ) ;
1843
1855
lint. help (
1844
1856
"ensure that all fields are mentioned explicitly by adding the suggested fields" ,
0 commit comments