Tweak wording and spans of closure lifetime errors
This commit is contained in:
parent
1820da5211
commit
6f9ecaa7cf
6 changed files with 64 additions and 33 deletions
|
|
@ -69,16 +69,46 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
|
|||
sup_sp,
|
||||
"borrowed data cannot be stored outside of its closure");
|
||||
err.span_label(sup_sp, "cannot be stored outside of its closure");
|
||||
if sup_sp == origin_sp {
|
||||
if origin_sp == sup_sp || origin_sp.contains(sup_sp) {
|
||||
// // sup_sp == origin.span():
|
||||
//
|
||||
// let mut x = None;
|
||||
// ----- borrowed data cannot be stored into here...
|
||||
// with_int(|y| x = Some(y));
|
||||
// --- ^ cannot be stored outside of its closure
|
||||
// |
|
||||
// ...because it cannot outlive this closure
|
||||
//
|
||||
// // origin.contains(&sup_sp):
|
||||
//
|
||||
// let mut f: Option<&u32> = None;
|
||||
// ----- borrowed data cannot be stored into here...
|
||||
// closure_expecting_bound(|x: &'x u32| {
|
||||
// ------------ ... because it cannot outlive this closure
|
||||
// f = Some(x);
|
||||
// ^ cannot be stored outside of its closure
|
||||
err.span_label(*external_span,
|
||||
"borrowed data cannot be stored into here...");
|
||||
err.span_label(*closure_span,
|
||||
"...because it cannot outlive this closure");
|
||||
} else {
|
||||
// FIXME: the wording for this case could be much improved
|
||||
//
|
||||
// let mut lines_to_use: Vec<&CrateId> = Vec::new();
|
||||
// - cannot infer an appropriate lifetime...
|
||||
// let push_id = |installed_id: &CrateId| {
|
||||
// ------- ------------------------ borrowed data cannot outlive this closure
|
||||
// |
|
||||
// ...so that variable is valid at time of its declaration
|
||||
// lines_to_use.push(installed_id);
|
||||
// ^^^^^^^^^^^^ cannot be stored outside of its closure
|
||||
err.span_label(origin_sp,
|
||||
"cannot infer an appropriate lifetime...");
|
||||
err.span_label(*external_span,
|
||||
"...so that variable is valid at time of its \
|
||||
declaration");
|
||||
err.span_label(*closure_span,
|
||||
"borrowed data cannot outlive this closure");
|
||||
err.span_label(origin_sp,
|
||||
"cannot infer an appropriate lifetime");
|
||||
}
|
||||
err.emit();
|
||||
return Some(ErrorReported);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ pub fn remove_package_from_database() {
|
|||
//~^ NOTE cannot infer an appropriate lifetime
|
||||
let push_id = |installed_id: &CrateId| {
|
||||
//~^ NOTE borrowed data cannot outlive this closure
|
||||
//~| NOTE ...so that variable is valid at time of its declaration
|
||||
lines_to_use.push(installed_id);
|
||||
//~^ ERROR borrowed data cannot be stored outside of its closure
|
||||
//~| NOTE cannot be stored outside of its closure
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
error: borrowed data cannot be stored outside of its closure
|
||||
--> $DIR/issue-7573.rs:31:27
|
||||
--> $DIR/issue-7573.rs:32:27
|
||||
|
|
||||
27 | let mut lines_to_use: Vec<&CrateId> = Vec::new();
|
||||
| - cannot infer an appropriate lifetime
|
||||
| - cannot infer an appropriate lifetime...
|
||||
28 | //~^ NOTE cannot infer an appropriate lifetime
|
||||
29 | let push_id = |installed_id: &CrateId| {
|
||||
| ------------------------ borrowed data cannot outlive this closure
|
||||
30 | //~^ NOTE borrowed data cannot outlive this closure
|
||||
31 | lines_to_use.push(installed_id);
|
||||
| ------- ------------------------ borrowed data cannot outlive this closure
|
||||
| |
|
||||
| ...so that variable is valid at time of its declaration
|
||||
...
|
||||
32 | lines_to_use.push(installed_id);
|
||||
| ^^^^^^^^^^^^ cannot be stored outside of its closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
error: borrowed data cannot be stored outside of its closure
|
||||
--> $DIR/regions-escape-bound-fn.rs:18:27
|
||||
|
|
||||
17 | let mut x: Option<&isize> = None;
|
||||
| ----- borrowed data cannot be stored into here...
|
||||
18 | with_int(|y| x = Some(y));
|
||||
| --- -----^-
|
||||
| | | |
|
||||
| | | cannot be stored outside of its closure
|
||||
| | cannot infer an appropriate lifetime
|
||||
| borrowed data cannot outlive this closure
|
||||
| --- ^ cannot be stored outside of its closure
|
||||
| |
|
||||
| ...because it cannot outlive this closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
error: borrowed data cannot be stored outside of its closure
|
||||
--> $DIR/regions-escape-unboxed-closure.rs:16:32
|
||||
|
|
||||
15 | let mut x: Option<&isize> = None;
|
||||
| ----- borrowed data cannot be stored into here...
|
||||
16 | with_int(&mut |y| x = Some(y));
|
||||
| --- -----^-
|
||||
| | | |
|
||||
| | | cannot be stored outside of its closure
|
||||
| | cannot infer an appropriate lifetime
|
||||
| borrowed data cannot outlive this closure
|
||||
| --- ^ cannot be stored outside of its closure
|
||||
| |
|
||||
| ...because it cannot outlive this closure
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
error: borrowed data cannot be stored outside of its closure
|
||||
--> $DIR/expect-region-supply-region.rs:28:18
|
||||
|
|
||||
26 | let mut f: Option<&u32> = None;
|
||||
| ----- borrowed data cannot be stored into here...
|
||||
27 | closure_expecting_bound(|x| {
|
||||
| --- borrowed data cannot outlive this closure
|
||||
| --- ...because it cannot outlive this closure
|
||||
28 | f = Some(x); //~ ERROR borrowed data cannot be stored outside of its closure
|
||||
| -----^-
|
||||
| | |
|
||||
| | cannot be stored outside of its closure
|
||||
| cannot infer an appropriate lifetime
|
||||
| ^ cannot be stored outside of its closure
|
||||
|
||||
error: borrowed data cannot be stored outside of its closure
|
||||
--> $DIR/expect-region-supply-region.rs:38:18
|
||||
|
|
||||
36 | let mut f: Option<&u32> = None;
|
||||
| ----- borrowed data cannot be stored into here...
|
||||
37 | closure_expecting_bound(|x: &u32| {
|
||||
| --------- borrowed data cannot outlive this closure
|
||||
| --------- ...because it cannot outlive this closure
|
||||
38 | f = Some(x); //~ ERROR borrowed data cannot be stored outside of its closure
|
||||
| -----^-
|
||||
| | |
|
||||
| | cannot be stored outside of its closure
|
||||
| cannot infer an appropriate lifetime
|
||||
| ^ cannot be stored outside of its closure
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/expect-region-supply-region.rs:47:33
|
||||
|
|
@ -87,14 +85,14 @@ note: ...does not necessarily outlive the anonymous lifetime #2 defined on the b
|
|||
error: borrowed data cannot be stored outside of its closure
|
||||
--> $DIR/expect-region-supply-region.rs:52:18
|
||||
|
|
||||
43 | let mut f: Option<&u32> = None;
|
||||
| ----- borrowed data cannot be stored into here...
|
||||
...
|
||||
47 | closure_expecting_bound(|x: &'x u32| {
|
||||
| ------------ borrowed data cannot outlive this closure
|
||||
| ------------ ...because it cannot outlive this closure
|
||||
...
|
||||
52 | f = Some(x);
|
||||
| -----^-
|
||||
| | |
|
||||
| | cannot be stored outside of its closure
|
||||
| cannot infer an appropriate lifetime
|
||||
| ^ cannot be stored outside of its closure
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue