Always return tupled_upvar_tys for Closure/Generator consituent tys

Depending on if upvar_tys inferred or not, we were returning either an
inference variable which later resolves to a tuple or else the upvar tys
themselves

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
This commit is contained in:
Aman Arora 2020-10-01 21:06:16 -04:00
parent dc183702da
commit 08d1ab0bf1
5 changed files with 9 additions and 20 deletions

View file

@ -1708,29 +1708,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Closure(_, ref substs) => {
let ty = self.infcx.shallow_resolve(substs.as_closure().tupled_upvars_ty());
if let ty::Infer(ty::TyVar(_)) = ty.kind() {
// The inference variable will be replaced by a tuple once capture analysis
// completes. If the tuple meets a bound, so do all the elements within it.
vec![ty]
} else {
substs.as_closure().upvar_tys().collect()
}
vec![ty]
}
ty::Generator(_, ref substs, _) => {
let upvar_tys_resolved =
self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
if let ty::Infer(ty::TyVar(_)) = upvar_tys_resolved.kind() {
// The inference variable will be replaced by a tuple once capture analysis
// completes, if the tuple meets a bound, so do all the elements within it.
let witness_resolved =
self.infcx.shallow_resolve(substs.as_generator().witness());
vec![upvar_tys_resolved, witness_resolved]
} else {
let witness = substs.as_generator().witness();
substs.as_generator().upvar_tys().chain(iter::once(witness)).collect()
}
let ty = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
let witness = substs.as_generator().witness();
vec![ty].into_iter().chain(iter::once(witness)).collect()
}
ty::GeneratorWitness(types) => {

View file

@ -41,6 +41,7 @@ LL | require_send(send_fut);
|
= help: the trait `Sync` is not implemented for `RefCell<i32>`
= note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
= note: required because it appears within the type `(Arc<RefCell<i32>>,)`
= note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:47:31: 47:36 {}]`
= note: required because it appears within the type `from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:47:31: 47:36 {}]>`
= note: required because it appears within the type `impl Future`

View file

@ -29,6 +29,7 @@ LL | require_send(send_gen);
|
= help: the trait `Sync` is not implemented for `RefCell<i32>`
= note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
= note: required because it appears within the type `(Arc<RefCell<i32>>,)`
= note: required because it appears within the type `[generator@$DIR/issue-68112.rs:38:5: 41:6 {()}]`
= note: required because it appears within the type `impl Generator`
= note: required because it appears within the type `impl Generator`

View file

@ -29,6 +29,7 @@ LL | require_send(send_gen);
|
= help: the trait `Sync` is not implemented for `RefCell<i32>`
= note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
= note: required because it appears within the type `(Arc<RefCell<i32>>,)`
= note: required because it appears within the type `[make_gen2<Arc<RefCell<i32>>>::{closure#0} upvar_tys=(Arc<RefCell<i32>>) {()}]`
= note: required because it appears within the type `Opaque(DefId(0:29 ~ generator_print_verbose_1[317d]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])`
= note: required because it appears within the type `Opaque(DefId(0:32 ~ generator_print_verbose_1[317d]::make_non_send_generator2::{opaque#0}), [])`

View file

@ -11,6 +11,7 @@ LL | send(before());
| ^^^^ `Rc<Cell<i32>>` cannot be sent between threads safely
|
= help: within `impl Fn<(i32,)>`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
= note: required because it appears within the type `(Rc<Cell<i32>>,)`
= note: required because it appears within the type `[closure@$DIR/auto-trait-leak2.rs:7:5: 7:22]`
= note: required because it appears within the type `impl Fn<(i32,)>`
@ -27,6 +28,7 @@ LL | fn after() -> impl Fn(i32) {
| ------------ within this `impl Fn<(i32,)>`
|
= help: within `impl Fn<(i32,)>`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
= note: required because it appears within the type `(Rc<Cell<i32>>,)`
= note: required because it appears within the type `[closure@$DIR/auto-trait-leak2.rs:24:5: 24:22]`
= note: required because it appears within the type `impl Fn<(i32,)>`