diff options
| author | bors <bors@rust-lang.org> | 2021-02-02 23:15:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-02 23:15:22 +0000 |
| commit | d95d4f0189e02ac2cd9056a0b39b0d5ab94fe69e (patch) | |
| tree | a90c3339a7ce44551ae29dac4a3b5d5ea554b58c /compiler/rustc_error_codes/src | |
| parent | 368275062fb655c1f36e0398f88b15379a1f3c93 (diff) | |
| parent | 81c64b34330090acf82285c3e9de67f876b3a98b (diff) | |
| download | rust-d95d4f0189e02ac2cd9056a0b39b0d5ab94fe69e.tar.gz rust-d95d4f0189e02ac2cd9056a0b39b0d5ab94fe69e.zip | |
Auto merge of #81678 - jackh726:rollup-3nerni4, r=jackh726
Rollup of 14 pull requests Successful merges: - #80593 (Upgrade Chalk) - #81260 (Add .editorconfig) - #81455 (Add AArch64 big-endian and ILP32 targets) - #81517 (Remove remnants of the santizer runtime crates from bootstrap) - #81530 (sys: use `process::abort()` instead of `arch::wasm32::unreachable()`) - #81544 (Add better diagnostic for unbounded Abst. Const) - #81588 (Add doc aliases for "delete") - #81603 (rustbuild: Don't build compiler twice for error-index-generator.) - #81634 (Add long explanation e0521) - #81636 (Directly use `Option<&[T]>` instead of converting from `Option<&Vec<T>>` later on) - #81647 (Fix bug with assert!() calling the wrong edition of panic!().) - #81655 (Improve wording of suggestion about accessing field) - #81665 (Fix out of date `Scalar` documentation) - #81671 (Add more associated type tests) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0521.md | 28 |
2 files changed, 29 insertions, 1 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index c669f7fed27..9ce74dd9b5a 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -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 diff --git a/compiler/rustc_error_codes/src/error_codes/E0521.md b/compiler/rustc_error_codes/src/error_codes/E0521.md new file mode 100644 index 00000000000..65dcac983ac --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0521.md @@ -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 |
