@@ -1938,35 +1938,43 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
19381938 }
19391939
19401940 ty:: Generator ( _, substs, hir:: Movability :: Movable ) => {
1941- let resolved_upvars = self . infcx . shallow_resolve ( substs. as_generator ( ) . tupled_upvars_ty ( ) ) ;
1942- let resolved_witness = self . infcx . shallow_resolve ( substs. as_generator ( ) . witness ( ) ) ;
1943- if {
1944- matches ! ( resolved_upvars. kind( ) , ty:: Infer ( ty:: TyVar ( _) ) ) ||
1945- matches ! ( resolved_witness. kind( ) , ty:: Infer ( ty:: TyVar ( _) ) )
1946- } {
1947- // Not yet resolved.
1948- Ambiguous
1941+ if self . tcx ( ) . features ( ) . generator_clone {
1942+ let resolved_upvars = self . infcx . shallow_resolve ( substs. as_generator ( ) . tupled_upvars_ty ( ) ) ;
1943+ let resolved_witness = self . infcx . shallow_resolve ( substs. as_generator ( ) . witness ( ) ) ;
1944+ if {
1945+ matches ! ( resolved_upvars. kind( ) , ty:: Infer ( ty:: TyVar ( _) ) ) ||
1946+ matches ! ( resolved_witness. kind( ) , ty:: Infer ( ty:: TyVar ( _) ) )
1947+ } {
1948+ // Not yet resolved.
1949+ Ambiguous
1950+ } else {
1951+ let mut all = substs. as_generator ( ) . upvar_tys ( ) . collect :: < Vec < _ > > ( ) ;
1952+ all. push ( substs. as_generator ( ) . witness ( ) ) ;
1953+ Where ( obligation. predicate . rebind ( all) )
1954+ }
19491955 } else {
1950- let mut all = substs. as_generator ( ) . upvar_tys ( ) . collect :: < Vec < _ > > ( ) ;
1951- all. push ( substs. as_generator ( ) . witness ( ) ) ;
1952- Where ( obligation. predicate . rebind ( all) )
1956+ None
19531957 }
19541958 }
19551959
19561960 ty:: GeneratorWitness ( binder) => {
1957- let tys = binder. no_bound_vars ( ) . unwrap ( ) ;
1958- let mut iter = tys. iter ( ) ;
1959- loop {
1960- let ty = match iter. next ( ) {
1961- Some ( ty) => ty,
1962- Option :: None => {
1963- break Where ( obligation. predicate . rebind ( tys. to_vec ( ) ) )
1964- } ,
1965- } ;
1966- let resolved = self . infcx . shallow_resolve ( ty) ;
1967- if matches ! ( resolved. kind( ) , ty:: Infer ( ty:: TyVar ( _) ) ) {
1968- break Ambiguous ;
1969- }
1961+ match binder. no_bound_vars ( ) {
1962+ Some ( tys) => {
1963+ let mut iter = tys. iter ( ) ;
1964+ loop {
1965+ let ty = match iter. next ( ) {
1966+ Some ( ty) => ty,
1967+ Option :: None => {
1968+ break Where ( obligation. predicate . rebind ( tys. to_vec ( ) ) )
1969+ } ,
1970+ } ;
1971+ let resolved = self . infcx . shallow_resolve ( ty) ;
1972+ if matches ! ( resolved. kind( ) , ty:: Infer ( ty:: TyVar ( _) ) ) {
1973+ break Ambiguous ;
1974+ }
1975+ }
1976+ } ,
1977+ Option :: None => None ,
19701978 }
19711979 }
19721980
0 commit comments