1 #[cfg_attr(rustfmt, rustfmt_skip)]
2 static RUST_KEYWORDS: &'static [&'static str] = &[
3 "_",
4 "as",
5 "async",
6 "await",
7 "break",
8 "crate",
9 "dyn",
10 "else",
11 "enum",
12 "extern",
13 "false",
14 "fn",
15 "for",
16 "if",
17 "impl",
18 "in",
19 "let",
20 "loop",
21 "match",
22 "mod",
23 "move",
24 "mut",
25 "pub",
26 "ref",
27 "return",
28 "static",
29 "self",
30 "Self",
31 "struct",
32 "super",
33 "true",
34 "trait",
35 "type",
36 "unsafe",
37 "use",
38 "while",
39 "continue",
40 "box",
41 "const",
42 "where",
43 "virtual",
44 "proc",
45 "alignof",
46 "become",
47 "offsetof",
48 "priv",
49 "pure",
50 "sizeof",
51 "typeof",
52 "unsized",
53 "yield",
54 "do",
55 "abstract",
56 "final",
57 "override",
58 "macro",
59 ];
60
61 // https://internals.rust-lang.org/t/raw-identifiers-dont-work-for-all-identifiers/9094/3
62 #[cfg_attr(rustfmt, rustfmt_skip)]
63 static RUST_KEYWORDS_WHICH_CANNOT_BE_RAW: &'static [&'static str] = &[
64 "super",
65 "self",
66 "Self",
67 "extern",
68 "crate",
69 ];
70
parse_rust_keyword(word: &str) -> Option<&'static str>71 pub(crate) fn parse_rust_keyword(word: &str) -> Option<&'static str> {
72 RUST_KEYWORDS.iter().cloned().find(|&kw| kw == word)
73 }
74
is_rust_keyword(ident: &str) -> bool75 pub(crate) fn is_rust_keyword(ident: &str) -> bool {
76 parse_rust_keyword(ident).is_some()
77 }
78
79 #[allow(dead_code)]
is_rust_keyword_which_cannot_be_raw(ident: &str) -> bool80 pub(crate) fn is_rust_keyword_which_cannot_be_raw(ident: &str) -> bool {
81 RUST_KEYWORDS_WHICH_CANNOT_BE_RAW
82 .iter()
83 .cloned()
84 .find(|&kw| kw == ident)
85 .is_some()
86 }
87