Skip to content

Commit 9a099d2

Browse files
committed
Auto merge of #115504 - bvanjoi:error-struct, r=cjgillot
resolve: derive diag for undetermined macro resolution simply for neatness.
2 parents 9b72cc9 + 7bad066 commit 9a099d2

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

compiler/rustc_resolve/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ resolve_cannot_determine_import_resolution =
5858
cannot determine resolution for the import
5959
.note = import resolution is stuck, try simplifying other imports
6060
61+
resolve_cannot_determine_macro_resolution =
62+
cannot determine resolution for the {$kind} `{$path}`
63+
.note = import resolution is stuck, try simplifying macro imports
64+
6165
resolve_cannot_find_ident_in_this_scope =
6266
cannot find {$expected} `{$ident}` in this scope
6367

compiler/rustc_resolve/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,16 @@ pub(crate) struct CannotDetermineImportResolution {
654654
pub(crate) span: Span,
655655
}
656656

657+
#[derive(Diagnostic)]
658+
#[diag(resolve_cannot_determine_macro_resolution)]
659+
#[note]
660+
pub(crate) struct CannotDetermineMacroResolution {
661+
#[primary_span]
662+
pub(crate) span: Span,
663+
pub(crate) kind: &'static str,
664+
pub(crate) path: String,
665+
}
666+
657667
#[derive(Diagnostic)]
658668
#[diag(resolve_cannot_be_reexported_private, code = "E0364")]
659669
pub(crate) struct CannotBeReexportedPrivate {

compiler/rustc_resolve/src/macros.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//! interface provided by `Resolver` to macro expander.
33
44
use crate::errors::{
5-
self, AddAsNonDerive, CannotFindIdentInThisScope, MacroExpectedFound, RemoveSurroundingDerive,
5+
self, AddAsNonDerive, CannotDetermineMacroResolution, CannotFindIdentInThisScope,
6+
MacroExpectedFound, RemoveSurroundingDerive,
67
};
78
use crate::Namespace::*;
89
use crate::{BuiltinMacroState, Determinacy};
@@ -719,13 +720,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
719720
// even if speculative `resolve_path` returned nothing previously, so we skip this
720721
// less informative error if the privacy error is reported elsewhere.
721722
if this.privacy_errors.is_empty() {
722-
let msg = format!(
723-
"cannot determine resolution for the {} `{}`",
724-
kind.descr(),
725-
Segment::names_to_string(path)
726-
);
727-
let msg_note = "import resolution is stuck, try simplifying macro imports";
728-
this.tcx.sess.struct_span_err(span, msg).note(msg_note).emit();
723+
this.tcx.sess.emit_err(CannotDetermineMacroResolution {
724+
span,
725+
kind: kind.descr(),
726+
path: Segment::names_to_string(path),
727+
});
729728
}
730729
}
731730
};

0 commit comments

Comments
 (0)