@@ -18,46 +18,64 @@ use util::common::ErrorReported;
1818mod different_lifetimes;
1919mod find_anon_type;
2020mod named_anon_conflict;
21+ mod outlives_closure;
2122mod util;
2223
2324impl < ' cx , ' gcx , ' tcx > InferCtxt < ' cx , ' gcx , ' tcx > {
2425 pub fn try_report_nice_region_error ( & self , error : & RegionResolutionError < ' tcx > ) -> bool {
25- let ( span, sub, sup) = match * error {
26- ConcreteFailure ( ref origin, sub, sup) => ( origin. span ( ) , sub, sup) ,
27- SubSupConflict ( _, ref origin, sub, _, sup) => ( origin. span ( ) , sub, sup) ,
28- _ => return false , // inapplicable
29- } ;
26+ match * error {
27+ ConcreteFailure ( ..) | SubSupConflict ( ..) => { }
28+ _ => return false , // inapplicable
29+ }
3030
3131 if let Some ( tables) = self . in_progress_tables {
3232 let tables = tables. borrow ( ) ;
33- NiceRegionError :: new ( self . tcx , span , sub , sup , Some ( & tables) ) . try_report ( ) . is_some ( )
33+ NiceRegionError :: new ( self . tcx , error . clone ( ) , Some ( & tables) ) . try_report ( ) . is_some ( )
3434 } else {
35- NiceRegionError :: new ( self . tcx , span , sub , sup , None ) . try_report ( ) . is_some ( )
35+ NiceRegionError :: new ( self . tcx , error . clone ( ) , None ) . try_report ( ) . is_some ( )
3636 }
3737 }
3838}
3939
4040pub struct NiceRegionError < ' cx , ' gcx : ' tcx , ' tcx : ' cx > {
4141 tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
42- span : Span ,
43- sub : ty:: Region < ' tcx > ,
44- sup : ty:: Region < ' tcx > ,
42+ error : Option < RegionResolutionError < ' tcx > > ,
43+ regions : Option < ( Span , ty:: Region < ' tcx > , ty:: Region < ' tcx > ) > ,
4544 tables : Option < & ' cx ty:: TypeckTables < ' tcx > > ,
4645}
4746
4847impl < ' cx , ' gcx , ' tcx > NiceRegionError < ' cx , ' gcx , ' tcx > {
4948 pub fn new (
49+ tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
50+ error : RegionResolutionError < ' tcx > ,
51+ tables : Option < & ' cx ty:: TypeckTables < ' tcx > > ,
52+ ) -> Self {
53+ Self { tcx, error : Some ( error) , regions : None , tables }
54+ }
55+
56+ pub fn new_from_span (
5057 tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
5158 span : Span ,
5259 sub : ty:: Region < ' tcx > ,
5360 sup : ty:: Region < ' tcx > ,
5461 tables : Option < & ' cx ty:: TypeckTables < ' tcx > > ,
5562 ) -> Self {
56- Self { tcx, span, sub, sup, tables }
63+ Self { tcx, error : None , regions : Some ( ( span, sub, sup) ) , tables }
5764 }
5865
5966 pub fn try_report ( & self ) -> Option < ErrorReported > {
6067 self . try_report_named_anon_conflict ( )
6168 . or_else ( || self . try_report_anon_anon_conflict ( ) )
69+ . or_else ( || self . try_report_outlives_closure ( ) )
70+ }
71+
72+ pub fn get_regions ( & self ) -> ( Span , ty:: Region < ' tcx > , ty:: Region < ' tcx > ) {
73+ match ( & self . error , self . regions ) {
74+ ( & Some ( ConcreteFailure ( ref origin, sub, sup) ) , None ) => ( origin. span ( ) , sub, sup) ,
75+ ( & Some ( SubSupConflict ( _, ref origin, sub, _, sup) ) , None ) => ( origin. span ( ) , sub, sup) ,
76+ ( None , Some ( ( span, sub, sup) ) ) => ( span, sub, sup) ,
77+ ( Some ( _) , Some ( _) ) => panic ! ( "incorrectly built NiceRegionError" ) ,
78+ _ => panic ! ( "trying to report on an incorrect lifetime failure" ) ,
79+ }
6280 }
6381}
0 commit comments