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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// SPDX-FileCopyrightText: 2026 Blackcat InformaticsĀ® Inc. <paudley@blackcatinformatics.ca>
// SPDX-License-Identifier: MIT OR Apache-2.0 OR MulanPSL-2.0
//! The workspace source index: packages and targets, the module tree of each
//! target, a symbol index and a `use`-alias resolver, over a [`Tree`] seam with
//! a disk and a memory backend and under canonical path containment.
//!
//! Load a workspace from a real directory and ask where a path is defined. The
//! block needs a real tree, so it is compiled and not run:
//!
//! ```rust,no_run
//! use raf_source::{DiskTree, Workspace};
//!
//! let ws = Workspace::load(&DiskTree::new(".")?, &["crates"])?;
//! let resolution = ws.resolve("raf_okf::Document")?;
//! for site in &resolution.sites {
//! let item = ws.item(*site).expect("a site is an item of this workspace");
//! println!("{} at {}:{}", item.path, item.file, item.name_line);
//! }
//! for target in ws.targets().filter(|t| !t.shipping) {
//! println!("{} is a non-shipping target", target.name);
//! }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! [`Workspace::exported_items`] lists the public surface of a library or a
//! binary: the items another crate can name through its crate root, each under
//! the path it is exported by and with the item that defines it, and the public
//! re-exports of other crates, which are not items of the target. Over a real
//! tree, each library's surface maps every exported path back to its
//! definition. The block needs a real tree, so it is compiled and not run:
//!
//! ```rust,no_run
//! use raf_source::{DiskTree, TargetKind, Workspace};
//!
//! let ws = Workspace::load(&DiskTree::new(".")?, &["crates"])?;
//! for id in ws.target_ids() {
//! let target = ws.target(id).expect("an id of this workspace");
//! if target.kind != TargetKind::Lib {
//! continue;
//! }
//! let exports = ws.exported_items(id)?;
//! for export in &exports.items {
//! let item = ws.item(export.item).expect("an item of this workspace");
//! println!("{} is {} in {}", export.path, item.path, export.file);
//! }
//! for reexport in &exports.reexports {
//! println!("{} re-exports {}", reexport.path, reexport.written);
//! }
//! }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! With [`MemoryTree`] a fixture needs no disk:
//!
//! ```rust
//! use raf_source::{MemoryTree, Workspace};
//!
//! let tree = MemoryTree::from([
//! ("Cargo.toml", "[package]\nname = \"demo\"\nversion = \"0.1.0\"\n"),
//! ("src/lib.rs", "mod inner;\npub use inner::go as run;\n"),
//! ("src/inner.rs", "pub fn go() {}\n"),
//! ]);
//! let ws = Workspace::load(&tree, &["."])?;
//! assert_eq!(ws.resolve("demo::run")?.path, "demo::inner::go");
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! A `pub` item of a private module is exported only through a `pub` re-export:
//!
//! ```rust
//! use raf_source::{MemoryTree, Workspace};
//!
//! let tree = MemoryTree::from([
//! ("Cargo.toml", "[package]\nname = \"demo\"\nversion = \"0.1.0\"\n"),
//! ("src/lib.rs", "mod inner;\npub use inner::go as run;\npub(crate) fn helper() {}\n"),
//! ("src/inner.rs", "pub fn go() {}\npub fn unused() {}\n"),
//! ]);
//! let ws = Workspace::load(&tree, &["."])?;
//! let lib = ws.target_ids().next().expect("the library");
//! let exports = ws.exported_items(lib)?;
//! assert_eq!(exports.items.len(), 1);
//! assert_eq!(exports.items[0].path, "demo::run");
//! assert_eq!(
//! ws.item(exports.items[0].item).map(|item| item.path.as_str()),
//! Some("demo::inner::go")
//! );
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! Every file the crate looks at goes through [`Tree`]. [`DiskTree`] reads a
//! directory on disk and refuses anything that leads out of its root, or is
//! not a regular file, or is larger than the caller allows. [`MemoryTree`]
//! holds the same contents in a map so that a fixture needs no disk:
//!
//! ```rust
//! use raf_source::{EntryKind, MemoryTree, RelPath, Tree, TreeError};
//!
//! let tree = MemoryTree::from([("src/lib.rs", "pub fn go() {}\n")]);
//! let lib = RelPath::new("src/lib.rs")?;
//! assert_eq!(tree.read(&lib, 1024)?, "pub fn go() {}\n");
//! assert_eq!(tree.entry(&RelPath::new("src")?)?, Some(EntryKind::Dir));
//! assert!(matches!(
//! tree.read(&RelPath::new("src/missing.rs")?, 1024),
//! Err(TreeError::NotFound { .. })
//! ));
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! [`parse_source`] parses Rust text under bounds. A token pre-scan refuses a file
//! that passes a recursion [`Budget`] before `syn` sees it, and the parse and a
//! caller's visitor then run on a thread named after the file, with a stack of
//! [`PARSE_STACK_BYTES`]:
//!
//! ```rust
//! use raf_source::{Budget, LoadErrorKind, RelPath, parse_source};
//!
//! let file = RelPath::new("src/lib.rs")?;
//! let items = parse_source(&file, "pub fn go() {}\n", |tree| tree.items.len())?;
//! assert_eq!(items, 1);
//!
//! let deep = format!("type T = {}u8{};", "A<".repeat(65), ">".repeat(65));
//! let refused = parse_source(&file, &deep, |_| ()).unwrap_err();
//! assert!(matches!(
//! refused.kind,
//! LoadErrorKind::Budget { budget: Budget::Angles, limit: 64 }
//! ));
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! [`Workspace::load`] takes explicit roots, finds the packages and targets under
//! them, and follows every target's `mod` declarations as rustc does:
//!
//! ```rust
//! use raf_source::{MemoryTree, TargetKind, Workspace};
//!
//! let tree = MemoryTree::from([
//! ("Cargo.toml", "[package]\nname = \"demo\"\nversion = \"0.1.0\"\n"),
//! ("src/lib.rs", "mod inner;\n"),
//! ("src/inner.rs", "pub fn go() {}\n"),
//! ("tests/it.rs", "fn case() {}\n"),
//! ]);
//! let ws = Workspace::load(&tree, &["."])?;
//! let targets: Vec<_> = ws.targets().map(|t| (t.kind, t.crate_path.as_str())).collect();
//! assert_eq!(
//! targets,
//! [(TargetKind::Lib, "demo"), (TargetKind::Test, "demo::test_crate::it")]
//! );
//! assert_eq!(ws.files().count(), 3);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! Only [`TreeError::NotFound`] means that nothing is there. Every other
//! error is a refusal or a failure and is never read as absence.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use visit_pattern_bindings;
pub use ;
pub use ;
pub use ;
pub use CargoLintManifest;
pub use ;
pub use Usage;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use discover_root;
/// The `syn` that produced the facts, re-exported so a consumer parses with the
/// same version; a `syn` major bump is a breaking change of this crate.
pub use syn;
pub use ;
pub use ;
pub use ;
pub use visit_grouped_import;
pub use ;
/// Native read-only repository and object access, without executable helpers.