-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
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 + '_>> + '_ { | ||
| ^^^^ |
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.
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 + '_
.
This comment has been minimized.
This comment has been minimized.
b483526
to
93770ff
Compare
93770ff
to
562f496
Compare
src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs
Show resolved
Hide resolved
r=me after nits fixed |
@bors r=nikomatsakis |
📌 Commit 3eb8eb9 has been approved by |
…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
Make
impl
anddyn
Trait lifetime suggestions a bit more resilient.Follow up to #72804.
r? @nikomatsakis