@@ -69,16 +69,46 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
69
69
sup_sp,
70
70
"borrowed data cannot be stored outside of its closure" ) ;
71
71
err. span_label ( sup_sp, "cannot be stored outside of its closure" ) ;
72
- if sup_sp == origin_sp {
72
+ if origin_sp == sup_sp || origin_sp. contains ( sup_sp) {
73
+ // // sup_sp == origin.span():
74
+ //
75
+ // let mut x = None;
76
+ // ----- borrowed data cannot be stored into here...
77
+ // with_int(|y| x = Some(y));
78
+ // --- ^ cannot be stored outside of its closure
79
+ // |
80
+ // ...because it cannot outlive this closure
81
+ //
82
+ // // origin.contains(&sup_sp):
83
+ //
84
+ // let mut f: Option<&u32> = None;
85
+ // ----- borrowed data cannot be stored into here...
86
+ // closure_expecting_bound(|x: &'x u32| {
87
+ // ------------ ... because it cannot outlive this closure
88
+ // f = Some(x);
89
+ // ^ cannot be stored outside of its closure
73
90
err. span_label ( * external_span,
74
91
"borrowed data cannot be stored into here..." ) ;
75
92
err. span_label ( * closure_span,
76
93
"...because it cannot outlive this closure" ) ;
77
94
} else {
95
+ // FIXME: the wording for this case could be much improved
96
+ //
97
+ // let mut lines_to_use: Vec<&CrateId> = Vec::new();
98
+ // - cannot infer an appropriate lifetime...
99
+ // let push_id = |installed_id: &CrateId| {
100
+ // ------- ------------------------ borrowed data cannot outlive this closure
101
+ // |
102
+ // ...so that variable is valid at time of its declaration
103
+ // lines_to_use.push(installed_id);
104
+ // ^^^^^^^^^^^^ cannot be stored outside of its closure
105
+ err. span_label ( origin_sp,
106
+ "cannot infer an appropriate lifetime..." ) ;
107
+ err. span_label ( * external_span,
108
+ "...so that variable is valid at time of its \
109
+ declaration") ;
78
110
err. span_label ( * closure_span,
79
111
"borrowed data cannot outlive this closure" ) ;
80
- err. span_label ( origin_sp,
81
- "cannot infer an appropriate lifetime" ) ;
82
112
}
83
113
err. emit ( ) ;
84
114
return Some ( ErrorReported ) ;
0 commit comments