Skip to content

Commit 275432c

Browse files
committed
Give an error number for "borrowed data escapes outside of closure"
1 parent 049bee0 commit 275432c

7 files changed

+31
-9
lines changed

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use borrow_check::nll::region_infer::RegionInferenceContext;
1313
use borrow_check::nll::region_infer::error_reporting::region_name::RegionNameSource;
1414
use borrow_check::nll::type_check::Locations;
1515
use borrow_check::nll::universal_regions::DefiningTy;
16+
use util::borrowck_errors::{BorrowckErrors, Origin};
1617
use rustc::hir::def_id::DefId;
1718
use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
1819
use rustc::infer::InferCtxt;
@@ -395,9 +396,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
395396
category, span, errors_buffer);
396397
}
397398

398-
let mut diag = infcx.tcx.sess.struct_span_err(
399-
span, &format!("borrowed data escapes outside of {}", escapes_from),
400-
);
399+
let mut diag = infcx.tcx.borrowed_data_escapes_closure(span, escapes_from, Origin::Mir);
401400

402401
if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
403402
diag.span_label(

src/librustc_mir/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,7 @@ register_diagnostics! {
23392339
// E0471, // constant evaluation error (in pattern)
23402340
// E0385, // {} in an aliasable location
23412341
E0493, // destructors cannot be evaluated at compile-time
2342+
E0521, // borrowed data escapes outside of closure
23422343
E0524, // two closures require unique access to `..` at the same time
23432344
E0526, // shuffle indices are not constant
23442345
E0594, // cannot assign to {}

src/librustc_mir/util/borrowck_errors.rs

+18
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,24 @@ pub trait BorrowckErrors<'cx>: Sized + Copy {
717717
self.cancel_if_wrong_origin(err, o)
718718
}
719719

720+
fn borrowed_data_escapes_closure(
721+
self,
722+
escape_span: Span,
723+
escapes_from: &str,
724+
o: Origin,
725+
) -> DiagnosticBuilder<'cx> {
726+
let err = struct_span_err!(
727+
self,
728+
escape_span,
729+
E0521,
730+
"borrowed data escapes outside of {}{OGN}",
731+
escapes_from,
732+
OGN = o
733+
);
734+
735+
self.cancel_if_wrong_origin(err, o)
736+
}
737+
720738
fn thread_local_value_does_not_live_long_enough(
721739
self,
722740
span: Span,

src/test/ui/borrowck/issue-45983.nll.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: borrowed data escapes outside of closure
1+
error[E0521]: borrowed data escapes outside of closure
22
--> $DIR/issue-45983.rs:36:18
33
|
44
LL | let x = None;
@@ -18,4 +18,5 @@ LL | give_any(|y| x = Some(y));
1818

1919
error: aborting due to 2 previous errors
2020

21-
For more information about this error, try `rustc --explain E0594`.
21+
Some errors occurred: E0521, E0594.
22+
For more information about an error, try `rustc --explain E0521`.

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | | })
1313
for<'r> extern "rust-call" fn((std::cell::Cell<&'_#1r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex(0), BrNamed(crate0:DefIndex(0:0), 'r)) u32>))
1414
]
1515

16-
error: borrowed data escapes outside of closure
16+
error[E0521]: borrowed data escapes outside of closure
1717
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:32:9
1818
|
1919
LL | foo(cell, |cell_a, cell_x| {
@@ -80,4 +80,5 @@ LL | }
8080

8181
error: aborting due to 2 previous errors
8282

83-
For more information about this error, try `rustc --explain E0597`.
83+
Some errors occurred: E0521, E0597.
84+
For more information about an error, try `rustc --explain E0521`.

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ LL | | }
3434
|
3535
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []
3636

37-
error: borrowed data escapes outside of function
37+
error[E0521]: borrowed data escapes outside of function
3838
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:5
3939
|
4040
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
@@ -61,3 +61,4 @@ LL | demand_y(x, y, x.get())
6161

6262
error: aborting due to 2 previous errors
6363

64+
For more information about this error, try `rustc --explain E0521`.

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LL | | }
3333
|
3434
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []
3535

36-
error: borrowed data escapes outside of function
36+
error[E0521]: borrowed data escapes outside of function
3737
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:5
3838
|
3939
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
@@ -59,3 +59,4 @@ LL | demand_y(x, y, x.get())
5959

6060
error: aborting due to 2 previous errors
6161

62+
For more information about this error, try `rustc --explain E0521`.

0 commit comments

Comments
 (0)