@@ -146,8 +146,8 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
146146 let graph = self . construct_graph ( ) ;
147147 self . expand_givens ( & graph) ;
148148 self . expansion ( & mut var_data) ;
149- let captures = self . collect_errors ( & mut var_data, errors) ;
150- self . collect_var_errors ( & var_data, & graph, errors, captures ) ;
149+ self . collect_errors ( & mut var_data, errors) ;
150+ self . collect_var_errors ( & var_data, & graph, errors) ;
151151 var_data
152152 }
153153
@@ -445,16 +445,9 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
445445 & self ,
446446 var_data : & mut LexicalRegionResolutions < ' tcx > ,
447447 errors : & mut Vec < RegionResolutionError < ' tcx > > ,
448- ) -> Vec < Span > {
449- let mut captures = vec ! [ ] ;
450-
448+ ) {
451449 for ( constraint, origin) in & self . data . constraints {
452450 debug ! ( ?constraint, ?origin) ;
453- if let ( Constraint :: VarSubVar ( _, _) , SubregionOrigin :: DataBorrowed ( _, sp) ) =
454- ( constraint, origin)
455- {
456- captures. push ( * sp) ;
457- }
458451 match * constraint {
459452 Constraint :: RegSubVar ( ..) | Constraint :: VarSubVar ( ..) => {
460453 // Expansion will ensure that these constraints hold. Ignore.
@@ -524,7 +517,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
524517 sub,
525518 ) ) ;
526519 }
527- captures
528520 }
529521
530522 /// Go over the variables that were declared to be error variables
@@ -534,7 +526,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
534526 var_data : & LexicalRegionResolutions < ' tcx > ,
535527 graph : & RegionGraph < ' tcx > ,
536528 errors : & mut Vec < RegionResolutionError < ' tcx > > ,
537- captures : Vec < Span > ,
538529 ) {
539530 debug ! ( "collect_var_errors, var_data = {:#?}" , var_data. values) ;
540531
@@ -578,12 +569,27 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
578569 // if this rule starts to create problems we'll
579570 // have to revisit this portion of the code and
580571 // think hard about it. =) -- nikomatsakis
572+
573+ // Obtain the spans for all the capture points for
574+ // richer diagnostics in `static_impl_trait`.
575+ let captures: Vec < Span > = self
576+ . data
577+ . constraints
578+ . iter ( )
579+ . filter_map ( |( constraint, origin) | match ( constraint, origin) {
580+ ( Constraint :: VarSubVar ( _, _) , SubregionOrigin :: DataBorrowed ( _, sp) ) => {
581+ Some ( * sp)
582+ }
583+ _ => None ,
584+ } )
585+ . collect ( ) ;
586+
581587 self . collect_error_for_expanding_node (
582588 graph,
583589 & mut dup_vec,
584590 node_vid,
585591 errors,
586- & captures,
592+ captures,
587593 ) ;
588594 }
589595 }
@@ -638,7 +644,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
638644 dup_vec : & mut IndexVec < RegionVid , Option < RegionVid > > ,
639645 node_idx : RegionVid ,
640646 errors : & mut Vec < RegionResolutionError < ' tcx > > ,
641- captures : & [ Span ] ,
647+ captures : Vec < Span > ,
642648 ) {
643649 // Errors in expanding nodes result from a lower-bound that is
644650 // not contained by an upper-bound.
@@ -686,18 +692,14 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
686692 origin, node_idx, lower_bound. region, upper_bound. region
687693 ) ;
688694
689- let mut capture_spans: Vec < Span > = captures. iter ( ) . cloned ( ) . collect ( ) ;
690- // Below, one span expects `&Span` and the other `&mut Span`, hence the dupes.
691- capture_spans. sort_by_key ( |span| ( span. lo ( ) , span. hi ( ) ) ) ;
692- capture_spans. dedup_by_key ( |span| ( span. lo ( ) , span. hi ( ) ) ) ;
693695 errors. push ( RegionResolutionError :: SubSupConflict (
694696 node_idx,
695697 origin,
696698 lower_bound. origin . clone ( ) ,
697699 lower_bound. region ,
698700 upper_bound. origin . clone ( ) ,
699701 upper_bound. region ,
700- capture_spans ,
702+ captures ,
701703 ) ) ;
702704 return ;
703705 }
0 commit comments