forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#132047 - compiler-errors:rbv-rtn-cleanup, r=c…
…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
- Loading branch information
Showing
3 changed files
with
143 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,31 @@ | ||
//@ check-pass | ||
|
||
#![feature(return_type_notation)] | ||
|
||
trait Trait { | ||
fn method(&self) -> impl Sized; | ||
} | ||
|
||
impl Trait for () { | ||
fn method(&self) -> impl Sized {} | ||
} | ||
|
||
struct Struct<T>(T); | ||
|
||
// This test used to fail a debug assertion since we weren't resolving the item | ||
// for `T::method(..)` correctly, leading to two bound vars being given the | ||
// index 0. The solution is to look at both generics of `test` and its parent impl. | ||
|
||
impl<T> Struct<T> | ||
where | ||
T: Trait, | ||
{ | ||
fn test() | ||
where | ||
T::method(..): Send | ||
{} | ||
} | ||
|
||
fn main() { | ||
Struct::<()>::test(); | ||
} |