Skip to content

Commit cf24b6b

Browse files
authored
Rollup merge of #67723 - ldm0:E0477, r=Dylan-DPC
Add error code explanation for E0477 Part of #61137
2 parents b223f5b + b4e1fbc commit cf24b6b

8 files changed

+54
-3
lines changed

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ E0463: include_str!("./error_codes/E0463.md"),
238238
E0466: include_str!("./error_codes/E0466.md"),
239239
E0468: include_str!("./error_codes/E0468.md"),
240240
E0469: include_str!("./error_codes/E0469.md"),
241+
E0477: include_str!("./error_codes/E0477.md"),
241242
E0478: include_str!("./error_codes/E0478.md"),
242243
E0491: include_str!("./error_codes/E0491.md"),
243244
E0492: include_str!("./error_codes/E0492.md"),
@@ -531,7 +532,6 @@ E0745: include_str!("./error_codes/E0745.md"),
531532
E0474, // captured variable `..` does not outlive the enclosing closure
532533
E0475, // index of slice outside its lifetime
533534
E0476, // lifetime of the source pointer does not outlive lifetime bound...
534-
E0477, // the type `..` does not fulfill the required lifetime...
535535
E0479, // the type `..` (provided as the value of a type parameter) is...
536536
E0480, // lifetime of method receiver does not outlive the method call
537537
E0481, // lifetime of function argument does not outlive the function call
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
The type does not fulfill the required lifetime.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0477
6+
use std::sync::Mutex;
7+
8+
struct MyString<'a> {
9+
data: &'a str,
10+
}
11+
12+
fn i_want_static_closure<F>(a: F)
13+
where F: Fn() + 'static {}
14+
15+
fn print_string<'a>(s: Mutex<MyString<'a>>) {
16+
17+
i_want_static_closure(move || { // error: this closure has lifetime 'a
18+
// rather than 'static
19+
println!("{}", s.lock().unwrap().data);
20+
});
21+
}
22+
```
23+
24+
In this example, the closure does not satisfy the `'static` lifetime constraint.
25+
To fix this error, you need to double check the lifetime of the type. Here, we
26+
can fix this problem by giving `s` a static lifetime:
27+
28+
```
29+
use std::sync::Mutex;
30+
31+
struct MyString<'a> {
32+
data: &'a str,
33+
}
34+
35+
fn i_want_static_closure<F>(a: F)
36+
where F: Fn() + 'static {}
37+
38+
fn print_string(s: Mutex<MyString<'static>>) {
39+
40+
i_want_static_closure(move || { // error: this closure has lifetime 'a
41+
// rather than 'static
42+
println!("{}", s.lock().unwrap().data);
43+
});
44+
}
45+
```

src/test/ui/issues/issue-26217.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ LL | foo::<&'a i32>();
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0477`.

src/test/ui/issues/issue-54943.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ LL | let x = foo::<&'a u32>();
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0477`.

src/test/ui/kindck/kindck-impl-type-params.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ LL | let a: Box<dyn Gettable<Foo>> = t;
7676

7777
error: aborting due to 7 previous errors
7878

79-
For more information about this error, try `rustc --explain E0277`.
79+
Some errors have detailed explanations: E0277, E0477.
80+
For more information about an error, try `rustc --explain E0277`.

src/test/ui/kindck/kindck-send-object1.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ LL | assert_send::<Box<dyn Dummy + 'a>>();
3333

3434
error: aborting due to 3 previous errors
3535

36-
For more information about this error, try `rustc --explain E0277`.
36+
Some errors have detailed explanations: E0277, E0477.
37+
For more information about an error, try `rustc --explain E0277`.

src/test/ui/regions/regions-bounded-by-trait-requiring-static.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ LL | assert_send::<*mut &'a isize>();
4848

4949
error: aborting due to 6 previous errors
5050

51+
For more information about this error, try `rustc --explain E0477`.

src/test/ui/regions/regions-bounded-method-type-parameters.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ LL | Foo.some_method::<&'a isize>();
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0477`.

0 commit comments

Comments
 (0)