Skip to content

Commit 33c3036

Browse files
authored
Rollup merge of rust-lang#108901 - LYF1999:yf/108897, r=lcnr
fix: evaluate with wrong obligation stack fix rust-lang#108897 r? ``@lcnr``
2 parents a95943b + 204ba32 commit 33c3036

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10831083
let mut nested_result = EvaluationResult::EvaluatedToOk;
10841084
for obligation in nested_obligations {
10851085
nested_result = cmp::max(
1086-
this.evaluate_predicate_recursively(stack.list(), obligation)?,
1086+
this.evaluate_predicate_recursively(previous_stack, obligation)?,
10871087
nested_result,
10881088
);
10891089
}
@@ -1092,7 +1092,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10921092
let obligation = obligation.with(this.tcx(), predicate);
10931093
result = cmp::max(
10941094
nested_result,
1095-
this.evaluate_trait_predicate_recursively(stack.list(), obligation)?,
1095+
this.evaluate_trait_predicate_recursively(previous_stack, obligation)?,
10961096
);
10971097
}
10981098
}

tests/ui/traits/unsend-future.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// edition:2021
2+
3+
// issue 108897
4+
trait Handler {}
5+
impl<F, Fut> Handler for F
6+
where
7+
Fut: Send,
8+
F: FnOnce() -> Fut,
9+
{}
10+
11+
fn require_handler<H: Handler>(h: H) {}
12+
13+
async fn handler() {
14+
let a = &1 as *const i32;
15+
async {}.await;
16+
}
17+
18+
fn main() {
19+
require_handler(handler)
20+
//~^ ERROR future cannot be sent between threads safely
21+
}

tests/ui/traits/unsend-future.stderr

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: future cannot be sent between threads safely
2+
--> $DIR/unsend-future.rs:19:21
3+
|
4+
LL | require_handler(handler)
5+
| ^^^^^^^ future returned by `handler` is not `Send`
6+
|
7+
= help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const i32`
8+
note: future is not `Send` as this value is used across an await
9+
--> $DIR/unsend-future.rs:15:13
10+
|
11+
LL | let a = &1 as *const i32;
12+
| - has type `*const i32` which is not `Send`
13+
LL | async {}.await;
14+
| ^^^^^^ await occurs here, with `a` maybe used later
15+
LL | }
16+
| - `a` is later dropped here
17+
note: required by a bound in `require_handler`
18+
--> $DIR/unsend-future.rs:11:23
19+
|
20+
LL | fn require_handler<H: Handler>(h: H) {}
21+
| ^^^^^^^ required by this bound in `require_handler`
22+
23+
error: aborting due to previous error
24+

0 commit comments

Comments
 (0)