From d4f1eafcb86f0dd59cafca386bce8dbdd2875849 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Sun, 27 Sep 2020 23:45:30 -0400 Subject: [PATCH] More things compile --- .../src/traits/select/mod.rs | 16 ++++++++++------ src/test/ui/async-await/issue-70818.rs | 2 +- src/test/ui/closures/closure-move-sync.stderr | 2 ++ src/test/ui/generator/not-send-sync.stderr | 1 + .../interior-mutability.stderr | 1 + src/test/ui/kindck/kindck-nonsendable-1.stderr | 1 + src/test/ui/no-send-res-ports.stderr | 1 + 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index abe3db29ee926..9c0330e589f3e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1740,7 +1740,8 @@ 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() { - //self.constituent_types_for_ty(ty) + // 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() @@ -1748,11 +1749,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } ty::Generator(_, ref substs, _) => { - let ty = self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty()); - if let ty::Infer(ty::TyVar(_)) = ty.kind() { - // Not yet resolved. - //self.constituent_types_for_ty(ty) - vec![ty] + let upvar_tys_resolved = + self.infcx.shallow_resolve(substs.as_generator().tupled_upvars_ty()); + let witness_resolved = self.infcx.shallow_resolve(substs.as_generator().witness()); + + 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. + vec![upvar_tys_resolved, witness_resolved] } else { let witness = substs.as_generator().witness(); substs.as_generator().upvar_tys().chain(iter::once(witness)).collect() diff --git a/src/test/ui/async-await/issue-70818.rs b/src/test/ui/async-await/issue-70818.rs index f1390a82b6955..0609e4fc08170 100644 --- a/src/test/ui/async-await/issue-70818.rs +++ b/src/test/ui/async-await/issue-70818.rs @@ -2,7 +2,7 @@ use std::future::Future; fn foo(ty: T, ty1: U) -> impl Future + Send { -//~^ Error 4:38: 4:73: `U` cannot be sent between threads safely [E0277] +//~^ Error future cannot be sent between threads safely async { (ty, ty1) } } diff --git a/src/test/ui/closures/closure-move-sync.stderr b/src/test/ui/closures/closure-move-sync.stderr index 505cae981b08e..2061e6b7ed313 100644 --- a/src/test/ui/closures/closure-move-sync.stderr +++ b/src/test/ui/closures/closure-move-sync.stderr @@ -11,6 +11,7 @@ LL | F: Send + 'static, | = help: the trait `Sync` is not implemented for `std::sync::mpsc::Receiver<()>` = note: required because of the requirements on the impl of `Send` for `&std::sync::mpsc::Receiver<()>` + = note: required because it appears within the type `(&std::sync::mpsc::Receiver<()>,)` = note: required because it appears within the type `[closure@$DIR/closure-move-sync.rs:6:27: 9:6 recv:&std::sync::mpsc::Receiver<()>]` error[E0277]: `Sender<()>` cannot be shared between threads safely @@ -26,6 +27,7 @@ LL | F: Send + 'static, | = help: the trait `Sync` is not implemented for `Sender<()>` = note: required because of the requirements on the impl of `Send` for `&Sender<()>` + = note: required because it appears within the type `(&Sender<()>,)` = note: required because it appears within the type `[closure@$DIR/closure-move-sync.rs:18:19: 18:42 tx:&Sender<()>]` error: aborting due to 2 previous errors diff --git a/src/test/ui/generator/not-send-sync.stderr b/src/test/ui/generator/not-send-sync.stderr index 32527c45c359c..571c55125971d 100644 --- a/src/test/ui/generator/not-send-sync.stderr +++ b/src/test/ui/generator/not-send-sync.stderr @@ -9,6 +9,7 @@ LL | assert_send(|| { | = help: the trait `Sync` is not implemented for `Cell` = note: required because of the requirements on the impl of `Send` for `&Cell` + = note: required because it appears within the type `(&Cell,)` = note: required because it appears within the type `[generator@$DIR/not-send-sync.rs:16:17: 20:6 a:&Cell _]` error: generator cannot be shared between threads safely diff --git a/src/test/ui/interior-mutability/interior-mutability.stderr b/src/test/ui/interior-mutability/interior-mutability.stderr index 3e19746cc5cb8..1c3de1419794f 100644 --- a/src/test/ui/interior-mutability/interior-mutability.stderr +++ b/src/test/ui/interior-mutability/interior-mutability.stderr @@ -12,6 +12,7 @@ LL | pub fn catch_unwind R + UnwindSafe, R>(f: F) -> Result { = help: within `Cell`, the trait `RefUnwindSafe` is not implemented for `UnsafeCell` = note: required because it appears within the type `Cell` = note: required because of the requirements on the impl of `UnwindSafe` for `&Cell` + = note: required because it appears within the type `(&Cell,)` = note: required because it appears within the type `[closure@$DIR/interior-mutability.rs:5:18: 5:35 x:&Cell]` error: aborting due to previous error diff --git a/src/test/ui/kindck/kindck-nonsendable-1.stderr b/src/test/ui/kindck/kindck-nonsendable-1.stderr index 45c767fbe6c5d..7cdf957d6819d 100644 --- a/src/test/ui/kindck/kindck-nonsendable-1.stderr +++ b/src/test/ui/kindck/kindck-nonsendable-1.stderr @@ -10,6 +10,7 @@ LL | bar(move|| foo(x)); | `Rc` cannot be sent between threads safely | = help: within `[closure@$DIR/kindck-nonsendable-1.rs:9:9: 9:22 x:Rc]`, the trait `Send` is not implemented for `Rc` + = note: required because it appears within the type `(Rc,)` = note: required because it appears within the type `[closure@$DIR/kindck-nonsendable-1.rs:9:9: 9:22 x:Rc]` error: aborting due to previous error diff --git a/src/test/ui/no-send-res-ports.stderr b/src/test/ui/no-send-res-ports.stderr index 6bd4537240c3c..1e5ca699ec3d6 100644 --- a/src/test/ui/no-send-res-ports.stderr +++ b/src/test/ui/no-send-res-ports.stderr @@ -19,6 +19,7 @@ LL | F: Send + 'static, = help: within `[closure@$DIR/no-send-res-ports.rs:25:19: 29:6 x:Foo]`, the trait `Send` is not implemented for `Rc<()>` = note: required because it appears within the type `Port<()>` = note: required because it appears within the type `Foo` + = note: required because it appears within the type `(Foo,)` = note: required because it appears within the type `[closure@$DIR/no-send-res-ports.rs:25:19: 29:6 x:Foo]` error: aborting due to previous error