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