From 7bad066f82f65781864804f674ee9c31c1ad68a7 Mon Sep 17 00:00:00 2001 From: bohan Date: Mon, 4 Sep 2023 00:52:17 +0800 Subject: [PATCH] resolve: derive diag for undetermined macro resolution --- compiler/rustc_resolve/messages.ftl | 4 ++++ compiler/rustc_resolve/src/errors.rs | 10 ++++++++++ compiler/rustc_resolve/src/macros.rs | 15 +++++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_resolve/messages.ftl b/compiler/rustc_resolve/messages.ftl index f98918cba8800..33fde28552445 100644 --- a/compiler/rustc_resolve/messages.ftl +++ b/compiler/rustc_resolve/messages.ftl @@ -58,6 +58,10 @@ resolve_cannot_determine_import_resolution = cannot determine resolution for the import .note = import resolution is stuck, try simplifying other imports +resolve_cannot_determine_macro_resolution = + cannot determine resolution for the {$kind} `{$path}` + .note = import resolution is stuck, try simplifying macro imports + resolve_cannot_find_ident_in_this_scope = cannot find {$expected} `{$ident}` in this scope diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index e4b89c65853d0..85c9171e78abb 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -654,6 +654,16 @@ pub(crate) struct CannotDetermineImportResolution { pub(crate) span: Span, } +#[derive(Diagnostic)] +#[diag(resolve_cannot_determine_macro_resolution)] +#[note] +pub(crate) struct CannotDetermineMacroResolution { + #[primary_span] + pub(crate) span: Span, + pub(crate) kind: &'static str, + pub(crate) path: String, +} + #[derive(Diagnostic)] #[diag(resolve_cannot_be_reexported_private, code = "E0364")] pub(crate) struct CannotBeReexportedPrivate { diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 1199290a4d1c6..8206071657577 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -2,7 +2,8 @@ //! interface provided by `Resolver` to macro expander. use crate::errors::{ - self, AddAsNonDerive, CannotFindIdentInThisScope, MacroExpectedFound, RemoveSurroundingDerive, + self, AddAsNonDerive, CannotDetermineMacroResolution, CannotFindIdentInThisScope, + MacroExpectedFound, RemoveSurroundingDerive, }; use crate::Namespace::*; use crate::{BuiltinMacroState, Determinacy}; @@ -719,13 +720,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { // even if speculative `resolve_path` returned nothing previously, so we skip this // less informative error if the privacy error is reported elsewhere. if this.privacy_errors.is_empty() { - let msg = format!( - "cannot determine resolution for the {} `{}`", - kind.descr(), - Segment::names_to_string(path) - ); - let msg_note = "import resolution is stuck, try simplifying macro imports"; - this.tcx.sess.struct_span_err(span, msg).note(msg_note).emit(); + this.tcx.sess.emit_err(CannotDetermineMacroResolution { + span, + kind: kind.descr(), + path: Segment::names_to_string(path), + }); } } };