Skip to content

Commit

Permalink
Fix failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
roxelo committed Oct 4, 2020
1 parent df54571 commit fe5b9c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,26 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
let mut generator = None;
let mut outer_generator = None;
let mut next_code = Some(&obligation.cause.code);
// By introducing a tuple into the upvar types, the first item in the obligation chain
// can be of Tuple type instead of the generator that captured the type. We want to catch for
// this case and skip it.
if let Some(code) = next_code {
match code {
ObligationCauseCode::DerivedObligation(derived_obligation)
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
| ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
let ty = derived_obligation.parent_trait_ref.skip_binder().self_ty();
match *ty.kind() {
ty::Tuple(_) => {
next_code = Some(derived_obligation.parent_code.as_ref());
}
_ => {}
}
}
_ => {}
}
}

while let Some(code) = next_code {
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
match code {
Expand Down
17 changes: 6 additions & 11 deletions src/test/ui/async-await/issue-70818.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
error[E0277]: `U` cannot be sent between threads safely
error: future cannot be sent between threads safely
--> $DIR/issue-70818.rs:4:38
|
LL | fn foo<T: Send, U>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `U` cannot be sent between threads safely
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
LL |
LL | async { (ty, ty1) }
| ------------------- this returned value is of type `impl Future`
|
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
|
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
| ------------------------------- within this `impl Future`
note: captured value is not `Send`
--> $DIR/issue-70818.rs:6:18
|
= note: required because it appears within the type `(T, U)`
= note: required because it appears within the type `[static generator@$DIR/issue-70818.rs:6:11: 6:24 _]`
= note: required because it appears within the type `from_generator::GenFuture<[static generator@$DIR/issue-70818.rs:6:11: 6:24 _]>`
= note: required because it appears within the type `impl Future`
LL | async { (ty, ty1) }
| ^^^ has type `U` which is not `Send`
= note: the return type of a function must have a statically known size
help: consider restricting type parameter `U`
|
Expand All @@ -24,4 +20,3 @@ LL | fn foo<T: Send, U: Send>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + S

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.

0 comments on commit fe5b9c1

Please sign in to comment.