Use () for plugin_registrar_fn.
This commit is contained in:
parent
829a9d33a9
commit
e9e1900af7
@ -137,8 +137,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
||||
reachable_non_generics.insert(id, SymbolExportLevel::C);
|
||||
}
|
||||
|
||||
if let Some(id) = tcx.plugin_registrar_fn(LOCAL_CRATE) {
|
||||
reachable_non_generics.insert(id, SymbolExportLevel::C);
|
||||
if let Some(id) = tcx.plugin_registrar_fn(()) {
|
||||
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
|
||||
}
|
||||
|
||||
reachable_non_generics
|
||||
|
@ -822,9 +822,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
|
||||
{
|
||||
entry_point = sess.time("looking_for_entry_point", || tcx.entry_fn(()));
|
||||
|
||||
sess.time("looking_for_plugin_registrar", || {
|
||||
plugin::build::find_plugin_registrar(tcx)
|
||||
});
|
||||
sess.time("looking_for_plugin_registrar", || tcx.ensure().plugin_registrar_fn(()));
|
||||
|
||||
sess.time("looking_for_derive_registrar", || proc_macro_decls::find(tcx));
|
||||
|
||||
|
@ -185,11 +185,6 @@ fn into_args(self) -> (DefId, DefId) {
|
||||
}
|
||||
native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) }
|
||||
foreign_modules => { cdata.get_foreign_modules(tcx) }
|
||||
plugin_registrar_fn => {
|
||||
cdata.root.plugin_registrar_fn.map(|index| {
|
||||
DefId { krate: def_id.krate, index }
|
||||
})
|
||||
}
|
||||
proc_macro_decls_static => {
|
||||
cdata.root.proc_macro_data.as_ref().map(|data| {
|
||||
DefId {
|
||||
|
@ -653,7 +653,6 @@ fn encode_crate_root(&mut self) -> Lazy<CrateRoot<'tcx>> {
|
||||
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
|
||||
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
|
||||
has_default_lib_allocator,
|
||||
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
|
||||
proc_macro_data,
|
||||
compiler_builtins: tcx.sess.contains_name(&attrs, sym::compiler_builtins),
|
||||
needs_allocator: tcx.sess.contains_name(&attrs, sym::needs_allocator),
|
||||
|
@ -209,7 +209,6 @@ macro_rules! Lazy {
|
||||
has_global_allocator: bool,
|
||||
has_panic_handler: bool,
|
||||
has_default_lib_allocator: bool,
|
||||
plugin_registrar_fn: Option<DefIndex>,
|
||||
|
||||
crate_deps: Lazy<[CrateDep]>,
|
||||
dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>,
|
||||
|
@ -1204,7 +1204,7 @@
|
||||
query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
|
||||
desc { "looking up the entry function of a crate" }
|
||||
}
|
||||
query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
|
||||
query plugin_registrar_fn(_: ()) -> Option<LocalDefId> {
|
||||
desc { "looking up the plugin registrar for a crate" }
|
||||
}
|
||||
query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Used by `rustc` when compiling a plugin crate.
|
||||
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
@ -31,33 +31,25 @@ fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {}
|
||||
}
|
||||
|
||||
/// Finds the function marked with `#[plugin_registrar]`, if any.
|
||||
pub fn find_plugin_registrar(tcx: TyCtxt<'_>) -> Option<DefId> {
|
||||
tcx.plugin_registrar_fn(LOCAL_CRATE)
|
||||
}
|
||||
|
||||
fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
fn plugin_registrar_fn(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
|
||||
let mut finder = RegistrarFinder { tcx, registrars: Vec::new() };
|
||||
tcx.hir().krate().visit_all_item_likes(&mut finder);
|
||||
|
||||
match finder.registrars.len() {
|
||||
0 => None,
|
||||
1 => {
|
||||
let (def_id, _) = finder.registrars.pop().unwrap();
|
||||
Some(def_id.to_def_id())
|
||||
}
|
||||
_ => {
|
||||
let diagnostic = tcx.sess.diagnostic();
|
||||
let mut e = diagnostic.struct_err("multiple plugin registration functions found");
|
||||
for &(_, span) in &finder.registrars {
|
||||
e.span_note(span, "one is here");
|
||||
}
|
||||
e.emit();
|
||||
diagnostic.abort_if_errors();
|
||||
unreachable!();
|
||||
let (def_id, span) = finder.registrars.pop()?;
|
||||
|
||||
if !finder.registrars.is_empty() {
|
||||
let diagnostic = tcx.sess.diagnostic();
|
||||
let mut e = diagnostic.struct_err("multiple plugin registration functions found");
|
||||
e.span_note(span, "one is here");
|
||||
for &(_, span) in &finder.registrars {
|
||||
e.span_note(span, "one is here");
|
||||
}
|
||||
e.emit();
|
||||
diagnostic.abort_if_errors();
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
Some(def_id)
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
|
@ -165,7 +165,7 @@ fn compute_symbol_name(
|
||||
|
||||
// FIXME(eddyb) Precompute a custom symbol name based on attributes.
|
||||
let is_foreign = if let Some(def_id) = def_id.as_local() {
|
||||
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id.to_def_id()) {
|
||||
if tcx.plugin_registrar_fn(()) == Some(def_id) {
|
||||
let disambiguator = tcx.sess.local_crate_disambiguator();
|
||||
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user