fix GeneratorWitness: Clone check

This commit is contained in:
Andrew Cann 2022-03-18 14:24:54 +08:00 committed by Charles Lew
parent a5cb3cca5e
commit c1f1bc6e8f

View File

@ -1958,19 +1958,24 @@ fn copy_clone_conditions(
}
ty::GeneratorWitness(binder) => {
let tys = self.tcx().erase_late_bound_regions(binder);
let mut iter = tys.iter();
let witness_tys = binder.skip_binder();
let mut iter = witness_tys.iter();
loop {
let ty = match iter.next() {
Some(ty) => ty,
Option::None => {
break Where(obligation.predicate.rebind(tys.to_vec()))
},
};
let resolved = self.infcx.shallow_resolve(ty);
match iter.next() {
Some(witness_ty) => {
let resolved = self.infcx.shallow_resolve(witness_ty);
if matches!(resolved.kind(), ty::Infer(ty::TyVar(_))) {
break Ambiguous;
}
},
Option::None => {
// (*) binder moved here
let all_vars = self.tcx().mk_bound_variable_kinds(
obligation.predicate.bound_vars().iter().chain(binder.bound_vars().iter())
);
break Where(ty::Binder::bind_with_vars(witness_tys.to_vec(), all_vars));
},
}
}
}