Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve: derive diag for undetermined macro resolution #115504

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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