@@ -18,46 +18,64 @@ use util::common::ErrorReported;
18
18
mod different_lifetimes;
19
19
mod find_anon_type;
20
20
mod named_anon_conflict;
21
+ mod outlives_closure;
21
22
mod util;
22
23
23
24
impl < ' cx , ' gcx , ' tcx > InferCtxt < ' cx , ' gcx , ' tcx > {
24
25
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
+ }
30
30
31
31
if let Some ( tables) = self . in_progress_tables {
32
32
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 ( )
34
34
} 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 ( )
36
36
}
37
37
}
38
38
}
39
39
40
40
pub struct NiceRegionError < ' cx , ' gcx : ' tcx , ' tcx : ' cx > {
41
41
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 > ) > ,
45
44
tables : Option < & ' cx ty:: TypeckTables < ' tcx > > ,
46
45
}
47
46
48
47
impl < ' cx , ' gcx , ' tcx > NiceRegionError < ' cx , ' gcx , ' tcx > {
49
48
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 (
50
57
tcx : TyCtxt < ' cx , ' gcx , ' tcx > ,
51
58
span : Span ,
52
59
sub : ty:: Region < ' tcx > ,
53
60
sup : ty:: Region < ' tcx > ,
54
61
tables : Option < & ' cx ty:: TypeckTables < ' tcx > > ,
55
62
) -> Self {
56
- Self { tcx, span, sub, sup, tables }
63
+ Self { tcx, error : None , regions : Some ( ( span, sub, sup) ) , tables }
57
64
}
58
65
59
66
pub fn try_report ( & self ) -> Option < ErrorReported > {
60
67
self . try_report_named_anon_conflict ( )
61
68
. 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
+ }
62
80
}
63
81
}
0 commit comments