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 'static lifetime suggestion when GAT implied 'static requirement from HRTB #106747

Merged
merged 1 commit into from
Jan 18, 2023

Conversation

yanchen4791
Copy link
Contributor

Fix for issue #105507

The problem:
When generic associated types (GATs) are from higher-ranked trait bounds (HRTB), they are implied 'static requirement (see
Implied 'static requirement from higher-ranked trait bounds for more details). If the user did not explicitly specify the 'static lifetime when using the GAT, the current error message will only point out the type does not live long enough where the type is used, but not where the GAT is specified and how to fix the problem.

The solution:
Add notes at the span where the problematic GATs are specified and suggestions of how to fix the problem by adding 'static lifetime at the right spans.

@rustbot
Copy link
Collaborator

rustbot commented Jan 11, 2023

r? @petrochenkov

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 11, 2023
@yanchen4791
Copy link
Contributor Author

r? @estebank Need to change existing src/test/ui/generic-associated-types/collectivity-regression.stderr in order to pass the tests. But I seemed not having write access the to file (see the message above). How to fix the problem?

@compiler-errors
Copy link
Member

@yanchen please rebase onto current master and move the test from ./src/test/ui to the new directory ./tests/ui

@yanchen4791 yanchen4791 force-pushed the issue-105507-fix branch 2 times, most recently from ee8c86d to 9a90b5a Compare January 12, 2023 02:49
None
}
})
.collect::<Vec<_>>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Seeing that you're only using it once afterwards, I don't think you need to collect this first, right? It can remain an iterator. Collecting has a marginal perf cost, but we can avoid it with confidence thanks to the type ownership system :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, agreed. The reason for keeping the code this way I thought was for more readability and ease of debugging.

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 17, 2023

📌 Commit aadd58e has been approved by estebank

It is now in the queue for this repository.

@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 17, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 18, 2023
…tebank

Add 'static lifetime suggestion when GAT implied 'static requirement from HRTB

Fix for issue rust-lang#105507

The problem:
When generic associated types (GATs) are from higher-ranked trait bounds (HRTB), they are implied 'static requirement (see
[Implied 'static requirement from higher-ranked trait bounds](https://blog.rust-lang.org/2022/10/28/gats-stabilization.html#implied-static-requirement-from-higher-ranked-trait-bounds) for more details). If the user did not explicitly specify the `'static` lifetime when using the GAT, the current error message will only point out the type `does not live long enough` where the type is used, but not where the GAT is specified and how to fix the problem.

The solution:
Add notes at the span where the problematic GATs are specified and suggestions of how to fix the problem by adding `'static` lifetime at the right spans.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 18, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#106244 (Improve Markdown styling in README)
 - rust-lang#106747 (Add 'static lifetime suggestion when GAT implied 'static requirement from HRTB)
 - rust-lang#106873 (dont randomly use `_` to print out const generic arguments)
 - rust-lang#106992 (Remove unused `#![feature(box_syntax)]` in `alloc`)
 - rust-lang#106995 (bump failing assembly & codegen tests from LLVM 14 to LLVM 15)
 - rust-lang#106996 (rustdoc: instead of `.setting-name { width: 100% }`, use default div CSS)
 - rust-lang#106997 (Add heapsort fallback in `select_nth_unstable`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d26e07b into rust-lang:master Jan 18, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 18, 2023
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants