Skip to content

Commit 1ac0028

Browse files
authored
Rollup merge of #65215 - JohnTitor:long-explanation-e0697, r=GuillaumeGomez
Add long error explanation for E0697 Part of #61137 r? @GuillaumeGomez
2 parents 36d4506 + c6cc29d commit 1ac0028

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
@@ -2005,6 +2005,24 @@ a (non-transparent) struct containing a single float, while `Grams` is a
20052005
transparent wrapper around a float. This can make a difference for the ABI.
20062006
"##,
20072007

2008+
E0697: r##"
2009+
A closure has been used as `static`.
2010+
2011+
Erroneous code example:
2012+
2013+
```compile_fail,E0697
2014+
fn main() {
2015+
static || {}; // used as `static`
2016+
}
2017+
```
2018+
2019+
Closures cannot be used as `static`. They "save" the environment,
2020+
and as such a static closure would save only a static environment
2021+
which would consist only of variables with a static lifetime. Given
2022+
this it would be better to use a proper function. The easiest fix
2023+
is to remove the `static` keyword.
2024+
"##,
2025+
20082026
E0698: r##"
20092027
When using generators (or async) all type variables must be bound so a
20102028
generator can be constructed.
@@ -2191,7 +2209,6 @@ See [RFC 2091] for details on this and other limitations.
21912209
E0657, // `impl Trait` can only capture lifetimes bound at the fn level
21922210
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
21932211
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
2194-
E0697, // closures cannot be static
21952212
// E0707, // multiple elided lifetimes used in arguments of `async fn`
21962213
E0708, // `async` non-`move` closures with parameters are not currently
21972214
// 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)