@@ -1640,9 +1640,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1640
1640
// }
1641
1641
// ```
1642
1642
// and a bound that looks like:
1643
- // `for<'a> T::Trait<'a, x(): for<'b> Other<'b>>`
1643
+ // `for<'a> T::Trait<'a, x(.. ): for<'b> Other<'b>>`
1644
1644
// this is going to expand to something like:
1645
- // `for<'a> for<'r, T > <T as Trait<'a>>::x::<'r, T>::{opaque#0}: for<'b> Other<'b>`.
1645
+ // `for<'a> for<'r> <T as Trait<'a>>::x::<'r, T>::{opaque#0}: for<'b> Other<'b>`.
1646
1646
if constraint. gen_args . parenthesized == hir:: GenericArgsParentheses :: ReturnTypeNotation
1647
1647
{
1648
1648
let bound_vars = if let Some ( type_def_id) = type_def_id
@@ -1853,13 +1853,13 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1853
1853
// For example, given
1854
1854
// ```
1855
1855
// trait Foo {
1856
- // async fn x<'r, T >();
1856
+ // async fn x<'r>();
1857
1857
// }
1858
1858
// ```
1859
1859
// and a bound that looks like:
1860
1860
// `for<'a, 'b> <T as Trait<'a>>::x(): Other<'b>`
1861
1861
// this is going to expand to something like:
1862
- // `for<'a, 'b, 'r, T > <T as Trait<'a>>::x::<'r, T>::{opaque#0}: Other<'b>`.
1862
+ // `for<'a, 'b, 'r> <T as Trait<'a>>::x::<'r, T>::{opaque#0}: Other<'b>`.
1863
1863
//
1864
1864
// We handle this similarly for associated-type-bound style return-type-notation
1865
1865
// in `visit_segment_args`.
@@ -2000,6 +2000,17 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
2000
2000
// the new bound vars. We do this because we need to know how many bound vars
2001
2001
// are present on the binder explicitly (i.e. not return-type-notation vars)
2002
2002
// to do bound var shifting correctly in HIR lowering.
2003
+ //
2004
+ // For example, in `where for<'a> <T as Trait<'a>>::method(..): Other`,
2005
+ // the `late_bound_vars` of the where clause predicate (i.e. this HIR ty's
2006
+ // parent) will include `'a` AND all the early- and late-bound vars of the
2007
+ // method. But when lowering the RTN type, we just want the list of vars
2008
+ // we used to resolve the trait ref. We explicitly stored those back onto
2009
+ // the item segment, since there's no other good place to put them.
2010
+ //
2011
+ // See where these vars are used in `HirTyLowerer::lower_ty_maybe_return_type_notation`.
2012
+ // And this is exercised in:
2013
+ // `tests/ui/associated-type-bounds/return-type-notation/higher-ranked-bound-works.rs`.
2003
2014
let existing_bound_vars = self . map . late_bound_vars . get_mut ( & hir_id) . unwrap ( ) ;
2004
2015
let existing_bound_vars_saved = existing_bound_vars. clone ( ) ;
2005
2016
existing_bound_vars. extend ( bound_vars) ;
0 commit comments