refactor path construction

Co-Authored-By: mu001999 <mu001999@outlook.com>
This commit is contained in:
Iris Shi
2026-05-08 16:21:06 +08:00
parent 1ad59ef182
commit b7d22fd68b
+10 -12
View File
@@ -2406,7 +2406,6 @@ fn report_privacy_error(&mut self, privacy_error: &PrivacyError<'ra>) {
let first_binding = decl;
let mut next_binding = Some(decl);
let mut next_ident = ident;
let mut path = vec![];
while let Some(binding) = next_binding {
let name = next_ident;
next_binding = match binding.kind {
@@ -2427,18 +2426,17 @@ fn report_privacy_error(&mut self, privacy_error: &PrivacyError<'ra>) {
match binding.kind {
DeclKind::Import { source_decl, import, .. } => {
for segment in &import.module_path {
// Don't include `{{root}}` in suggestions - it's an internal symbol
// that should never be shown to users.
if segment.ident.name != kw::PathRoot {
path.push(segment.ident);
}
}
// Don't include `{{root}}` in suggestions - it's an internal symbol
// that should never be shown to users.
let path = import
.module_path
.iter()
.filter(|seg| seg.ident.name != kw::PathRoot)
.map(|seg| seg.ident.clone())
.chain(std::iter::once(ident))
.collect::<Vec<_>>();
let through_reexport = !matches!(source_decl.kind, DeclKind::Def(_));
sugg_paths.push((
path.iter().cloned().chain(std::iter::once(ident)).collect::<Vec<_>>(),
through_reexport,
));
sugg_paths.push((path, through_reexport));
}
DeclKind::Def(_) => {}
}