@@ -12,7 +12,8 @@ use super::SelectionContext;
12
12
use super :: SelectionError ;
13
13
use super :: {
14
14
ImplSourceClosureData , ImplSourceDiscriminantKindData , ImplSourceFnPointerData ,
15
- ImplSourceGeneratorData , ImplSourcePointeeData , ImplSourceUserDefinedData ,
15
+ ImplSourceFutureData , ImplSourceGeneratorData , ImplSourcePointeeData ,
16
+ ImplSourceUserDefinedData ,
16
17
} ;
17
18
use super :: { Normalized , NormalizedTy , ProjectionCacheEntry , ProjectionCacheKey } ;
18
19
@@ -1556,6 +1557,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
1556
1557
let eligible = match & impl_source {
1557
1558
super :: ImplSource :: Closure ( _)
1558
1559
| super :: ImplSource :: Generator ( _)
1560
+ | super :: ImplSource :: Future ( _)
1559
1561
| super :: ImplSource :: FnPointer ( _)
1560
1562
| super :: ImplSource :: TraitAlias ( _) => true ,
1561
1563
super :: ImplSource :: UserDefined ( impl_data) => {
@@ -1844,6 +1846,7 @@ fn confirm_select_candidate<'cx, 'tcx>(
1844
1846
match impl_source {
1845
1847
super :: ImplSource :: UserDefined ( data) => confirm_impl_candidate ( selcx, obligation, data) ,
1846
1848
super :: ImplSource :: Generator ( data) => confirm_generator_candidate ( selcx, obligation, data) ,
1849
+ super :: ImplSource :: Future ( data) => confirm_future_candidate ( selcx, obligation, data) ,
1847
1850
super :: ImplSource :: Closure ( data) => confirm_closure_candidate ( selcx, obligation, data) ,
1848
1851
super :: ImplSource :: FnPointer ( data) => confirm_fn_pointer_candidate ( selcx, obligation, data) ,
1849
1852
super :: ImplSource :: DiscriminantKind ( data) => {
@@ -1884,55 +1887,75 @@ fn confirm_generator_candidate<'cx, 'tcx>(
1884
1887
debug ! ( ?obligation, ?gen_sig, ?obligations, "confirm_generator_candidate" ) ;
1885
1888
1886
1889
let tcx = selcx. tcx ( ) ;
1890
+ let gen_def_id = tcx. require_lang_item ( LangItem :: Generator , None ) ;
1887
1891
1888
- let predicate = if impl_source. is_async {
1889
- let fut_def_id = tcx. require_lang_item ( LangItem :: Future , None ) ;
1890
-
1891
- // FIXME(swatinem): this is just copy-pasted from `generator_trait_ref_and_outputs` for now
1892
- let self_ty = obligation. predicate . self_ty ( ) ;
1893
- debug_assert ! ( !self_ty. has_escaping_bound_vars( ) ) ;
1894
- let trait_ref =
1895
- ty:: TraitRef { def_id : fut_def_id, substs : tcx. mk_substs_trait ( self_ty, & [ ] ) } ;
1896
- gen_sig. map_bound ( |sig| ( trait_ref, sig. return_ty ) ) . map_bound ( |( trait_ref, return_ty) | {
1897
- let name = tcx. associated_item ( obligation. predicate . item_def_id ) . name ;
1898
- let ty = if name == sym:: Output { return_ty } else { bug ! ( ) } ;
1899
-
1900
- ty:: ProjectionPredicate {
1901
- projection_ty : ty:: ProjectionTy {
1902
- substs : trait_ref. substs ,
1903
- item_def_id : obligation. predicate . item_def_id ,
1904
- } ,
1905
- term : ty. into ( ) ,
1906
- }
1907
- } )
1908
- } else {
1909
- let gen_def_id = tcx. require_lang_item ( LangItem :: Generator , None ) ;
1892
+ let predicate = super :: util:: generator_trait_ref_and_outputs (
1893
+ tcx,
1894
+ gen_def_id,
1895
+ obligation. predicate . self_ty ( ) ,
1896
+ gen_sig,
1897
+ )
1898
+ . map_bound ( |( trait_ref, yield_ty, return_ty) | {
1899
+ let name = tcx. associated_item ( obligation. predicate . item_def_id ) . name ;
1900
+ let ty = if name == sym:: Return {
1901
+ return_ty
1902
+ } else if name == sym:: Yield {
1903
+ yield_ty
1904
+ } else {
1905
+ bug ! ( )
1906
+ } ;
1910
1907
1911
- super :: util:: generator_trait_ref_and_outputs (
1912
- tcx,
1913
- gen_def_id,
1914
- obligation. predicate . self_ty ( ) ,
1915
- gen_sig,
1916
- )
1917
- . map_bound ( |( trait_ref, yield_ty, return_ty) | {
1918
- let name = tcx. associated_item ( obligation. predicate . item_def_id ) . name ;
1919
- let ty = if name == sym:: Return {
1920
- return_ty
1921
- } else if name == sym:: Yield {
1922
- yield_ty
1923
- } else {
1924
- bug ! ( )
1925
- } ;
1908
+ ty:: ProjectionPredicate {
1909
+ projection_ty : ty:: ProjectionTy {
1910
+ substs : trait_ref. substs ,
1911
+ item_def_id : obligation. predicate . item_def_id ,
1912
+ } ,
1913
+ term : ty. into ( ) ,
1914
+ }
1915
+ } ) ;
1926
1916
1927
- ty:: ProjectionPredicate {
1928
- projection_ty : ty:: ProjectionTy {
1929
- substs : trait_ref. substs ,
1930
- item_def_id : obligation. predicate . item_def_id ,
1931
- } ,
1932
- term : ty. into ( ) ,
1933
- }
1934
- } )
1935
- } ;
1917
+ confirm_param_env_candidate ( selcx, obligation, predicate, false )
1918
+ . with_addl_obligations ( impl_source. nested )
1919
+ . with_addl_obligations ( obligations)
1920
+ }
1921
+
1922
+ fn confirm_future_candidate < ' cx , ' tcx > (
1923
+ selcx : & mut SelectionContext < ' cx , ' tcx > ,
1924
+ obligation : & ProjectionTyObligation < ' tcx > ,
1925
+ impl_source : ImplSourceFutureData < ' tcx , PredicateObligation < ' tcx > > ,
1926
+ ) -> Progress < ' tcx > {
1927
+ let gen_sig = impl_source. substs . as_generator ( ) . poly_sig ( ) ;
1928
+ let Normalized { value : gen_sig, obligations } = normalize_with_depth (
1929
+ selcx,
1930
+ obligation. param_env ,
1931
+ obligation. cause . clone ( ) ,
1932
+ obligation. recursion_depth + 1 ,
1933
+ gen_sig,
1934
+ ) ;
1935
+
1936
+ debug ! ( ?obligation, ?gen_sig, ?obligations, "confirm_future_candidate" ) ;
1937
+
1938
+ let tcx = selcx. tcx ( ) ;
1939
+ let fut_def_id = tcx. require_lang_item ( LangItem :: Future , None ) ;
1940
+
1941
+ let predicate = super :: util:: future_trait_ref_and_outputs (
1942
+ tcx,
1943
+ fut_def_id,
1944
+ obligation. predicate . self_ty ( ) ,
1945
+ gen_sig,
1946
+ )
1947
+ . map_bound ( |( trait_ref, return_ty) | {
1948
+ let name = tcx. associated_item ( obligation. predicate . item_def_id ) . name ;
1949
+ let ty = if name == sym:: Output { return_ty } else { bug ! ( ) } ;
1950
+
1951
+ ty:: ProjectionPredicate {
1952
+ projection_ty : ty:: ProjectionTy {
1953
+ substs : trait_ref. substs ,
1954
+ item_def_id : obligation. predicate . item_def_id ,
1955
+ } ,
1956
+ term : ty. into ( ) ,
1957
+ }
1958
+ } ) ;
1936
1959
1937
1960
confirm_param_env_candidate ( selcx, obligation, predicate, false )
1938
1961
. with_addl_obligations ( impl_source. nested )
0 commit comments