#![feature(nll)]
#![recursion_limit = "256"]
#![allow(rustdoc::private_intra_doc_links)]
-#![cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
+#![allow(rustc::potential_query_instability)]
#[macro_use]
extern crate tracing;
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::intern::Interned;
use rustc_data_structures::sync::Lrc;
-use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
+use rustc_errors::{struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorReported};
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
use rustc_hir::def::Namespace::*;
use rustc_hir::def::{self, CtorOf, DefKind, NonMacroAttrKind, PartialRes};
}
struct UseError<'a> {
- err: DiagnosticBuilder<'a>,
+ err: DiagnosticBuilder<'a, ErrorReported>,
/// Candidates which user could `use` to access the missing type.
candidates: Vec<ImportSuggestion>,
/// The `DefId` of the module to place the use-statements in.
)
}
- fn is_macro_def(&self) -> bool {
- matches!(self.kind, NameBindingKind::Res(Res::Def(DefKind::Macro(..), _), _))
- }
-
fn macro_kind(&self) -> Option<MacroKind> {
self.res().macro_kind()
}
crate_loader: CrateLoader<'a>,
macro_names: FxHashSet<Ident>,
builtin_macros: FxHashMap<Symbol, BuiltinMacroState>,
+ /// A small map keeping true kinds of built-in macros that appear to be fn-like on
+ /// the surface (`macro` items in libcore), but are actually attributes or derives.
+ builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
registered_attrs: FxHashSet<Ident>,
registered_tools: RegisteredTools,
macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>,
def_id
}
+
+ fn decl_macro_kind(&self, def_id: LocalDefId) -> MacroKind {
+ self.builtin_macro_kinds.get(&def_id).copied().unwrap_or(MacroKind::Bang)
+ }
}
impl<'a> Resolver<'a> {
crate_loader: CrateLoader::new(session, metadata_loader, crate_name),
macro_names: FxHashSet::default(),
builtin_macros: Default::default(),
+ builtin_macro_kinds: Default::default(),
registered_attrs,
registered_tools,
macro_use_prelude: FxHashMap::default(),
/// ```
fn add_suggestion_for_rename_of_use(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
name: Symbol,
import: &Import<'_>,
binding_span: Span,
/// as characters expected by span manipulations won't be present.
fn add_suggestion_for_duplicate_nested_use(
&self,
- err: &mut DiagnosticBuilder<'_>,
+ err: &mut Diagnostic,
import: &Import<'_>,
binding_span: Span,
) {
let ident = Ident::with_dummy_span(sym::main);
let parent_scope = &ParentScope::module(module, self);
- let name_binding = match self.resolve_ident_in_module(
+ let Ok(name_binding) = self.resolve_ident_in_module(
ModuleOrUniformRoot::Module(module),
ident,
ValueNS,
parent_scope,
false,
DUMMY_SP,
- ) {
- Ok(name_binding) => name_binding,
- _ => return,
+ ) else {
+ return;
};
let res = name_binding.res();