-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Detect when 'static
obligation might come from an impl
#73783
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
Merged
bors
merged 8 commits into
rust-lang:master
from
estebank:impl-dyn-trait-static-lifetime
Jul 23, 2020
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6513148
Detect when `'static` obligation might come from an `impl`
estebank 4e08bab
Increase accuracy of lifetime bound on trait object impl suggestion
estebank 6bac3db
Add more context to diagnostic
estebank 7bf39fa
Further tweak wording of E0759 and introduce E0767
estebank f807437
Use `ty::Instance::resolve` to identify `'static` bound source
estebank 3712dfc
Partially account for case where used method is from trait
estebank 53d96b5
Handle fully-qualified paths and add test cases
estebank 889a4d9
Change error code number
estebank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Handle fully-qualified paths and add test cases
- Loading branch information
commit 53d96b5159ee4eb937728bbc33c28c3b98ebebd6
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...gestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.nll.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
error[E0597]: `val` does not live long enough | ||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:22:9 | ||
| | ||
LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> { | ||
| -- lifetime `'a` defined here ------------------- opaque type requires that `val` is borrowed for `'a` | ||
LL | val.use_self() | ||
| ^^^ borrowed value does not live long enough | ||
LL | } | ||
| - `val` dropped here while still borrowed | ||
| | ||
help: you can add a bound to the opaque type to make it last less than `'static` and match `'a` | ||
| | ||
LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a { | ||
| ^^^^ | ||
|
||
error[E0515]: cannot return value referencing function parameter `val` | ||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:44:9 | ||
| | ||
LL | val.use_self() | ||
| ---^^^^^^^^^^^ | ||
| | | ||
| returns a value referencing data owned by the current function | ||
| `val` is borrowed here | ||
|
||
error[E0515]: cannot return value referencing function parameter `val` | ||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:110:9 | ||
| | ||
LL | val.use_self() | ||
| ---^^^^^^^^^^^ | ||
| | | ||
| returns a value referencing data owned by the current function | ||
| `val` is borrowed here | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0515, E0597. | ||
For more information about an error, try `rustc --explain E0515`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice for
DiagnosticBuilder
to have a concept of 'ordered diagnostics', as there are lots of other places where this kind of logic would be useful. However, it doesn't have to block this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a proposal around this at some point. I wanted to change the rendering if the diagnostics would not display in source order.