-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Robustify and genericize return-type-notation resolution in resolve_bound_vars
#132047
Conversation
if let Some(parent_id) = opt_parent_item { | ||
self.tcx.local_def_id_to_hir_id(parent_id) | ||
} else { | ||
continue; |
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.
just to make sure I'm following the logic correctly ...
On this branch, next_scope
is still None
(right?), and therefore this continue
will end up sending a None
up into the while let Some(current_scope)
condition, which means that this continue
effectively ends up acting like ... a break
?
(But then ... why not just write break
here?)
((Having said that, there's nothing wrong here that I can see. I was just trying to figure out if I misunderstood something and that this would not end up behaving just like a break
would...))
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.
Yeah, it doesn't really matter. I can change it to a break for clarity I guess.
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.
In other methods, we prefer scope
not being an option, and breaking when getting to Root
. Do you mind making this a bit more uniform?
@bors r+ |
…=pnkfelix Robustify and genericize return-type-notation resolution in `resolve_bound_vars` rust-lang#129629 implemented return-type-notation (RTN) in its path form, like `where T::method(..): Bound`. As part of lowering, we must record the late-bound vars for the where clause introduced by the method (namely, its early- and late-bound lifetime arguments, since `where T::method(..)` turns into a higher-ranked where clause over all of the lifetimes according to [RFC 3654](https://rust-lang.github.io/rfcs/3654-return-type-notation.html#converting-to-higher-ranked-trait-bounds)). However, this logic was only looking at the where clauses of the parent item that the `T::method(..)` bound was written on, and not any parent items. This PR generalizes that logic to look at the parent item (i.e. the outer impl or trait) instead and fixes a (debug only) assertion as an effect. This logic is also more general and likely easier to adapt to more interesting (though likely very far off) cases like non-lifetime binder `for<T: Trait> T::method(..): Send` bounds. Tracking: - rust-lang#109417
@bors r- |
fcb40d2
to
5fceae3
Compare
@rustbot ready Could use another review for the commit on top. I forgot that we can have self type bounds not from the supertraits, but from the trait self, like:
The PR simplifies the logic a bit to account for that case. |
Felix said he's gone for a week, so r? compiler |
r? compiler |
if let Some(parent_id) = opt_parent_item { | ||
self.tcx.local_def_id_to_hir_id(parent_id) | ||
} else { | ||
continue; |
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.
In other methods, we prefer scope
not being an option, and breaking when getting to Root
. Do you mind making this a bit more uniform?
if Some(&second_bound) != one_bound.as_ref() { | ||
self.tcx.dcx().span_delayed_bug( | ||
path.span, | ||
"ambiguous resolution for RTN path", |
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.
For my own culture, where should the proper error be emitted?
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 will error when we probe for the bound in astconv (HIR -> middle).
let Some((bound_vars, assoc_item)) = one_bound else { | ||
self.tcx | ||
.dcx() | ||
.span_delayed_bug(path.span, "no resolution for RTN path"); |
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.
Likewise, where should this error?
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.
Likewise, it will error when we probe for the bound in astconv (HIR -> middle).
}, | ||
) | ||
.fuse() | ||
} |
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 wonder how hard it would be to reuse the method probing code we have in rustc_hir_typeck.
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 think it would be pretty difficult to do without inducing cycles, since the lowering code requires lowering trait refs.
5fceae3
to
591ad34
Compare
☔ The latest upstream changes (presumably #132894) made this pull request unmergeable. Please resolve the merge conflicts. |
591ad34
to
0f5759a
Compare
r? @cjgillot, could you perhaps take another look at this? otherwise, please re-roll. |
@bors r+ |
…jgillot Robustify and genericize return-type-notation resolution in `resolve_bound_vars` rust-lang#129629 implemented return-type-notation (RTN) in its path form, like `where T::method(..): Bound`. As part of lowering, we must record the late-bound vars for the where clause introduced by the method (namely, its early- and late-bound lifetime arguments, since `where T::method(..)` turns into a higher-ranked where clause over all of the lifetimes according to [RFC 3654](https://rust-lang.github.io/rfcs/3654-return-type-notation.html#converting-to-higher-ranked-trait-bounds)). However, this logic was only looking at the where clauses of the parent item that the `T::method(..)` bound was written on, and not any parent items. This PR generalizes that logic to look at the parent item (i.e. the outer impl or trait) instead and fixes a (debug only) assertion as an effect. This logic is also more general and likely easier to adapt to more interesting (though likely very far off) cases like non-lifetime binder `for<T: Trait> T::method(..): Send` bounds. Tracking: - rust-lang#109417
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
spurious @bors retry |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#128184 (std: refactor `pthread`-based synchronization) - rust-lang#132047 (Robustify and genericize return-type-notation resolution in `resolve_bound_vars`) - rust-lang#133515 (fix: hurd build, stat64.st_fsid was renamed to st_dev) - rust-lang#133602 (fix: fix codeblocks in `PathBuf` example) - rust-lang#133622 (update link to "C++ Exceptions under the hood" blog) - rust-lang#133660 (Do not create trait object type if missing associated types) - rust-lang#133686 (Add diagnostic item for `std::ops::ControlFlow`) - rust-lang#133689 (Fixed typos by changing `happend` to `happened`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#132047 - compiler-errors:rbv-rtn-cleanup, r=cjgillot Robustify and genericize return-type-notation resolution in `resolve_bound_vars` rust-lang#129629 implemented return-type-notation (RTN) in its path form, like `where T::method(..): Bound`. As part of lowering, we must record the late-bound vars for the where clause introduced by the method (namely, its early- and late-bound lifetime arguments, since `where T::method(..)` turns into a higher-ranked where clause over all of the lifetimes according to [RFC 3654](https://rust-lang.github.io/rfcs/3654-return-type-notation.html#converting-to-higher-ranked-trait-bounds)). However, this logic was only looking at the where clauses of the parent item that the `T::method(..)` bound was written on, and not any parent items. This PR generalizes that logic to look at the parent item (i.e. the outer impl or trait) instead and fixes a (debug only) assertion as an effect. This logic is also more general and likely easier to adapt to more interesting (though likely very far off) cases like non-lifetime binder `for<T: Trait> T::method(..): Send` bounds. Tracking: - rust-lang#109417
#129629 implemented return-type-notation (RTN) in its path form, like
where T::method(..): Bound
. As part of lowering, we must record the late-bound vars for the where clause introduced by the method (namely, its early- and late-bound lifetime arguments, sincewhere T::method(..)
turns into a higher-ranked where clause over all of the lifetimes according to RFC 3654).However, this logic was only looking at the where clauses of the parent item that the
T::method(..)
bound was written on, and not any parent items. This PR generalizes that logic to look at the parent item (i.e. the outer impl or trait) instead and fixes a (debug only) assertion as an effect.This logic is also more general and likely easier to adapt to more interesting (though likely very far off) cases like non-lifetime binder
for<T: Trait> T::method(..): Send
bounds.Tracking: