From b7d22fd68bd2047ad67b3d5b53186157b591111b Mon Sep 17 00:00:00 2001 From: Iris Shi <0.0@owo.li> Date: Fri, 8 May 2026 16:21:06 +0800 Subject: [PATCH] refactor path construction Co-Authored-By: mu001999 --- compiler/rustc_resolve/src/diagnostics.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 47b4e9ca2c69..874b4ca98830 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -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::>(); let through_reexport = !matches!(source_decl.kind, DeclKind::Def(_)); - sugg_paths.push(( - path.iter().cloned().chain(std::iter::once(ident)).collect::>(), - through_reexport, - )); + sugg_paths.push((path, through_reexport)); } DeclKind::Def(_) => {} }