From ab0938d0df6f6801e0ad2d1f6d11f05106d00646 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 7 Jun 2022 00:55:12 -0700 Subject: Filter out intrinsics if we have other import candidates to suggest --- compiler/rustc_resolve/src/late/diagnostics.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_resolve') diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index cb39eb5416b..6f1b1996474 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -384,7 +384,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { // Try to lookup name in more relaxed fashion for better error reporting. let ident = path.last().unwrap().ident; - let candidates = self + let mut candidates = self .r .lookup_import_candidates(ident, ns, &self.parent_scope, is_expected) .into_iter() @@ -396,6 +396,18 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { }) .collect::>(); let crate_def_id = CRATE_DEF_ID.to_def_id(); + // Try to filter out intrinsics candidates, as long as we have + // some other candidates to suggest. + let intrinsic_candidates: Vec<_> = candidates + .drain_filter(|sugg| { + let path = path_names_to_string(&sugg.path); + path.starts_with("core::intrinsics::") || path.starts_with("std::intrinsics::") + }) + .collect(); + if candidates.is_empty() { + // Put them back if we have no more candidates to suggest... + candidates.extend(intrinsic_candidates); + } if candidates.is_empty() && is_expected(Res::Def(DefKind::Enum, crate_def_id)) { let mut enum_candidates: Vec<_> = self .r -- cgit 1.4.1-3-g733a5