use rustc_ast::UseTree;
use rustc_span::kw;
use super::config::{CfgBlockHandling, Config, Group};
fn first_segment(tree: &UseTree) -> Option<String> {
for segment in &tree.prefix.segments {
if segment.ident.name == kw::PathRoot {
continue;
}
return Some(segment.ident.name.to_string());
}
None
}
fn path_group(tree: &UseTree, config: &Config) -> Group {
let Some(first) = first_segment(tree) else {
return Group::Thirdparty;
};
if config.std_crates.contains(&first) {
Group::Std
} else if config.internal_prefixes.contains(&first) {
Group::Internal
} else {
Group::Thirdparty
}
}
pub(super) fn rank(tree: &UseTree, is_cfg_gated: bool, config: &Config) -> usize {
if is_cfg_gated && matches!(config.cfg_block_handling, CfgBlockHandling::Trailing) {
return config.cfg_rank();
}
config.group_rank(path_group(tree, config))
}