From e0ef7767cab847f73e145d3f2eb99aef02c94067 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 9 Oct 2019 01:59:14 +0900 Subject: [PATCH 1/2] Add long error explanation for E0697 --- src/librustc/error_codes.rs | 19 ++++++++++++++++++- src/test/ui/static/static-closures.stderr | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs index e208e25f6ea9d..a4c1afc4f1dac 100644 --- a/src/librustc/error_codes.rs +++ b/src/librustc/error_codes.rs @@ -2001,6 +2001,24 @@ a (non-transparent) struct containing a single float, while `Grams` is a transparent wrapper around a float. This can make a difference for the ABI. "##, +E0697: r##" +A closure has been used as `static`. + +Erroneous code example: + +```compile_fail,E0697 +fn main() { + static || {}; // used as `static` +} +``` + +Closures cannot be used as `static`. They "save" the environment. +Therefore, having a static closure with a static environment doesn't +really make sense since all you can capture inside it would be variables +with static lifetime. In this condition, better use a function directly. +The easiest fix is to remove `static` keyword. +"##, + E0698: r##" When using generators (or async) all type variables must be bound so a generator can be constructed. @@ -2187,7 +2205,6 @@ See [RFC 2091] for details on this and other limitations. E0657, // `impl Trait` can only capture lifetimes bound at the fn level E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders - E0697, // closures cannot be static // E0707, // multiple elided lifetimes used in arguments of `async fn` E0708, // `async` non-`move` closures with parameters are not currently // supported diff --git a/src/test/ui/static/static-closures.stderr b/src/test/ui/static/static-closures.stderr index ced78c03e09d6..99235e26e15e7 100644 --- a/src/test/ui/static/static-closures.stderr +++ b/src/test/ui/static/static-closures.stderr @@ -6,3 +6,4 @@ LL | static || {}; error: aborting due to previous error +For more information about this error, try `rustc --explain E0697`. From c6cc29d8cfa0e2c18cd01861df542e7772ae26a6 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 13 Oct 2019 13:19:40 +0900 Subject: [PATCH 2/2] Apply suggestion --- src/librustc/error_codes.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs index a4c1afc4f1dac..78aa9e79e1017 100644 --- a/src/librustc/error_codes.rs +++ b/src/librustc/error_codes.rs @@ -2012,11 +2012,11 @@ fn main() { } ``` -Closures cannot be used as `static`. They "save" the environment. -Therefore, having a static closure with a static environment doesn't -really make sense since all you can capture inside it would be variables -with static lifetime. In this condition, better use a function directly. -The easiest fix is to remove `static` keyword. +Closures cannot be used as `static`. They "save" the environment, +and as such a static closure would save only a static environment +which would consist only of variables with a static lifetime. Given +this it would be better to use a proper function. The easiest fix +is to remove the `static` keyword. "##, E0698: r##"