Skip to content

Commit 08d1ab0

Browse files
arora-amanroxelo
andcommitted
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 <[email protected]>
1 parent dc18370 commit 08d1ab0

File tree

5 files changed

+9
-20
lines changed

5 files changed

+9
-20
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,29 +1708,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17081708

17091709
ty::Closure(_, ref substs) => {
17101710
let ty = self.infcx.shallow_resolve(substs.as_closure().tupled_upvars_ty());
1711-
if let ty::Infer(ty::TyVar(_)) = ty.kind() {
1712-
// The inference variable will be replaced by a tuple once capture analysis
1713-
// completes. If the tuple meets a bound, so do all the elements within it.
1714-
vec![ty]
1715-
} else {
1716-
substs.as_closure().upvar_tys().collect()
1717-
}
1711+
vec![ty]
17181712
}
17191713

17201714
ty::Generator(_, ref substs, _) => {
1721-
let upvar_tys_resolved =
1722-
self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
1723-
1724-
if let ty::Infer(ty::TyVar(_)) = upvar_tys_resolved.kind() {
1725-
// The inference variable will be replaced by a tuple once capture analysis
1726-
// completes, if the tuple meets a bound, so do all the elements within it.
1727-
let witness_resolved =
1728-
self.infcx.shallow_resolve(substs.as_generator().witness());
1729-
vec![upvar_tys_resolved, witness_resolved]
1730-
} else {
1731-
let witness = substs.as_generator().witness();
1732-
substs.as_generator().upvar_tys().chain(iter::once(witness)).collect()
1733-
}
1715+
let ty = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty());
1716+
let witness = substs.as_generator().witness();
1717+
vec![ty].into_iter().chain(iter::once(witness)).collect()
17341718
}
17351719

17361720
ty::GeneratorWitness(types) => {

src/test/ui/async-await/issue-68112.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ LL | require_send(send_fut);
4141
|
4242
= help: the trait `Sync` is not implemented for `RefCell<i32>`
4343
= note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
44+
= note: required because it appears within the type `(Arc<RefCell<i32>>,)`
4445
= note: required because it appears within the type `[static generator@$DIR/issue-68112.rs:47:31: 47:36 {}]`
4546
= note: required because it appears within the type `from_generator::GenFuture<[static generator@$DIR/issue-68112.rs:47:31: 47:36 {}]>`
4647
= note: required because it appears within the type `impl Future`

src/test/ui/generator/issue-68112.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ LL | require_send(send_gen);
2929
|
3030
= help: the trait `Sync` is not implemented for `RefCell<i32>`
3131
= note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
32+
= note: required because it appears within the type `(Arc<RefCell<i32>>,)`
3233
= note: required because it appears within the type `[generator@$DIR/issue-68112.rs:38:5: 41:6 {()}]`
3334
= note: required because it appears within the type `impl Generator`
3435
= note: required because it appears within the type `impl Generator`

src/test/ui/generator/print/generator-print-verbose-1.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ LL | require_send(send_gen);
2929
|
3030
= help: the trait `Sync` is not implemented for `RefCell<i32>`
3131
= note: required because of the requirements on the impl of `Send` for `Arc<RefCell<i32>>`
32+
= note: required because it appears within the type `(Arc<RefCell<i32>>,)`
3233
= note: required because it appears within the type `[make_gen2<Arc<RefCell<i32>>>::{closure#0} upvar_tys=(Arc<RefCell<i32>>) {()}]`
3334
= 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>>])`
3435
= note: required because it appears within the type `Opaque(DefId(0:32 ~ generator_print_verbose_1[317d]::make_non_send_generator2::{opaque#0}), [])`

src/test/ui/impl-trait/auto-trait-leak2.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LL | send(before());
1111
| ^^^^ `Rc<Cell<i32>>` cannot be sent between threads safely
1212
|
1313
= help: within `impl Fn<(i32,)>`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
14+
= note: required because it appears within the type `(Rc<Cell<i32>>,)`
1415
= note: required because it appears within the type `[closure@$DIR/auto-trait-leak2.rs:7:5: 7:22]`
1516
= note: required because it appears within the type `impl Fn<(i32,)>`
1617

@@ -27,6 +28,7 @@ LL | fn after() -> impl Fn(i32) {
2728
| ------------ within this `impl Fn<(i32,)>`
2829
|
2930
= help: within `impl Fn<(i32,)>`, the trait `Send` is not implemented for `Rc<Cell<i32>>`
31+
= note: required because it appears within the type `(Rc<Cell<i32>>,)`
3032
= note: required because it appears within the type `[closure@$DIR/auto-trait-leak2.rs:24:5: 24:22]`
3133
= note: required because it appears within the type `impl Fn<(i32,)>`
3234

0 commit comments

Comments
 (0)