Skip to main content

rapx/preprocess/
dummy_fns.rs

1use super::set_attrs;
2use rustc_ast::*;
3use rustc_span::{DUMMY_SP, symbol::Ident};
4use thin_vec::ThinVec;
5
6fn make_dummy_fn_sig() -> FnSig {
7    let fn_decl = FnDecl {
8        inputs: ThinVec::new(),
9        output: FnRetTy::Default(DUMMY_SP),
10    };
11
12    FnSig {
13        decl: Box::new(fn_decl),
14        header: FnHeader {
15            safety: Safety::Default,
16            constness: Const::No,
17            ext: Extern::None,
18            #[cfg(rapx_ge_100)]
19            coroutine_marker: None,
20            #[cfg(not(rapx_ge_100))]
21            coroutine_kind: None,
22        },
23        span: DUMMY_SP,
24    }
25}
26
27fn make_dummy_block() -> Block {
28    Block {
29        stmts: ThinVec::new(),
30        id: DUMMY_NODE_ID,
31        rules: BlockCheckMode::Default,
32        span: DUMMY_SP,
33        #[cfg(not(rapx_ge_99))]
34        tokens: None,
35    }
36}
37
38fn make_dummy_fn(ident_name: &str, build_std: bool) -> Box<Item> {
39    let ident = Ident::from_str(ident_name);
40
41    let fn_ast = Fn {
42        #[cfg(rapx_ge_99)]
43        defaultness: Defaultness::Implicit,
44        #[cfg(not(rapx_ge_99))]
45        defaultness: Defaultness::Final,
46        ident,
47        generics: Generics::default(),
48        sig: make_dummy_fn_sig(),
49        contract: None,
50        define_opaque: None,
51        #[cfg(rapx_ge_100)]
52        eii_impl: Default::default(),
53        #[cfg(all(rapx_ge_99, not(rapx_ge_100)))]
54        eii_impls: Default::default(),
55        body: Some(Box::new(make_dummy_block())),
56    };
57
58    Box::new(Item {
59        attrs: set_attrs(build_std),
60        id: DUMMY_NODE_ID,
61        kind: ItemKind::Fn(Box::new(fn_ast)),
62        vis: Visibility {
63            span: DUMMY_SP,
64            kind: VisibilityKind::Public,
65            #[cfg(not(rapx_ge_99))]
66            tokens: None,
67        },
68        span: DUMMY_SP,
69        tokens: None,
70    })
71}
72
73pub(crate) fn create_dummy_fns(krate: &mut Crate, build_std: bool) {
74    let raw_ptr_fn = make_dummy_fn("__raw_ptr_deref_dummy", build_std);
75    let static_mut_fn = make_dummy_fn("__static_mut_deref_dummy", build_std);
76
77    krate.items.push(raw_ptr_fn);
78    krate.items.push(static_mut_fn);
79}