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

Account for multiple impl/dyn Trait in return type when suggesting '_ #73496

Merged
merged 2 commits into from
Jun 23, 2020

Conversation

estebank
Copy link
Contributor

Make impl and dyn Trait lifetime suggestions a bit more resilient.

Follow up to #72804.

r? @nikomatsakis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 19, 2020
Comment on lines +26 to +45
error[E0759]: cannot infer an appropriate lifetime
--> $DIR/trait-object-nested-in-impl-trait.rs:41:31
|
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ {
| ----- this data with an anonymous lifetime `'_`...
...
LL | remaining: self.0.iter(),
| ------ ^^^^
| |
| ...is captured here...
|
note: ...and is required to live as long as `'static` here
--> $DIR/trait-object-nested-in-impl-trait.rs:38:23
|
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo>> + '_ {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to declare that the trait object captures data from argument `self`, you can add an explicit `'_` lifetime bound
|
LL | fn iter(&self) -> impl Iterator<Item = Box<dyn Foo + '_>> + '_ {
| ^^^^
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the main case I wanted to tackle in this PR. Avoiding giving an incorrect suggestion for '_ which is already present, and identifying that there are other places where '_ might be needed, in this case dyn Foo + '_.

@rust-highfive

This comment has been minimized.

@nikomatsakis
Copy link
Contributor

r=me after nits fixed

@estebank
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 23, 2020

📌 Commit 3eb8eb9 has been approved by nikomatsakis

@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 Jun 23, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 23, 2020
…arth

Rollup of 9 pull requests

Successful merges:

 - rust-lang#72271 (Improve compiler error message for wrong generic parameter order)
 - rust-lang#72493 ( move leak-check to during coherence, candidate eval)
 - rust-lang#73398 (A way forward for pointer equality in const eval)
 - rust-lang#73472 (Clean up E0689 explanation)
 - rust-lang#73496 (Account for multiple impl/dyn Trait in return type when suggesting `'_`)
 - rust-lang#73515 (Add second message for LiveDrop errors)
 - rust-lang#73567 (Clarify --extern documentation.)
 - rust-lang#73572 (Fix typos in doc comments)
 - rust-lang#73590 (bootstrap: no `config.toml` exists regression)

Failed merges:

r? @ghost
@bors bors merged commit cd18ac1 into rust-lang:master Jun 23, 2020
@cuviper cuviper added this to the 1.46 milestone May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants