File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
compiler/rustc_error_codes/src Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,7 @@ E0516: include_str!("./error_codes/E0516.md"),
267267E0517 : include_str!( "./error_codes/E0517.md" ) ,
268268E0518 : include_str!( "./error_codes/E0518.md" ) ,
269269E0520 : include_str!( "./error_codes/E0520.md" ) ,
270+ E0521 : include_str!( "./error_codes/E0521.md" ) ,
270271E0522 : include_str!( "./error_codes/E0522.md" ) ,
271272E0524 : include_str!( "./error_codes/E0524.md" ) ,
272273E0525 : 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 number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments