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

E310 uses weird terminology #36700

Closed
hanna-kruppe opened this issue Sep 24, 2016 · 3 comments
Closed

E310 uses weird terminology #36700

hanna-kruppe opened this issue Sep 24, 2016 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@hanna-kruppe
Copy link
Contributor

For context, the message is, in the case of a type parameter T missing a lifetime bound:

error: the parameter type T may not live long enough

The suggestion that follows (adding a lifetime bound to T) is fine, but I've just seen someone confused by the wording of the actual error message. Irrespective of any misconceptions or lack of knowledge that might have factored in that specific person's confusion, this message does seem to use very strange terminology. Types, as opposed to values, don't really live (it's occasionally convenient to make puns about this, but in this case it hurts), and it's not really a question of how long a value of type T lives but rather of lifetime parameters contained in T. Also, "parameter type" looks odd — "type parameter" seems much more common.

I'd suggest something like

error: values of type T may contain data that does not live long enough

The exact wording is just a straw man, I don't think it's optimal.

@pnkfelix pnkfelix added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 24, 2016
@steveklabnik steveklabnik added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2017
@Mark-Simulacrum
Copy link
Member

The note added today improves the situation but the main error message could still be enhanced.

struct Foo<T> {
    foo: &'static T
}
error[E0310]: the parameter type `T` may not live long enough
 --> test.rs:4:5
  |
4 |     foo: &'static T
  |     ^^^^^^^^^^^^^^^
  |
  = help: consider adding an explicit lifetime bound `T: 'static`...
note: ...so that the reference type `&'static T` does not outlive the data it points at
 --> test.rs:4:5
  |
4 |     foo: &'static T
  |     ^^^^^^^^^^^^^^^

error: aborting due to previous error(s)

@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@estebank
Copy link
Contributor

Related: #33652

bors added a commit that referenced this issue Sep 27, 2017
Point at parameter type on E0301

On "the parameter type `T` may not live long enough" error, point to the
parameter type suggesting lifetime bindings:

```
error[E0310]: the parameter type `T` may not live long enough
  --> $DIR/lifetime-doesnt-live-long-enough.rs:28:5
   |
27 | struct Foo<T> {
   |            - help: consider adding an explicit lifetime bound `T: 'static`...
28 |     foo: &'static T
   |     ^^^^^^^^^^^^^^^
   |
note: ...so that the reference type `&'static T` does not outlive the data it points at
  --> $DIR/lifetime-doesnt-live-long-enough.rs:28:5
   |
28 |     foo: &'static T
   |     ^^^^^^^^^^^^^^^
```

Fix #36700.
@hanna-kruppe
Copy link
Contributor Author

I don't think this should have been closed. #44782 is a good improvement of the error message, but did not change the primary message. It still says "the parameter type T may not live long enough" which is bad for reasons described above.

(I can't re-open, could someone with more permissions do that please?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants