Skip to content

Commit fe5b9c1

Browse files
committed
Fix failing test
1 parent df54571 commit fe5b9c1

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,26 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
13071307
let mut generator = None;
13081308
let mut outer_generator = None;
13091309
let mut next_code = Some(&obligation.cause.code);
1310+
// By introducing a tuple into the upvar types, the first item in the obligation chain
1311+
// can be of Tuple type instead of the generator that captured the type. We want to catch for
1312+
// this case and skip it.
1313+
if let Some(code) = next_code {
1314+
match code {
1315+
ObligationCauseCode::DerivedObligation(derived_obligation)
1316+
| ObligationCauseCode::BuiltinDerivedObligation(derived_obligation)
1317+
| ObligationCauseCode::ImplDerivedObligation(derived_obligation) => {
1318+
let ty = derived_obligation.parent_trait_ref.skip_binder().self_ty();
1319+
match *ty.kind() {
1320+
ty::Tuple(_) => {
1321+
next_code = Some(derived_obligation.parent_code.as_ref());
1322+
}
1323+
_ => {}
1324+
}
1325+
}
1326+
_ => {}
1327+
}
1328+
}
1329+
13101330
while let Some(code) = next_code {
13111331
debug!("maybe_note_obligation_cause_for_async_await: code={:?}", code);
13121332
match code {
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
error[E0277]: `U` cannot be sent between threads safely
1+
error: future cannot be sent between threads safely
22
--> $DIR/issue-70818.rs:4:38
33
|
44
LL | fn foo<T: Send, U>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + Send {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `U` cannot be sent between threads safely
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ future created by async block is not `Send`
66
LL |
77
LL | async { (ty, ty1) }
88
| ------------------- this returned value is of type `impl Future`
9-
|
10-
::: $SRC_DIR/core/src/future/mod.rs:LL:COL
119
|
12-
LL | pub const fn from_generator<T>(gen: T) -> impl Future<Output = T::Return>
13-
| ------------------------------- within this `impl Future`
10+
note: captured value is not `Send`
11+
--> $DIR/issue-70818.rs:6:18
1412
|
15-
= note: required because it appears within the type `(T, U)`
16-
= note: required because it appears within the type `[static generator@$DIR/issue-70818.rs:6:11: 6:24 _]`
17-
= note: required because it appears within the type `from_generator::GenFuture<[static generator@$DIR/issue-70818.rs:6:11: 6:24 _]>`
18-
= note: required because it appears within the type `impl Future`
13+
LL | async { (ty, ty1) }
14+
| ^^^ has type `U` which is not `Send`
1915
= note: the return type of a function must have a statically known size
2016
help: consider restricting type parameter `U`
2117
|
@@ -24,4 +20,3 @@ LL | fn foo<T: Send, U: Send>(ty: T, ty1: U) -> impl Future<Output = (T, U)> + S
2420

2521
error: aborting due to previous error
2622

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

0 commit comments

Comments
 (0)