Skip to content

Commit bc33094

Browse files
authored
Rollup merge of rust-lang#81634 - jesusprubio:jesusprubio/add-long-explanation-e0521, r=GuillaumeGomez
Add long explanation e0521 Helps with rust-lang#61137
2 parents 39b3ce9 + 9ef24f9 commit bc33094

15 files changed

+43
-2
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ E0516: include_str!("./error_codes/E0516.md"),
267267
E0517: include_str!("./error_codes/E0517.md"),
268268
E0518: include_str!("./error_codes/E0518.md"),
269269
E0520: include_str!("./error_codes/E0520.md"),
270+
E0521: include_str!("./error_codes/E0521.md"),
270271
E0522: include_str!("./error_codes/E0522.md"),
271272
E0524: include_str!("./error_codes/E0524.md"),
272273
E0525: include_str!("./error_codes/E0525.md"),
@@ -597,7 +598,6 @@ E0780: include_str!("./error_codes/E0780.md"),
597598
E0514, // metadata version mismatch
598599
E0519, // local crate and dependency have same (crate-name, disambiguator)
599600
// two dependencies have same (crate-name, disambiguator) but different SVH
600-
E0521, // borrowed data escapes outside of closure
601601
E0523,
602602
// E0526, // shuffle indices are not constant
603603
// E0540, // multiple rustc_deprecated attributes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Borrowed data escapes outside of closure.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0521
6+
let mut list: Vec<&str> = Vec::new();
7+
8+
let _add = |el: &str| {
9+
list.push(el); // error: `el` escapes the closure body here
10+
};
11+
```
12+
13+
A type anotation of a closure parameter implies a new lifetime declaration.
14+
Consider to drop it, the compiler is reliably able to infer them.
15+
16+
```
17+
let mut list: Vec<&str> = Vec::new();
18+
19+
let _add = |el| {
20+
list.push(el);
21+
};
22+
```
23+
24+
See the [Closure type inference and annotation][closure-infere-annotation] and
25+
[Lifetime elision][lifetime-elision] sections of the Book for more details.
26+
27+
[closure-infere-annotation]: https://doc.rust-lang.org/book/ch13-01-closures.html#closure-type-inference-and-annotation
28+
[lifetime-elision]: https://doc.rust-lang.org/reference/lifetime-elision.html

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

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ LL | give_any(|y| x = Some(y));
1010

1111
error: aborting due to previous error
1212

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

src/test/ui/borrowck/issue-7573.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ LL | lines_to_use.push(installed_id);
1212

1313
error: aborting due to previous error
1414

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

src/test/ui/borrowck/regions-escape-bound-fn-2.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ LL | with_int(|y| x = Some(y));
1010

1111
error: aborting due to previous error
1212

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

src/test/ui/borrowck/regions-escape-bound-fn.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ LL | with_int(|y| x = Some(y));
1010

1111
error: aborting due to previous error
1212

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

src/test/ui/borrowck/regions-escape-unboxed-closure.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ LL | with_int(&mut |y| x = Some(y));
1010

1111
error: aborting due to previous error
1212

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

src/test/ui/closures/closure-expected-type/expect-region-supply-region.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ LL | f = Some(x);
2020

2121
error: aborting due to 2 previous errors
2222

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

src/test/ui/generator/ref-escapes-but-not-over-yield.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ LL | a = &b;
1212

1313
error: aborting due to previous error
1414

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

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@ LL | }
8383

8484
error: aborting due to 2 previous errors
8585

86-
For more information about this error, try `rustc --explain E0597`.
86+
Some errors have detailed explanations: E0521, E0597.
87+
For more information about an error, try `rustc --explain E0521`.

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

+1
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ LL | | });
5151

5252
error: aborting due to previous error
5353

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

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

+1
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ LL | | });
5151

5252
error: aborting due to previous error
5353

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

src/test/ui/nll/outlives-suggestion-simple.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,4 @@ LL | Bar2::new(&self)
106106

107107
error: aborting due to 9 previous errors
108108

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

src/test/ui/nll/user-annotations/closure-substs.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ LL | b(x);
3838

3939
error: aborting due to 4 previous errors
4040

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

src/test/ui/regions/issue-78262.nll.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ LL | let f = |x: &dyn TT| x.func();
88

99
error: aborting due to previous error
1010

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

0 commit comments

Comments
 (0)