mod evaluation;
mod fs_walk;
mod glob_hazard;
mod item_head;
mod occurrence;
mod path_vocab;
mod reachability;
mod resolve;
mod scope_tree;
mod source_texts;
mod symbol_scan;
mod token_tree;
mod use_scan;
mod use_tree;
pub(crate) use evaluation::{EvaluationScans, RootScan};
pub(crate) use fs_walk::rust_files;
pub(crate) use path_vocab::{
PrefixRoot, SymbolPrefix, canonical_module_path, canonical_module_spelling,
canonical_symbol_path_spelling, package_name_to_import_ident, path_within, sysroot_crate,
};
pub(crate) use reachability::{governed_files, names_crate_by_path_alone, reachable_modules};
#[cfg(test)]
pub(crate) use scope_tree::take_table_builds;
pub(crate) use symbol_scan::{InlineFinding, UnitScan};
pub(crate) use token_tree::Edition;
pub(crate) use use_scan::ImportedPath;
#[cfg(test)]
mod tests {
use super::path_vocab::canonical_segment;
use super::reachability::declared_modules;
use super::token_tree::{Edition, Kind, TokenTree};
use super::use_scan::{imported_module_paths, imports_with_importers};
use super::{ImportedPath, canonical_module_path};
#[test]
fn scanner_does_not_panic_on_odd_input() {
for src in [
"r#\"unterminated raw string",
"\"unterminated string",
"/* unterminated block",
"'",
"r",
"use ",
"use crate::",
"mod ",
"mod foo",
"}",
"",
] {
let _ = imported_module_paths(src, "crate::kernel").unwrap();
let _ = declared_modules(src);
}
}
#[test]
fn a_raw_identifier_macro_name_does_not_leak_its_body() {
let with_use = r#"
macro_rules! r#try {
() => { use crate::ghost::Thing; };
}
use crate::real::A;
"#;
assert_eq!(
imported_module_paths(with_use, "crate").unwrap(),
vec![ImportedPath::plain("crate::real::A")],
"a `use` inside a raw-identifier macro definition is not observed"
);
let with_mod = "macro_rules! r#try { () => { mod ghost; }; }\nmod real;";
assert_eq!(
declared_modules(with_mod),
vec!["real".to_string()],
"a `mod` inside a raw-identifier macro definition is not a declared module"
);
}
#[test]
fn keyword_detection_does_not_fire_inside_a_unicode_identifier() {
let first = |source: &str| {
let tree = TokenTree::lex(source, Edition::Rust2018);
(tree.kind(0), tree.text(0).to_string())
};
assert_eq!(first("use貓;"), (Kind::Ident, "use貓".to_string()));
assert_eq!(first("mod貓 {}"), (Kind::Ident, "mod貓".to_string()));
assert_eq!(first("use 貓;"), (Kind::Keyword, "use".to_string()));
assert!(
imports_with_importers("fn use貓() {}", "crate", Edition::Rust2018)
.unwrap()
.is_empty()
);
assert!(declared_modules("fn mod貓() {}").is_empty());
}
#[test]
fn raw_identifiers_are_canonicalized() {
assert_eq!(canonical_segment("r#type"), "type");
assert_eq!(canonical_segment("type"), "type");
assert_eq!(
canonical_module_path("crate::r#type::r#mod"),
"crate::type::mod"
);
assert_eq!(
declared_modules("pub mod r#type;"),
vec!["type".to_string()]
);
assert_eq!(
imported_module_paths("use crate::r#type::Thing;", "crate").unwrap(),
vec![ImportedPath::plain("crate::type::Thing")],
"a raw-identifier use path is canonicalized to its plain form"
);
}
}