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

Tweak lifetime definition errors #68267

Merged
merged 6 commits into from
Jan 21, 2020
Merged

Tweak lifetime definition errors #68267

merged 6 commits into from
Jan 21, 2020

Conversation

estebank
Copy link
Contributor

Taking inspiration from the narrative in @fasterthanlime's https://fasterthanli.me/blog/2019/declarative-memory-management/, add suggestions to some lifetime definition errors.

@rust-highfive
Copy link
Collaborator

r? @cramertj

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 16, 2020
@cramertj
Copy link
Member

r? @Centril

@rust-highfive rust-highfive assigned Centril and unassigned cramertj Jan 16, 2020
@Centril
Copy link
Contributor

Centril commented Jan 16, 2020

r? @petrochenkov

src/librustc_resolve/lifetimes.rs Outdated Show resolved Hide resolved
src/librustc_resolve/lifetimes.rs Outdated Show resolved Hide resolved
@rust-highfive

This comment has been minimized.

@estebank

This comment has been minimized.

@bors

This comment has been minimized.

src/librustc_resolve/lifetimes.rs Outdated Show resolved Hide resolved
src/librustc_resolve/lifetimes.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 19, 2020
This doesn't mention that using an existing lifetime is possible, but
that would hopefully be clear as always being an option. The intention
of this is to teach newcomers what the lifetime syntax is.
@rust-highfive

This comment has been minimized.

@estebank estebank removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 20, 2020
@estebank estebank added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 20, 2020
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 20, 2020

📌 Commit 03d7fed has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 20, 2020
@bors
Copy link
Contributor

bors commented Jan 21, 2020

⌛ Testing commit 03d7fed with merge ce361fb...

bors added a commit that referenced this pull request Jan 21, 2020
Tweak lifetime definition errors

Taking inspiration from the narrative in @fasterthanlime's https://fasterthanli.me/blog/2019/declarative-memory-management/, add suggestions to some lifetime definition errors.
@bors
Copy link
Contributor

bors commented Jan 21, 2020

☀️ Test successful - checks-azure
Approved by: petrochenkov
Pushing ce361fb to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 21, 2020
@bors bors merged commit 03d7fed into rust-lang:master Jan 21, 2020
help: consider introducing a named lifetime parameter
|
LL | struct Foo<'lifetime> {
LL | x: &'lifetime bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this use 'a instead of 'lifetime, to be more realistic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could, but we are also targeting people who might be just picking Rust up with these messages who might not know the meaning of 'a to begin with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nicer to say that 'a is a lifetime somewhere in the diagnostic, than risk people copy-pasting the 'lifetime example literally into their code and getting the wrong impression that it's a convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#68583 tackles this

Centril added a commit to Centril/rust that referenced this pull request Feb 5, 2020
Account for HR lifetimes when suggesting introduction of named lifetime

```
error[E0106]: missing lifetime specifier
 --> src/test/ui/suggestions/fn-missing-lifetime-in-item.rs:2:32
  |
2 | struct S2<F: Fn(&i32, &i32) -> &i32>(F);
  |                 ----  ----     ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from argument 1 or argument 2
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
2 | struct S2<F: for<'a> Fn(&'a i32, &'a i32) -> &'a i32>(F);
  |              ^^^^^^^    ^^^^^^^  ^^^^^^^     ^^^
help: consider introducing a named lifetime parameter
  |
2 | struct S2<'a, F: Fn(&'a i32, &'a i32) -> &'a i32>(F);=
  |           ^^^       ^^^^^^^  ^^^^^^^     ^^^
```

Follow up to rust-lang#68267. Addresses the diagnostics part of rust-lang#49287.
bors added a commit that referenced this pull request Feb 6, 2020
Account for HR lifetimes when suggesting introduction of named lifetime

```
error[E0106]: missing lifetime specifier
 --> src/test/ui/suggestions/fn-missing-lifetime-in-item.rs:2:32
  |
2 | struct S2<F: Fn(&i32, &i32) -> &i32>(F);
  |                 ----  ----     ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from argument 1 or argument 2
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
2 | struct S2<F: for<'a> Fn(&'a i32, &'a i32) -> &'a i32>(F);
  |              ^^^^^^^    ^^^^^^^  ^^^^^^^     ^^^
help: consider introducing a named lifetime parameter
  |
2 | struct S2<'a, F: Fn(&'a i32, &'a i32) -> &'a i32>(F);=
  |           ^^^       ^^^^^^^  ^^^^^^^     ^^^
```

Follow up to #68267. Addresses the diagnostics part of #49287.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants