Skip to content

Commit 7eca647

Browse files
committed
Update error format for E0373
1 parent 4c02363 commit 7eca647

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

src/librustc_borrowck/borrowck/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -942,9 +942,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
942942
but it borrows {}, \
943943
which is owned by the current function",
944944
cmt_path_or_string)
945-
.span_note(capture_span,
945+
.span_label(capture_span,
946946
&format!("{} is borrowed here",
947947
cmt_path_or_string))
948+
.span_label(err.span,
949+
&format!("may outlive borrowed value {}",
950+
cmt_path_or_string))
948951
.span_suggestion(err.span,
949952
&format!("to force the closure to take ownership of {} \
950953
(and any other referenced variables), \

src/test/compile-fail/borrowck/borrowck-escaping-closure-error-1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ fn main() {
2222
let mut books = vec![1,2,3];
2323
spawn(|| books.push(4));
2424
//~^ ERROR E0373
25+
//~| NOTE `books` is borrowed here
26+
//~| NOTE may outlive borrowed value `books`
2527
}

src/test/compile-fail/borrowck/borrowck-escaping-closure-error-2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ fn foo<'a>(x: &'a i32) -> Box<FnMut()+'a> {
2020
let mut books = vec![1,2,3];
2121
Box::new(|| books.push(4))
2222
//~^ ERROR E0373
23+
//~| NOTE `books` is borrowed here
24+
//~| NOTE may outlive borrowed value `books`
2325
}
2426

2527
fn main() { }

src/test/compile-fail/issue-4335.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ fn f<'r, T>(v: &'r T) -> Box<FnMut() -> T + 'r> {
1414
// FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
1515
id(Box::new(|| *v))
1616
//~^ ERROR E0373
17-
//~| ERROR cannot move out of borrowed content
17+
//~| NOTE `v` is borrowed here
18+
//~| NOTE may outlive borrowed value `v`
19+
//~| ERROR E0507
20+
//~| NOTE cannot move out of borrowed content
1821
}
1922

2023
fn main() {

src/test/compile-fail/region-borrow-params-issue-29793-small.rs

+40
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
fn escaping_borrow_of_closure_params_1() {
1818
let g = |x: usize, y:usize| {
19+
//~^ NOTE reference must be valid for the scope of call-site for function
20+
//~| NOTE ...but borrowed value is only valid for the scope of function body
21+
//~| NOTE reference must be valid for the scope of call-site for function
22+
//~| NOTE ...but borrowed value is only valid for the scope of function body
1923
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
2024
//~^ ERROR `x` does not live long enough
2125
//~| ERROR `y` does not live long enough
@@ -31,6 +35,10 @@ fn escaping_borrow_of_closure_params_1() {
3135

3236
fn escaping_borrow_of_closure_params_2() {
3337
let g = |x: usize, y:usize| {
38+
//~^ NOTE reference must be valid for the scope of call-site for function
39+
//~| NOTE ...but borrowed value is only valid for the scope of function body
40+
//~| NOTE reference must be valid for the scope of call-site for function
41+
//~| NOTE ...but borrowed value is only valid for the scope of function body
3442
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
3543
//~^ ERROR `x` does not live long enough
3644
//~| ERROR `y` does not live long enough
@@ -64,7 +72,11 @@ fn escaping_borrow_of_fn_params_1() {
6472
fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
6573
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
6674
//~^ ERROR E0373
75+
//~| NOTE `x` is borrowed here
76+
//~| NOTE may outlive borrowed value `x`
6777
//~| ERROR E0373
78+
//~| NOTE `y` is borrowed here
79+
//~| NOTE may outlive borrowed value `y`
6880
return Box::new(f);
6981
};
7082

@@ -75,7 +87,11 @@ fn escaping_borrow_of_fn_params_2() {
7587
fn g<'a>(x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
7688
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
7789
//~^ ERROR E0373
90+
//~| NOTE `x` is borrowed here
91+
//~| NOTE may outlive borrowed value `x`
7892
//~| ERROR E0373
93+
//~| NOTE `y` is borrowed here
94+
//~| NOTE may outlive borrowed value `y`
7995
Box::new(f)
8096
};
8197

@@ -99,7 +115,11 @@ fn escaping_borrow_of_method_params_1() {
99115
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
100116
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
101117
//~^ ERROR E0373
118+
//~| NOTE `x` is borrowed here
119+
//~| NOTE may outlive borrowed value `x`
102120
//~| ERROR E0373
121+
//~| NOTE `y` is borrowed here
122+
//~| NOTE may outlive borrowed value `y`
103123
return Box::new(f);
104124
}
105125
}
@@ -113,7 +133,11 @@ fn escaping_borrow_of_method_params_2() {
113133
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
114134
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
115135
//~^ ERROR E0373
136+
//~| NOTE `x` is borrowed here
137+
//~| NOTE may outlive borrowed value `x`
116138
//~| ERROR E0373
139+
//~| NOTE `y` is borrowed here
140+
//~| NOTE may outlive borrowed value `y`
117141
Box::new(f)
118142
}
119143
}
@@ -141,7 +165,11 @@ fn escaping_borrow_of_trait_impl_params_1() {
141165
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
142166
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
143167
//~^ ERROR E0373
168+
//~| NOTE `x` is borrowed here
169+
//~| NOTE may outlive borrowed value `x`
144170
//~| ERROR E0373
171+
//~| NOTE `y` is borrowed here
172+
//~| NOTE may outlive borrowed value `y`
145173
return Box::new(f);
146174
}
147175
}
@@ -156,7 +184,11 @@ fn escaping_borrow_of_trait_impl_params_2() {
156184
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
157185
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
158186
//~^ ERROR E0373
187+
//~| NOTE `x` is borrowed here
188+
//~| NOTE may outlive borrowed value `x`
159189
//~| ERROR E0373
190+
//~| NOTE `y` is borrowed here
191+
//~| NOTE may outlive borrowed value `y`
160192
Box::new(f)
161193
}
162194
}
@@ -184,7 +216,11 @@ fn escaping_borrow_of_trait_default_params_1() {
184216
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
185217
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
186218
//~^ ERROR E0373
219+
//~| NOTE `x` is borrowed here
220+
//~| NOTE may outlive borrowed value `x`
187221
//~| ERROR E0373
222+
//~| NOTE `y` is borrowed here
223+
//~| NOTE may outlive borrowed value `y`
188224
return Box::new(f);
189225
}
190226
}
@@ -198,7 +234,11 @@ fn escaping_borrow_of_trait_default_params_2() {
198234
fn g<'a>(&self, x: usize, y:usize) -> Box<Fn(bool) -> usize + 'a> {
199235
let f = |t: bool| if t { x } else { y }; // (separate errors for `x` vs `y`)
200236
//~^ ERROR E0373
237+
//~| NOTE `x` is borrowed here
238+
//~| NOTE may outlive borrowed value `x`
201239
//~| ERROR E0373
240+
//~| NOTE `y` is borrowed here
241+
//~| NOTE may outlive borrowed value `y`
202242
Box::new(f)
203243
}
204244
}

src/test/compile-fail/regions-nested-fns-2.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ fn ignore<F>(_f: F) where F: for<'z> FnOnce(&'z isize) -> &'z isize {}
1313
fn nested() {
1414
let y = 3;
1515
ignore(
16-
|z| { //~ ERROR E0373
16+
|z| {
17+
//~^ ERROR E0373
18+
//~| NOTE may outlive borrowed value `y`
1719
if false { &y } else { z }
20+
//~^ NOTE `y` is borrowed here
1821
});
1922
}
2023

0 commit comments

Comments
 (0)