resolve: Pre-intern builtin name bindings
This commit is contained in:
parent
0b31792ef1
commit
9ce35198bf
@ -1,7 +1,5 @@
|
||||
use rustc_ast::{self as ast, NodeId};
|
||||
use rustc_feature::is_builtin_attr_name;
|
||||
use rustc_hir::def::{DefKind, Namespace, NonMacroAttrKind, PartialRes, PerNS};
|
||||
use rustc_hir::PrimTy;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::lint::builtin::PROC_MACRO_DERIVE_RESOLUTION_FALLBACK;
|
||||
@ -9,7 +7,7 @@
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::hygiene::{ExpnId, ExpnKind, LocalExpnId, MacroKind, SyntaxContext};
|
||||
use rustc_span::symbol::{kw, Ident};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::Span;
|
||||
|
||||
use crate::errors::{ParamKindInEnumDiscriminant, ParamKindInNonTrivialAnonConst};
|
||||
use crate::late::{
|
||||
@ -562,17 +560,10 @@ struct Flags: u8 {
|
||||
)),
|
||||
}
|
||||
}
|
||||
Scope::BuiltinAttrs => {
|
||||
if is_builtin_attr_name(ident.name) {
|
||||
ok(
|
||||
Res::NonMacroAttr(NonMacroAttrKind::Builtin(ident.name)),
|
||||
DUMMY_SP,
|
||||
this.arenas,
|
||||
)
|
||||
} else {
|
||||
Err(Determinacy::Determined)
|
||||
}
|
||||
}
|
||||
Scope::BuiltinAttrs => match this.builtin_attrs_bindings.get(&ident.name) {
|
||||
Some(binding) => Ok((*binding, Flags::empty())),
|
||||
None => Err(Determinacy::Determined),
|
||||
},
|
||||
Scope::ExternPrelude => {
|
||||
match this.extern_prelude_get(ident, finalize.is_some()) {
|
||||
Some(binding) => Ok((binding, Flags::empty())),
|
||||
@ -603,8 +594,8 @@ struct Flags: u8 {
|
||||
}
|
||||
result
|
||||
}
|
||||
Scope::BuiltinTypes => match PrimTy::from_name(ident.name) {
|
||||
Some(prim_ty) => ok(Res::PrimTy(prim_ty), DUMMY_SP, this.arenas),
|
||||
Scope::BuiltinTypes => match this.builtin_types_bindings.get(&ident.name) {
|
||||
Some(binding) => Ok((*binding, Flags::empty())),
|
||||
None => Err(Determinacy::Determined),
|
||||
},
|
||||
};
|
||||
|
@ -39,13 +39,15 @@
|
||||
Applicability, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, SubdiagnosticMessage,
|
||||
};
|
||||
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
|
||||
use rustc_feature::BUILTIN_ATTRIBUTES;
|
||||
use rustc_fluent_macro::fluent_messages;
|
||||
use rustc_hir::def::Namespace::{self, *};
|
||||
use rustc_hir::def::NonMacroAttrKind;
|
||||
use rustc_hir::def::{self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, PartialRes, PerNS};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, LocalDefIdSet};
|
||||
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::DefPathData;
|
||||
use rustc_hir::TraitCandidate;
|
||||
use rustc_hir::{PrimTy, TraitCandidate};
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_metadata::creader::{CStore, CrateLoader};
|
||||
use rustc_middle::metadata::ModChild;
|
||||
@ -996,6 +998,8 @@ pub struct Resolver<'a, 'tcx> {
|
||||
|
||||
arenas: &'a ResolverArenas<'a>,
|
||||
dummy_binding: NameBinding<'a>,
|
||||
builtin_types_bindings: FxHashMap<Symbol, NameBinding<'a>>,
|
||||
builtin_attrs_bindings: FxHashMap<Symbol, NameBinding<'a>>,
|
||||
|
||||
used_extern_options: FxHashSet<Symbol>,
|
||||
macro_names: FxHashSet<Ident>,
|
||||
@ -1283,6 +1287,7 @@ pub fn new(
|
||||
let registered_tools = tcx.registered_tools(());
|
||||
|
||||
let features = tcx.features();
|
||||
let pub_vis = ty::Visibility::<DefId>::Public;
|
||||
|
||||
let mut resolver = Resolver {
|
||||
tcx,
|
||||
@ -1330,14 +1335,24 @@ pub fn new(
|
||||
macro_expanded_macro_export_errors: BTreeSet::new(),
|
||||
|
||||
arenas,
|
||||
dummy_binding: arenas.alloc_name_binding(NameBindingData {
|
||||
kind: NameBindingKind::Res(Res::Err),
|
||||
ambiguity: None,
|
||||
warn_ambiguity: false,
|
||||
expansion: LocalExpnId::ROOT,
|
||||
span: DUMMY_SP,
|
||||
vis: ty::Visibility::Public,
|
||||
}),
|
||||
dummy_binding: (Res::Err, pub_vis, DUMMY_SP, LocalExpnId::ROOT).to_name_binding(arenas),
|
||||
builtin_types_bindings: PrimTy::ALL
|
||||
.iter()
|
||||
.map(|prim_ty| {
|
||||
let binding = (Res::PrimTy(*prim_ty), pub_vis, DUMMY_SP, LocalExpnId::ROOT)
|
||||
.to_name_binding(arenas);
|
||||
(prim_ty.name(), binding)
|
||||
})
|
||||
.collect(),
|
||||
builtin_attrs_bindings: BUILTIN_ATTRIBUTES
|
||||
.iter()
|
||||
.map(|builtin_attr| {
|
||||
let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin(builtin_attr.name));
|
||||
let binding =
|
||||
(res, pub_vis, DUMMY_SP, LocalExpnId::ROOT).to_name_binding(arenas);
|
||||
(builtin_attr.name, binding)
|
||||
})
|
||||
.collect(),
|
||||
|
||||
used_extern_options: Default::default(),
|
||||
macro_names: FxHashSet::default(),
|
||||
|
Loading…
Reference in New Issue
Block a user