rapx/preprocess/
mod.rs

1pub mod dummy_fns;
2pub mod ssa_preprocess;
3
4use rustc_ast::{
5    token::{CommentKind, Delimiter, Lit, Token, TokenKind},
6    tokenstream::{DelimSpan, Spacing, TokenStream, TokenTree},
7    *,
8};
9use rustc_span::{DUMMY_SP, Ident, symbol::Symbol};
10use thin_vec::ThinVec;
11
12/// Empty `#[doc]` on the struct.
13/// cc https://github.com/Artisan-Lab/RAPx/issues/184
14fn doc_attr() -> Attribute {
15    Attribute {
16        kind: AttrKind::DocComment(CommentKind::Line, Symbol::intern("doc")),
17        id: AttrId::ZERO,
18        style: AttrStyle::Outer,
19        span: DUMMY_SP,
20    }
21}
22
23// #[stable(feature = "foo", since = "1.93")]
24fn stability_attr() -> Attribute {
25    let mut attr = NormalAttr::from_ident(Ident::from_str("stable"));
26    let tokens: Vec<_> = {
27        let feature = Token::from_ast_ident(Ident::from_str("feature"));
28        let eq = Token::new(TokenKind::Eq, DUMMY_SP);
29        let feature_val = Token::new(
30            TokenKind::Literal(Lit::new(token::LitKind::Str, Symbol::intern("foo"), None)),
31            DUMMY_SP,
32        );
33        let comma = Token::new(TokenKind::Comma, DUMMY_SP);
34        let since = Token::from_ast_ident(Ident::from_str("since"));
35        let since_val = Token::new(
36            TokenKind::Literal(Lit::new(token::LitKind::Str, Symbol::intern("1.93"), None)),
37            DUMMY_SP,
38        );
39        [feature, eq, feature_val, comma, since, eq, since_val]
40            .into_iter()
41            .map(|t| TokenTree::Token(t, Spacing::Alone))
42            .collect()
43    };
44    attr.item.args = AttrArgs::Delimited(DelimArgs {
45        dspan: DelimSpan::dummy(),
46        delim: Delimiter::Parenthesis,
47        tokens: TokenStream::new(tokens),
48    });
49    Attribute {
50        kind: AttrKind::Normal(attr.into()),
51        id: AttrId::ZERO,
52        style: AttrStyle::Outer,
53        span: DUMMY_SP,
54    }
55}
56
57fn set_attrs(build_std: bool) -> ThinVec<Attribute> {
58    let mut v = ThinVec::with_capacity(2);
59    v.push(doc_attr());
60    if build_std {
61        v.push(stability_attr());
62    }
63    v
64}