summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_resolve/src/macros.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_resolve/src/macros.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_resolve/src/macros.rs')
-rw-r--r--compiler/rustc_resolve/src/macros.rs41
1 files changed, 27 insertions, 14 deletions
diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs
index df5c16a93..d16b7902f 100644
--- a/compiler/rustc_resolve/src/macros.rs
+++ b/compiler/rustc_resolve/src/macros.rs
@@ -1,12 +1,15 @@
//! A bunch of methods and structures more or less related to resolving macros and
//! interface provided by `Resolver` to macro expander.
-use crate::errors::{self, AddAsNonDerive, MacroExpectedFound, RemoveSurroundingDerive};
+use crate::errors::{
+ self, AddAsNonDerive, CannotFindIdentInThisScope, MacroExpectedFound, RemoveSurroundingDerive,
+};
use crate::Namespace::*;
use crate::{BuiltinMacroState, Determinacy};
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
use crate::{ModuleKind, ModuleOrUniformRoot, NameBinding, PathResult, Segment};
-use rustc_ast::{self as ast, attr, Inline, ItemKind, ModKind, NodeId};
+use rustc_ast::expand::StrippedCfgItem;
+use rustc_ast::{self as ast, attr, Crate, Inline, ItemKind, ModKind, NodeId};
use rustc_ast_pretty::pprust;
use rustc_attr::StabilityLevel;
use rustc_data_structures::intern::Interned;
@@ -39,7 +42,7 @@ type Res = def::Res<NodeId>;
/// Not modularized, can shadow previous `macro_rules` bindings, etc.
#[derive(Debug)]
pub(crate) struct MacroRulesBinding<'a> {
- pub(crate) binding: &'a NameBinding<'a>,
+ pub(crate) binding: NameBinding<'a>,
/// `macro_rules` scope into which the `macro_rules` item was planted.
pub(crate) parent_macro_rules_scope: MacroRulesScopeRef<'a>,
pub(crate) ident: Ident,
@@ -465,6 +468,10 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
self.proc_macros.push(id)
}
+ fn append_stripped_cfg_item(&mut self, parent_node: NodeId, name: Ident, cfg: ast::MetaItem) {
+ self.stripped_cfg_items.push(StrippedCfgItem { parent_module: parent_node, name, cfg });
+ }
+
fn registered_tools(&self) -> &RegisteredTools {
&self.registered_tools
}
@@ -638,7 +645,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
res
} else {
- let scope_set = kind.map_or(ScopeSet::All(MacroNS, false), ScopeSet::Macro);
+ let scope_set = kind.map_or(ScopeSet::All(MacroNS), ScopeSet::Macro);
let binding = self.early_resolve_ident_in_lexical_scope(
path[0].ident,
scope_set,
@@ -669,7 +676,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
res.map(|res| (self.get_macro(res).map(|macro_data| macro_data.ext), res))
}
- pub(crate) fn finalize_macro_resolutions(&mut self) {
+ pub(crate) fn finalize_macro_resolutions(&mut self, krate: &Crate) {
let check_consistency = |this: &mut Self,
path: &[Segment],
span,
@@ -721,7 +728,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
path_res @ (PathResult::NonModule(..) | PathResult::Failed { .. }) => {
let mut suggestion = None;
- let (span, label) = if let PathResult::Failed { span, label, .. } = path_res {
+ let (span, label, module) = if let PathResult::Failed { span, label, module, .. } = path_res {
// try to suggest if it's not a macro, maybe a function
if let PathResult::NonModule(partial_res) = self.maybe_resolve_path(&path, Some(ValueNS), &parent_scope)
&& partial_res.unresolved_segments() == 0 {
@@ -733,7 +740,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
Applicability::MaybeIncorrect
));
}
- (span, label)
+ (span, label, module)
} else {
(
path_span,
@@ -742,11 +749,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
kind.article(),
kind.descr()
),
+ None,
)
};
self.report_error(
span,
- ResolutionError::FailedToResolve { label, suggestion },
+ ResolutionError::FailedToResolve { last_segment: path.last().map(|segment| segment.ident.name), label, suggestion, module },
);
}
PathResult::Module(..) | PathResult::Indeterminate => unreachable!(),
@@ -787,9 +795,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}
Err(..) => {
let expected = kind.descr_expected();
- let msg = format!("cannot find {} `{}` in this scope", expected, ident);
- let mut err = self.tcx.sess.struct_span_err(ident.span, msg);
- self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident);
+
+ let mut err = self.tcx.sess.create_err(CannotFindIdentInThisScope {
+ span: ident.span,
+ expected,
+ ident,
+ });
+
+ self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident, krate);
err.emit();
}
}
@@ -827,7 +840,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if !is_allowed(feature) && !allowed_by_implication {
let lint_buffer = &mut self.lint_buffer;
let soft_handler =
- |lint, span, msg: &_| lint_buffer.buffer_lint(lint, node_id, span, msg);
+ |lint, span, msg: String| lint_buffer.buffer_lint(lint, node_id, span, msg);
stability::report_unstable(
self.tcx.sess,
feature,
@@ -846,7 +859,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let (message, lint) = stability::deprecation_message_and_lint(depr, "macro", &path);
stability::early_report_deprecation(
&mut self.lint_buffer,
- &message,
+ message,
depr.suggestion,
lint,
span,
@@ -857,7 +870,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
fn prohibit_imported_non_macro_attrs(
&self,
- binding: Option<&'a NameBinding<'a>>,
+ binding: Option<NameBinding<'a>>,
res: Option<Res>,
span: Span,
) {