Rollup merge of #81634 - jesusprubio:jesusprubio/add-long-explanation-e0521, r=GuillaumeGomez

Add long explanation e0521

Helps with #61137
This commit is contained in:
Jack Huey 2021-02-02 16:01:44 -05:00 committed by GitHub
commit fd4f4adede
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 55 additions and 4 deletions

View File

@ -267,6 +267,7 @@ E0516: include_str!("./error_codes/E0516.md"),
E0517: include_str!("./error_codes/E0517.md"),
E0518: include_str!("./error_codes/E0518.md"),
E0520: include_str!("./error_codes/E0520.md"),
E0521: include_str!("./error_codes/E0521.md"),
E0522: include_str!("./error_codes/E0522.md"),
E0524: include_str!("./error_codes/E0524.md"),
E0525: include_str!("./error_codes/E0525.md"),
@ -597,7 +598,6 @@ E0780: include_str!("./error_codes/E0780.md"),
E0514, // metadata version mismatch
E0519, // local crate and dependency have same (crate-name, disambiguator)
// two dependencies have same (crate-name, disambiguator) but different SVH
E0521, // borrowed data escapes outside of closure
E0523,
// E0526, // shuffle indices are not constant
// E0540, // multiple rustc_deprecated attributes

View File

@ -0,0 +1,28 @@
Borrowed data escapes outside of closure.
Erroneous code example:
```compile_fail,E0521
let mut list: Vec<&str> = Vec::new();
let _add = |el: &str| {
list.push(el); // error: `el` escapes the closure body here
};
```
A type anotation of a closure parameter implies a new lifetime declaration.
Consider to drop it, the compiler is reliably able to infer them.
```
let mut list: Vec<&str> = Vec::new();
let _add = |el| {
list.push(el);
};
```
See the [Closure type inference and annotation][closure-infere-annotation] and
[Lifetime elision][lifetime-elision] sections of the Book for more details.
[closure-infere-annotation]: https://doc.rust-lang.org/book/ch13-01-closures.html#closure-type-inference-and-annotation
[lifetime-elision]: https://doc.rust-lang.org/reference/lifetime-elision.html

View File

@ -26,4 +26,5 @@ LL | foo(|| self.bar()).await;
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0373`.
Some errors have detailed explanations: E0373, E0521.
For more information about an error, try `rustc --explain E0373`.

View File

@ -10,3 +10,4 @@ LL | give_any(|y| x = Some(y));
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -12,3 +12,4 @@ LL | lines_to_use.push(installed_id);
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -10,3 +10,4 @@ LL | with_int(|y| x = Some(y));
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -10,3 +10,4 @@ LL | with_int(|y| x = Some(y));
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -10,3 +10,4 @@ LL | with_int(&mut |y| x = Some(y));
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -20,3 +20,4 @@ LL | f = Some(x);
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0521`.

View File

@ -12,3 +12,4 @@ LL | a = &b;
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -10,3 +10,4 @@ LL | static_val(x);
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -8,3 +8,4 @@ LL | self.a();
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -8,3 +8,4 @@ LL | self.foo();
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -22,3 +22,4 @@ LL | lib::ref_obj(x)
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0521`.

View File

@ -83,4 +83,5 @@ LL | }
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.
Some errors have detailed explanations: E0521, E0597.
For more information about an error, try `rustc --explain E0521`.

View File

@ -51,3 +51,4 @@ LL | | });
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -51,3 +51,4 @@ LL | | });
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -106,3 +106,4 @@ LL | Bar2::new(&self)
error: aborting due to 9 previous errors
For more information about this error, try `rustc --explain E0521`.

View File

@ -38,3 +38,4 @@ LL | b(x);
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0521`.

View File

@ -23,3 +23,4 @@ LL | load0(ss)
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0521`.

View File

@ -8,3 +8,4 @@ LL | let f = |x: &dyn TT| x.func();
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -11,3 +11,4 @@ LL | x.unwrap()
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -13,3 +13,4 @@ LL | f.method(b);
error: aborting due to previous error
For more information about this error, try `rustc --explain E0521`.

View File

@ -50,4 +50,5 @@ LL | if false { return x; }
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0597`.
Some errors have detailed explanations: E0521, E0597.
For more information about an error, try `rustc --explain E0521`.

View File

@ -40,3 +40,4 @@ LL | MyTrait::use_self(val)
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0521`.