Skip to content

Commit 63e90bc

Browse files
authored
Unrolled build for rust-lang#121350
Rollup merge of rust-lang#121350 - compiler-errors:resolve, r=oli-obk Fix stray trait mismatch in `resolve_associated_item` for `AsyncFn` Copy-paste error meant that we were calling `fn_trait_kind_from_def_id` instead of `async_fn_trait_kind_from_def_id`. But turns out we don't even need to do that, since we already matched the trait def id above. Fixes rust-lang#121306 r? oli-obk
2 parents bb59453 + 762febd commit 63e90bc

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

compiler/rustc_ty_utils/src/instance.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ fn resolve_associated_item<'tcx>(
246246
span: tcx.def_span(trait_item_id),
247247
})
248248
}
249-
} else if tcx.fn_trait_kind_from_def_id(trait_ref.def_id).is_some() {
249+
} else if let Some(target_kind) = tcx.fn_trait_kind_from_def_id(trait_ref.def_id) {
250250
// FIXME: This doesn't check for malformed libcore that defines, e.g.,
251251
// `trait Fn { fn call_once(&self) { .. } }`. This is mostly for extension
252252
// methods.
@@ -265,13 +265,7 @@ fn resolve_associated_item<'tcx>(
265265
}
266266
match *rcvr_args.type_at(0).kind() {
267267
ty::Closure(closure_def_id, args) => {
268-
let trait_closure_kind = tcx.fn_trait_kind_from_def_id(trait_id).unwrap();
269-
Some(Instance::resolve_closure(
270-
tcx,
271-
closure_def_id,
272-
args,
273-
trait_closure_kind,
274-
))
268+
Some(Instance::resolve_closure(tcx, closure_def_id, args, target_kind))
275269
}
276270
ty::FnDef(..) | ty::FnPtr(..) => Some(Instance {
277271
def: ty::InstanceDef::FnPtrShim(trait_item_id, rcvr_args.type_at(0)),
@@ -324,13 +318,7 @@ fn resolve_associated_item<'tcx>(
324318
}
325319
}
326320
ty::Closure(closure_def_id, args) => {
327-
let trait_closure_kind = tcx.fn_trait_kind_from_def_id(trait_id).unwrap();
328-
Some(Instance::resolve_closure(
329-
tcx,
330-
closure_def_id,
331-
args,
332-
trait_closure_kind,
333-
))
321+
Some(Instance::resolve_closure(tcx, closure_def_id, args, target_kind))
334322
}
335323
ty::FnDef(..) | ty::FnPtr(..) => Some(Instance {
336324
def: ty::InstanceDef::FnPtrShim(trait_item_id, rcvr_args.type_at(0)),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ edition: 2021
2+
3+
#![feature(async_closure, noop_waker)]
4+
5+
use std::future::Future;
6+
use std::pin::pin;
7+
use std::task::*;
8+
9+
pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
10+
let mut fut = pin!(fut);
11+
// Poll loop, just to test the future...
12+
let ctx = &mut Context::from_waker(Waker::noop());
13+
14+
loop {
15+
match unsafe { fut.as_mut().poll(ctx) } {
16+
Poll::Pending => {}
17+
Poll::Ready(t) => break t,
18+
}
19+
}
20+
}

tests/ui/async-await/async-fn/simple.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
//@ aux-build:block-on.rs
12
//@ edition: 2021
23
//@ build-pass
34

45
#![feature(async_fn_traits)]
56

7+
extern crate block_on;
8+
69
use std::ops::AsyncFn;
710

811
async fn foo() {}
@@ -12,5 +15,7 @@ async fn call_asyncly(f: impl AsyncFn(i32) -> i32) -> i32 {
1215
}
1316

1417
fn main() {
15-
let fut = call_asyncly(|x| async move { x + 1 });
18+
block_on::block_on(async {
19+
call_asyncly(|x| async move { x + 1 }).await;
20+
});
1621
}

0 commit comments

Comments
 (0)