Skip to content

Commit

Permalink
Rollup merge of rust-lang#81634 - jesusprubio:jesusprubio/add-long-ex…
Browse files Browse the repository at this point in the history
…planation-e0521, r=GuillaumeGomez

Add long explanation e0521

Helps with rust-lang#61137
  • Loading branch information
jackh726 authored Feb 2, 2021
2 parents 4a74152 + c57889b commit 9757be5
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0521.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/test/ui/async-await/issues/issue-62097.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/borrowck/issue-45983.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/borrowck/issue-7573.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/borrowck/regions-escape-bound-fn-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/borrowck/regions-escape-bound-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/borrowck/regions-escape-unboxed-closure.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ LL | a = &b;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0521`.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ LL | static_val(x);

error: aborting due to previous error

For more information about this error, try `rustc --explain E0521`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-16683.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | self.a();

error: aborting due to previous error

For more information about this error, try `rustc --explain E0521`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-17758.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | self.foo();

error: aborting due to previous error

For more information about this error, try `rustc --explain E0521`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ LL | | });

error: aborting due to previous error

For more information about this error, try `rustc --explain E0521`.
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ LL | | });

error: aborting due to previous error

For more information about this error, try `rustc --explain E0521`.
1 change: 1 addition & 0 deletions src/test/ui/nll/outlives-suggestion-simple.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 1 addition & 0 deletions src/test/ui/nll/user-annotations/closure-substs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ LL | b(x);

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0521`.
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ LL | load0(ss)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0521`.
1 change: 1 addition & 0 deletions src/test/ui/regions/issue-78262.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ LL | x.unwrap()

error: aborting due to previous error

For more information about this error, try `rustc --explain E0521`.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ LL | f.method(b);

error: aborting due to previous error

For more information about this error, try `rustc --explain E0521`.
3 changes: 2 additions & 1 deletion src/test/ui/regions/regions-nested-fns.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

0 comments on commit 9757be5

Please sign in to comment.