Skip to content

Commit e0ef776

Browse files
committed
Add long error explanation for E0697
1 parent 321ccbe commit e0ef776

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc/error_codes.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,24 @@ a (non-transparent) struct containing a single float, while `Grams` is a
20012001
transparent wrapper around a float. This can make a difference for the ABI.
20022002
"##,
20032003

2004+
E0697: r##"
2005+
A closure has been used as `static`.
2006+
2007+
Erroneous code example:
2008+
2009+
```compile_fail,E0697
2010+
fn main() {
2011+
static || {}; // used as `static`
2012+
}
2013+
```
2014+
2015+
Closures cannot be used as `static`. They "save" the environment.
2016+
Therefore, having a static closure with a static environment doesn't
2017+
really make sense since all you can capture inside it would be variables
2018+
with static lifetime. In this condition, better use a function directly.
2019+
The easiest fix is to remove `static` keyword.
2020+
"##,
2021+
20042022
E0698: r##"
20052023
When using generators (or async) all type variables must be bound so a
20062024
generator can be constructed.
@@ -2187,7 +2205,6 @@ See [RFC 2091] for details on this and other limitations.
21872205
E0657, // `impl Trait` can only capture lifetimes bound at the fn level
21882206
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
21892207
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
2190-
E0697, // closures cannot be static
21912208
// E0707, // multiple elided lifetimes used in arguments of `async fn`
21922209
E0708, // `async` non-`move` closures with parameters are not currently
21932210
// supported

src/test/ui/static/static-closures.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | static || {};
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0697`.

0 commit comments

Comments
 (0)