@@ -890,7 +890,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
890
890
( pair, r)
891
891
} )
892
892
. unzip ( ) ;
893
+
893
894
self . record_late_bound_vars ( hir_id, binders) ;
895
+
896
+ // If this is an RTN type in the self type, then append those to the binder.
897
+ self . try_append_return_type_notation_params ( hir_id, bounded_ty) ;
898
+
894
899
// Even if there are no lifetimes defined here, we still wrap it in a binder
895
900
// scope. If there happens to be a nested poly trait ref (an error), that
896
901
// will be `Concatenating` anyways, so we don't have to worry about the depth
@@ -1856,6 +1861,110 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
1856
1861
let old_value = self . map . defs . swap_remove ( & lifetime_ref. hir_id ) ;
1857
1862
assert_eq ! ( old_value, Some ( bad_def) ) ;
1858
1863
}
1864
+
1865
+ // TODO:
1866
+ fn try_append_return_type_notation_params (
1867
+ & mut self ,
1868
+ hir_id : HirId ,
1869
+ hir_ty : & ' tcx hir:: Ty < ' tcx > ,
1870
+ ) {
1871
+ let hir:: TyKind :: Path ( qpath) = hir_ty. kind else {
1872
+ // TODO:
1873
+ return ;
1874
+ } ;
1875
+
1876
+ let ( mut bound_vars, item_def_id, item_segment) = match qpath {
1877
+ // TODO:
1878
+ hir:: QPath :: Resolved ( _, path)
1879
+ if let [ .., item_segment] = & path. segments [ ..]
1880
+ && item_segment. args . is_some_and ( |args| {
1881
+ matches ! (
1882
+ args. parenthesized,
1883
+ hir:: GenericArgsParentheses :: ReturnTypeNotation
1884
+ )
1885
+ } ) =>
1886
+ {
1887
+ let Res :: Def ( DefKind :: AssocFn , item_def_id) = path. res else {
1888
+ bug ! ( ) ;
1889
+ } ;
1890
+ ( vec ! [ ] , item_def_id, item_segment)
1891
+ }
1892
+
1893
+ // TODO:
1894
+ hir:: QPath :: TypeRelative ( qself, item_segment)
1895
+ if item_segment. args . is_some_and ( |args| {
1896
+ matches ! ( args. parenthesized, hir:: GenericArgsParentheses :: ReturnTypeNotation )
1897
+ } ) =>
1898
+ {
1899
+ let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , path) ) = qself. kind else {
1900
+ return ;
1901
+ } ;
1902
+
1903
+ match path. res {
1904
+ Res :: Def ( DefKind :: TyParam , _) | Res :: SelfTyParam { trait_ : _ } => {
1905
+ let Some ( generics) = self . tcx . hir_owner_node ( hir_id. owner ) . generics ( )
1906
+ else {
1907
+ return ;
1908
+ } ;
1909
+
1910
+ let one_bound = generics. predicates . iter ( ) . find_map ( |predicate| {
1911
+ let hir:: WherePredicate :: BoundPredicate ( predicate) = predicate else {
1912
+ return None ;
1913
+ } ;
1914
+ let hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , bounded_path) ) =
1915
+ predicate. bounded_ty . kind
1916
+ else {
1917
+ return None ;
1918
+ } ;
1919
+ if bounded_path. res != path. res {
1920
+ return None ;
1921
+ }
1922
+ predicate. bounds . iter ( ) . find_map ( |bound| {
1923
+ let hir:: GenericBound :: Trait ( trait_, _) = bound else {
1924
+ return None ;
1925
+ } ;
1926
+ BoundVarContext :: supertrait_hrtb_vars (
1927
+ self . tcx ,
1928
+ trait_. trait_ref . trait_def_id ( ) ?,
1929
+ item_segment. ident ,
1930
+ ty:: AssocKind :: Fn ,
1931
+ )
1932
+ } )
1933
+ } ) ;
1934
+ let Some ( ( bound_vars, assoc_item) ) = one_bound else {
1935
+ return ;
1936
+ } ;
1937
+ ( bound_vars, assoc_item. def_id , item_segment)
1938
+ }
1939
+ Res :: SelfTyAlias { is_trait_impl : true , .. } => todo ! ( ) ,
1940
+ _ => return ,
1941
+ }
1942
+ }
1943
+
1944
+ _ => return ,
1945
+ } ;
1946
+
1947
+ // TODO:
1948
+ bound_vars. extend ( self . tcx . generics_of ( item_def_id) . own_params . iter ( ) . map ( |param| {
1949
+ match param. kind {
1950
+ ty:: GenericParamDefKind :: Lifetime => ty:: BoundVariableKind :: Region (
1951
+ ty:: BoundRegionKind :: BrNamed ( param. def_id , param. name ) ,
1952
+ ) ,
1953
+ ty:: GenericParamDefKind :: Type { .. } => {
1954
+ ty:: BoundVariableKind :: Ty ( ty:: BoundTyKind :: Param ( param. def_id , param. name ) )
1955
+ }
1956
+ ty:: GenericParamDefKind :: Const { .. } => ty:: BoundVariableKind :: Const ,
1957
+ }
1958
+ } ) ) ;
1959
+ bound_vars. extend ( self . tcx . fn_sig ( item_def_id) . instantiate_identity ( ) . bound_vars ( ) ) ;
1960
+
1961
+ // TODO:
1962
+ let existing_bound_vars = self . map . late_bound_vars . get_mut ( & hir_id) . unwrap ( ) ;
1963
+ let existing_bound_vars_saved = existing_bound_vars. clone ( ) ;
1964
+ existing_bound_vars. extend ( bound_vars) ;
1965
+ // TODO: subtle
1966
+ self . record_late_bound_vars ( item_segment. hir_id , existing_bound_vars_saved) ;
1967
+ }
1859
1968
}
1860
1969
1861
1970
/// Detects late-bound lifetimes and inserts them into
0 commit comments