diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index c669f7fed272..9ce74dd9b5a7 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 000000000000..65dcac983acd --- /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 diff --git a/src/test/ui/async-await/issues/issue-62097.nll.stderr b/src/test/ui/async-await/issues/issue-62097.nll.stderr index 2a399540e529..ab10e5f1810b 100644 --- a/src/test/ui/async-await/issues/issue-62097.nll.stderr +++ b/src/test/ui/async-await/issues/issue-62097.nll.stderr @@ -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`. diff --git a/src/test/ui/borrowck/issue-45983.stderr b/src/test/ui/borrowck/issue-45983.stderr index efd414a2d44f..feb098c59858 100644 --- a/src/test/ui/borrowck/issue-45983.stderr +++ b/src/test/ui/borrowck/issue-45983.stderr @@ -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`. diff --git a/src/test/ui/borrowck/issue-7573.stderr b/src/test/ui/borrowck/issue-7573.stderr index 815419db833e..9d86286b8676 100644 --- a/src/test/ui/borrowck/issue-7573.stderr +++ b/src/test/ui/borrowck/issue-7573.stderr @@ -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`. diff --git a/src/test/ui/borrowck/regions-escape-bound-fn-2.stderr b/src/test/ui/borrowck/regions-escape-bound-fn-2.stderr index 1dc60bb15545..14393bc8eeed 100644 --- a/src/test/ui/borrowck/regions-escape-bound-fn-2.stderr +++ b/src/test/ui/borrowck/regions-escape-bound-fn-2.stderr @@ -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`. diff --git a/src/test/ui/borrowck/regions-escape-bound-fn.stderr b/src/test/ui/borrowck/regions-escape-bound-fn.stderr index 5c548ec2876a..a23fdacdee64 100644 --- a/src/test/ui/borrowck/regions-escape-bound-fn.stderr +++ b/src/test/ui/borrowck/regions-escape-bound-fn.stderr @@ -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`. diff --git a/src/test/ui/borrowck/regions-escape-unboxed-closure.stderr b/src/test/ui/borrowck/regions-escape-unboxed-closure.stderr index f2a49e70d271..153f77c8913a 100644 --- a/src/test/ui/borrowck/regions-escape-unboxed-closure.stderr +++ b/src/test/ui/borrowck/regions-escape-unboxed-closure.stderr @@ -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`. diff --git a/src/test/ui/closures/closure-expected-type/expect-region-supply-region.stderr b/src/test/ui/closures/closure-expected-type/expect-region-supply-region.stderr index 213071abfffc..0d97fa7e2301 100644 --- a/src/test/ui/closures/closure-expected-type/expect-region-supply-region.stderr +++ b/src/test/ui/closures/closure-expected-type/expect-region-supply-region.stderr @@ -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`. diff --git a/src/test/ui/generator/ref-escapes-but-not-over-yield.stderr b/src/test/ui/generator/ref-escapes-but-not-over-yield.stderr index 9986220218e2..5fc810040982 100644 --- a/src/test/ui/generator/ref-escapes-but-not-over-yield.stderr +++ b/src/test/ui/generator/ref-escapes-but-not-over-yield.stderr @@ -12,3 +12,4 @@ LL | a = &b; error: aborting due to previous error +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr b/src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr index 8e660d6814c4..d72435bc6311 100644 --- a/src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr +++ b/src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr @@ -10,3 +10,4 @@ LL | static_val(x); error: aborting due to previous error +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/issues/issue-16683.nll.stderr b/src/test/ui/issues/issue-16683.nll.stderr index b82b0b552e2d..51d86eaf9e60 100644 --- a/src/test/ui/issues/issue-16683.nll.stderr +++ b/src/test/ui/issues/issue-16683.nll.stderr @@ -8,3 +8,4 @@ LL | self.a(); error: aborting due to previous error +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/issues/issue-17758.nll.stderr b/src/test/ui/issues/issue-17758.nll.stderr index 23557b4d956a..075c141ed7af 100644 --- a/src/test/ui/issues/issue-17758.nll.stderr +++ b/src/test/ui/issues/issue-17758.nll.stderr @@ -8,3 +8,4 @@ LL | self.foo(); error: aborting due to previous error +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr b/src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr index 60420973e1ee..57dab46df6b6 100644 --- a/src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr +++ b/src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr @@ -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`. diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index 0115f5412f21..0932f9415480 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -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`. diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index e55d033d2c76..bf6e2a922ed0 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -51,3 +51,4 @@ LL | | }); error: aborting due to previous error +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index ac4a4579c9cd..a3d993848cba 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -51,3 +51,4 @@ LL | | }); error: aborting due to previous error +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/nll/outlives-suggestion-simple.stderr b/src/test/ui/nll/outlives-suggestion-simple.stderr index 6300ea66511f..bfe98a71a99b 100644 --- a/src/test/ui/nll/outlives-suggestion-simple.stderr +++ b/src/test/ui/nll/outlives-suggestion-simple.stderr @@ -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`. diff --git a/src/test/ui/nll/user-annotations/closure-substs.stderr b/src/test/ui/nll/user-annotations/closure-substs.stderr index e3e294106d16..37e751aeb67b 100644 --- a/src/test/ui/nll/user-annotations/closure-substs.stderr +++ b/src/test/ui/nll/user-annotations/closure-substs.stderr @@ -38,3 +38,4 @@ LL | b(x); error: aborting due to 4 previous errors +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr b/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr index d871eb5327d2..42dae7e40dbb 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr @@ -23,3 +23,4 @@ LL | load0(ss) error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/regions/issue-78262.nll.stderr b/src/test/ui/regions/issue-78262.nll.stderr index 4607dbad4220..fafff35e4155 100644 --- a/src/test/ui/regions/issue-78262.nll.stderr +++ b/src/test/ui/regions/issue-78262.nll.stderr @@ -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`. diff --git a/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr b/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr index d941030d8247..89a22adc8f02 100644 --- a/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr +++ b/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr @@ -11,3 +11,4 @@ LL | x.unwrap() error: aborting due to previous error +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr b/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr index 92a3942c916b..ed7b17c207c3 100644 --- a/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr +++ b/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr @@ -13,3 +13,4 @@ LL | f.method(b); error: aborting due to previous error +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/regions/regions-nested-fns.nll.stderr b/src/test/ui/regions/regions-nested-fns.nll.stderr index 9d966486f98d..60754f4c2284 100644 --- a/src/test/ui/regions/regions-nested-fns.nll.stderr +++ b/src/test/ui/regions/regions-nested-fns.nll.stderr @@ -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`. diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr index 697467dc3a63..6c235ae8f027 100644 --- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr +++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr @@ -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`.