@@ -141,7 +141,8 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
141141 let pattern: & _ = cx. pattern_arena . alloc ( expand_pattern ( pattern) ) ;
142142 if !patcx. errors . is_empty ( ) {
143143 * have_errors = true ;
144- patcx. report_inlining_errors ( pat. span ) ;
144+ let pat_span = self . tcx . hir ( ) . span ( pat. hir_id ) ;
145+ patcx. report_inlining_errors ( pat_span) ;
145146 }
146147 ( pattern, pattern_ty)
147148 }
@@ -226,9 +227,10 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
226227 }
227228
228229 let joined_patterns = joined_uncovered_patterns ( & witnesses) ;
230+ let pat_span = self . tcx . hir ( ) . span ( pat. hir_id ) ;
229231 let mut err = struct_span_err ! (
230232 self . tcx. sess,
231- pat . span ,
233+ pat_span ,
232234 E0005 ,
233235 "refutable pattern in {}: {} not covered" ,
234236 origin,
@@ -242,7 +244,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
242244 false
243245 }
244246 _ => {
245- err. span_label ( pat . span , pattern_not_covered_label ( & witnesses, & joined_patterns) ) ;
247+ err. span_label ( pat_span , pattern_not_covered_label ( & witnesses, & joined_patterns) ) ;
246248 true
247249 }
248250 } ;
@@ -281,13 +283,14 @@ fn const_not_var(
281283 path : & hir:: Path < ' _ > ,
282284) {
283285 let descr = path. res . descr ( ) ;
286+ let pat_span = tcx. hir ( ) . span ( pat. hir_id ) ;
284287 err. span_label (
285- pat . span ,
288+ pat_span ,
286289 format ! ( "interpreted as {} {} pattern, not a new variable" , path. res. article( ) , descr, ) ,
287290 ) ;
288291
289292 err. span_suggestion (
290- pat . span ,
293+ pat_span ,
291294 "introduce a variable instead" ,
292295 format ! ( "{}_var" , path. segments[ 0 ] . ident) . to_lowercase ( ) ,
293296 // Cannot use `MachineApplicable` as it's not really *always* correct
@@ -304,8 +307,9 @@ fn const_not_var(
304307fn check_for_bindings_named_same_as_variants ( cx : & MatchVisitor < ' _ , ' _ > , pat : & Pat < ' _ > ) {
305308 pat. walk_always ( |p| {
306309 if let hir:: PatKind :: Binding ( _, _, ident, None ) = p. kind {
310+ let span = cx. tcx . hir ( ) . span ( p. hir_id ) ;
307311 if let Some ( ty:: BindByValue ( hir:: Mutability :: Not ) ) =
308- cx. typeck_results . extract_binding_mode ( cx. tcx . sess , p. hir_id , p . span )
312+ cx. typeck_results . extract_binding_mode ( cx. tcx . sess , p. hir_id , span)
309313 {
310314 let pat_ty = cx. typeck_results . pat_ty ( p) . peel_refs ( ) ;
311315 if let ty:: Adt ( edef, _) = pat_ty. kind ( ) {
@@ -317,7 +321,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa
317321 cx. tcx . struct_span_lint_hir (
318322 BINDINGS_WITH_VARIANT_NAME ,
319323 p. hir_id ,
320- p . span ,
324+ span,
321325 |lint| {
322326 let ty_path = cx. tcx . def_path_str ( edef. did ) ;
323327 lint. build ( & format ! (
@@ -327,7 +331,7 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa
327331 ) )
328332 . code ( error_code ! ( E0170 ) )
329333 . span_suggestion (
330- p . span ,
334+ span,
331335 "to match on the variant, qualify the path" ,
332336 format ! ( "{}::{}" , ty_path, ident) ,
333337 Applicability :: MachineApplicable ,
@@ -616,17 +620,19 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
616620 hir:: PatKind :: Binding ( .., name, Some ( sub) ) => ( * name, sub) ,
617621 _ => return ,
618622 } ;
619- let binding_span = pat. span . with_hi ( name. span . hi ( ) ) ;
623+ let pat_span = cx. tcx . hir ( ) . span ( pat. hir_id ) ;
624+ let binding_span = pat_span. with_hi ( name. span . hi ( ) ) ;
620625
621626 let typeck_results = cx. typeck_results ;
622627 let sess = cx. tcx . sess ;
623628
624629 // Get the binding move, extract the mutability if by-ref.
625- let mut_outer = match typeck_results. extract_binding_mode ( sess, pat. hir_id , pat . span ) {
626- Some ( ty:: BindByValue ( _) ) if is_binding_by_move ( cx, pat. hir_id , pat . span ) => {
630+ let mut_outer = match typeck_results. extract_binding_mode ( sess, pat. hir_id , pat_span ) {
631+ Some ( ty:: BindByValue ( _) ) if is_binding_by_move ( cx, pat. hir_id , pat_span ) => {
627632 // We have `x @ pat` where `x` is by-move. Reject all borrows in `pat`.
628633 let mut conflicts_ref = Vec :: new ( ) ;
629- sub. each_binding ( |_, hir_id, span, _| {
634+ sub. each_binding ( |_, hir_id, _| {
635+ let span = cx. tcx . hir ( ) . span ( hir_id) ;
630636 match typeck_results. extract_binding_mode ( sess, hir_id, span) {
631637 Some ( ty:: BindByValue ( _) ) | None => { }
632638 Some ( ty:: BindByReference ( _) ) => conflicts_ref. push ( span) ,
@@ -638,7 +644,7 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
638644 name,
639645 typeck_results. node_type( pat. hir_id) ,
640646 ) ;
641- sess. struct_span_err ( pat . span , "borrow of moved value" )
647+ sess. struct_span_err ( pat_span , "borrow of moved value" )
642648 . span_label ( binding_span, format ! ( "value moved into `{}` here" , name) )
643649 . span_label ( binding_span, occurs_because)
644650 . span_labels ( conflicts_ref, "value borrowed here after move" )
@@ -655,7 +661,8 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
655661 let mut conflicts_move = Vec :: new ( ) ;
656662 let mut conflicts_mut_mut = Vec :: new ( ) ;
657663 let mut conflicts_mut_ref = Vec :: new ( ) ;
658- sub. each_binding ( |_, hir_id, span, name| {
664+ sub. each_binding ( |_, hir_id, name| {
665+ let span = cx. tcx . hir ( ) . span ( hir_id) ;
659666 match typeck_results. extract_binding_mode ( sess, hir_id, span) {
660667 Some ( ty:: BindByReference ( mut_inner) ) => match ( mut_outer, mut_inner) {
661668 ( Mutability :: Not , Mutability :: Not ) => { } // Both sides are `ref`.
@@ -673,7 +680,7 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
673680 if !conflicts_mut_mut. is_empty ( ) {
674681 // Report mutability conflicts for e.g. `ref mut x @ Some(ref mut y)`.
675682 let mut err = sess
676- . struct_span_err ( pat . span , "cannot borrow value as mutable more than once at a time" ) ;
683+ . struct_span_err ( pat_span , "cannot borrow value as mutable more than once at a time" ) ;
677684 err. span_label ( binding_span, format ! ( "first mutable borrow, by `{}`, occurs here" , name) ) ;
678685 for ( span, name) in conflicts_mut_mut {
679686 err. span_label ( span, format ! ( "another mutable borrow, by `{}`, occurs here" , name) ) ;
@@ -693,7 +700,7 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
693700 } ;
694701 let msg =
695702 format ! ( "cannot borrow value as {} because it is also borrowed as {}" , also, primary) ;
696- let mut err = sess. struct_span_err ( pat . span , & msg) ;
703+ let mut err = sess. struct_span_err ( pat_span , & msg) ;
697704 err. span_label ( binding_span, format ! ( "{} borrow, by `{}`, occurs here" , primary, name) ) ;
698705 for ( span, name) in conflicts_mut_ref {
699706 err. span_label ( span, format ! ( "{} borrow, by `{}`, occurs here" , also, name) ) ;
@@ -705,7 +712,7 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
705712 } else if !conflicts_move. is_empty ( ) {
706713 // Report by-ref and by-move conflicts, e.g. `ref x @ y`.
707714 let mut err =
708- sess. struct_span_err ( pat . span , "cannot move out of value because it is borrowed" ) ;
715+ sess. struct_span_err ( pat_span , "cannot move out of value because it is borrowed" ) ;
709716 err. span_label ( binding_span, format ! ( "value borrowed, by `{}`, here" , name) ) ;
710717 for ( span, name) in conflicts_move {
711718 err. span_label ( span, format ! ( "value moved into `{}` here" , name) ) ;
@@ -735,10 +742,11 @@ fn check_legality_of_bindings_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pa
735742 match pat. kind {
736743 hir:: PatKind :: Binding ( .., ref subpat) => {
737744 if !self . bindings_allowed {
745+ let pat_span = self . cx . tcx . hir ( ) . span ( pat. hir_id ) ;
738746 feature_err (
739747 & self . cx . tcx . sess . parse_sess ,
740748 sym:: bindings_after_at,
741- pat . span ,
749+ pat_span ,
742750 "pattern bindings after an `@` are unstable" ,
743751 )
744752 . emit ( ) ;
0 commit comments