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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! The standard library paths and the English, SQL, WASI and WebAssembly words that
//! `cargo xtask vocab` builds.
/// The public paths reachable from one crate root.
pub(crate) struct Layer {
/// The root the layer's paths start with.
pub(crate) root: &'static str,
/// The suffixes, of two or more segments, of every path.
suffixes: fst::Set<&'static [u8]>,
/// Every segment of every path.
names: fst::Set<&'static [u8]>,
}
impl Layer {
fn new(root: &'static str, suffixes: &'static [u8], names: &'static [u8]) -> Self {
let set = |bytes| fst::Set::new(bytes).expect("data/std holds fst sets written by xtask");
Self {
root,
suffixes: set(suffixes),
names: set(names),
}
}
/// Whether `path`, spelled with `::`, ends a public path of this layer.
pub(crate) fn ends_a_path(&self, path: &str) -> bool {
self.suffixes.contains(path)
}
/// Whether some public path of this layer has a segment `name`.
pub(crate) fn has_name(&self, name: &str) -> bool {
self.names.contains(name)
}
}
/// The `core`, `alloc`, `std` and `proc_macro` layers.
pub(crate) fn layers() -> [Layer; 4] {
[
Layer::new(
"core",
include_bytes!("../data/std/core.fst"),
include_bytes!("../data/std/core-names.fst"),
),
Layer::new(
"alloc",
include_bytes!("../data/std/alloc.fst"),
include_bytes!("../data/std/alloc-names.fst"),
),
Layer::new(
"std",
include_bytes!("../data/std/std.fst"),
include_bytes!("../data/std/std-names.fst"),
),
Layer::new(
"proc_macro",
include_bytes!("../data/std/proc_macro.fst"),
include_bytes!("../data/std/proc_macro-names.fst"),
),
]
}
/// Words a bare name may simply be, English words in running text and SQL key words, WASI
/// functions and WebAssembly instructions in running text and code spans.
pub(crate) struct Vocabulary {
words: fst::Set<&'static [u8]>,
}
impl Vocabulary {
pub(crate) fn english() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/english/words.fst")[..])
.expect("data/english holds an fst set written by xtask"),
}
}
/// The reserved key words of SQL:2023, uppercase as the standard spells them.
pub(crate) fn sql_2023() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/sql/words.fst")[..])
.expect("data/sql holds an fst set written by xtask"),
}
}
/// The function names of WASI Preview 1.
pub(crate) fn wasi_preview1() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/wasi/words.fst")[..])
.expect("data/wasi holds an fst set written by xtask"),
}
}
/// The WebAssembly 3.0 instructions whose text-format name has no dot.
pub(crate) fn wasm_3() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/wasm/words.fst")[..])
.expect("data/wasm holds an fst set written by xtask"),
}
}
/// The compound class names and camelCase method names of the public Android 16 API.
pub(crate) fn android_36() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/android/words.fst")[..])
.expect("data/android holds an fst set written by xtask"),
}
}
/// The compound Objective-C type names and camelCase selector heads of `UIKit` in the
/// Xcode 27.1 SDK.
pub(crate) fn uikit_27_1() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/uikit/words.fst")[..])
.expect("data/uikit holds an fst set written by xtask"),
}
}
/// The POSIX.1-2017 header constants and functions with an inner underscore, error
/// numbers and signals.
pub(crate) fn posix_2017() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/posix/words.fst")[..])
.expect("data/posix holds an fst set written by xtask"),
}
}
/// The standards-track Web API interface and member names that are compound or camelCase,
/// from MDN's browser compatibility data of October 2026.
pub(crate) fn web_api_2026_10() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/bcd/web-api.fst")[..])
.expect("data/bcd holds fst sets written by xtask"),
}
}
/// The compound and camelCase Python 3.15 built-in and standard-library object names.
pub(crate) fn python_3_15() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/python/words.fst")[..])
.expect("data/python holds an fst set written by xtask"),
}
}
/// The mixed-case standards-track JavaScript built-in globals and members, from MDN's
/// browser compatibility data of October 2026.
pub(crate) fn javascript_2026_10() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/bcd/javascript.fst")[..])
.expect("data/bcd holds fst sets written by xtask"),
}
}
/// The camelCase standards-track SVG element and attribute names, from MDN's browser
/// compatibility data of October 2026.
pub(crate) fn svg_2026_10() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/bcd/svg.fst")[..])
.expect("data/bcd holds fst sets written by xtask"),
}
}
/// The documented PostgreSQL 18 function names with an inner underscore, or single words
/// English lacks, such as `set_config` and `uuidv7`.
pub(crate) fn postgres_18() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/postgres/words.fst")[..])
.expect("data/postgres holds an fst set written by xtask"),
}
}
/// The SQLite 3.54 built-in function names with an inner underscore, or single words
/// English lacks, such as `json_extract` and `strftime`.
pub(crate) fn sqlite_3_54() -> Self {
Self {
words: fst::Set::new(&include_bytes!("../data/sqlite/words.fst")[..])
.expect("data/sqlite holds an fst set written by xtask"),
}
}
/// Whether `word`, spelled as the vocabulary stores it, is one of its words.
pub(crate) fn contains(&self, word: &str) -> bool {
self.words.contains(word)
}
}