Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error code explanation for E0477 #67723

Merged
merged 2 commits into from
Dec 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ E0463: include_str!("./error_codes/E0463.md"),
E0466: include_str!("./error_codes/E0466.md"),
E0468: include_str!("./error_codes/E0468.md"),
E0469: include_str!("./error_codes/E0469.md"),
E0477: include_str!("./error_codes/E0477.md"),
E0478: include_str!("./error_codes/E0478.md"),
E0491: include_str!("./error_codes/E0491.md"),
E0492: include_str!("./error_codes/E0492.md"),
Expand Down Expand Up @@ -531,7 +532,6 @@ E0745: include_str!("./error_codes/E0745.md"),
E0474, // captured variable `..` does not outlive the enclosing closure
E0475, // index of slice outside its lifetime
E0476, // lifetime of the source pointer does not outlive lifetime bound...
E0477, // the type `..` does not fulfill the required lifetime...
E0479, // the type `..` (provided as the value of a type parameter) is...
E0480, // lifetime of method receiver does not outlive the method call
E0481, // lifetime of function argument does not outlive the function call
Expand Down
45 changes: 45 additions & 0 deletions src/librustc_error_codes/error_codes/E0477.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
The type does not fulfill the required lifetime.

Erroneous code example:

```compile_fail,E0477
use std::sync::Mutex;

struct MyString<'a> {
data: &'a str,
}

fn i_want_static_closure<F>(a: F)
where F: Fn() + 'static {}

fn print_string<'a>(s: Mutex<MyString<'a>>) {

i_want_static_closure(move || { // error: this closure has lifetime 'a
// rather than 'static
println!("{}", s.lock().unwrap().data);
});
}
```

In this example, the closure doesn't satisfy the `'static` lifetime constraint.
ldm0 marked this conversation as resolved.
Show resolved Hide resolved
To fix this kind of error, you need to double check lifetime of the type. Here,
ldm0 marked this conversation as resolved.
Show resolved Hide resolved
we can fix this problem by giving `s` a static lifetime:

```
use std::sync::Mutex;

struct MyString<'a> {
data: &'a str,
}

fn i_want_static_closure<F>(a: F)
where F: Fn() + 'static {}

fn print_string(s: Mutex<MyString<'static>>) {

i_want_static_closure(move || { // error: this closure has lifetime 'a
// rather than 'static
println!("{}", s.lock().unwrap().data);
});
}
```
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-26217.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | foo::<&'a i32>();

error: aborting due to previous error

For more information about this error, try `rustc --explain E0477`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-54943.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | let x = foo::<&'a u32>();

error: aborting due to previous error

For more information about this error, try `rustc --explain E0477`.
3 changes: 2 additions & 1 deletion src/test/ui/kindck/kindck-impl-type-params.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ LL | let a: Box<dyn Gettable<Foo>> = t;

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0277`.
Some errors have detailed explanations: E0277, E0477.
For more information about an error, try `rustc --explain E0277`.
3 changes: 2 additions & 1 deletion src/test/ui/kindck/kindck-send-object1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ LL | assert_send::<Box<dyn Dummy + 'a>>();

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0277`.
Some errors have detailed explanations: E0277, E0477.
For more information about an error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ LL | assert_send::<*mut &'a isize>();

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0477`.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | Foo.some_method::<&'a isize>();

error: aborting due to previous error

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