Skip to content

Commit

Permalink
Auto merge of rust-lang#115504 - bvanjoi:error-struct, r=cjgillot
Browse files Browse the repository at this point in the history
resolve: derive diag for undetermined macro resolution

simply for neatness.
  • Loading branch information
bors committed Sep 11, 2023
2 parents 9b72cc9 + 7bad066 commit 9a099d2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_resolve/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_resolve/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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),
});
}
}
};
Expand Down

0 comments on commit 9a099d2

Please sign in to comment.