File: by-move-body-inlined-attrs.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (28 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//@ check-pass
//@ compile-flags: -Zinline-mir -Zvalidate-mir
//@ edition: 2024

// See comment below.

use std::future::Future;
use std::pin::pin;
use std::task::{Context, Waker};

fn call_once<T>(f: impl FnOnce() -> T) -> T { f() }

fn main() {
    let x = async || {};
    // We first inline `call_once<{async closure}>`.
    //
    // This gives us a future whose type is the "FnOnce" flavor of the async closure's
    // child coroutine. The body of this coroutine is synthetic, which we synthesize in
    // the by-move body query.
    let fut = pin!(call_once(x));
    // We then try to inline that body in this poll call.
    //
    // The inliner does some inlinability checks; one of these checks involves checking
    // the body for the `#[rustc_no_mir_inline]` attribute. Since the synthetic body had
    // no HIR synthesized, but it's still a local def id, we end up ICEing in the
    // `local_def_id_to_hir_id` call when trying to read its attrs.
    fut.poll(&mut Context::from_waker(Waker::noop()));
}