diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index b894452250c..7cae637a49d 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -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 diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 6bf79e1f28d..948aad966fa 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -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)); diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index e5008b5c07d..6975ecef1c2 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -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 { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 4662c7e5535..55b6672afb9 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -653,7 +653,6 @@ fn encode_crate_root(&mut self) -> Lazy> { 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), diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 6b375045f14..d67dc362391 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -209,7 +209,6 @@ macro_rules! Lazy { has_global_allocator: bool, has_panic_handler: bool, has_default_lib_allocator: bool, - plugin_registrar_fn: Option, crate_deps: Lazy<[CrateDep]>, dylib_dependency_formats: Lazy<[Option]>, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index b4f4bffdae7..e1d56311ae1 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -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 { + query plugin_registrar_fn(_: ()) -> Option { desc { "looking up the plugin registrar for a crate" } } query proc_macro_decls_static(_: CrateNum) -> Option { diff --git a/compiler/rustc_plugin_impl/src/build.rs b/compiler/rustc_plugin_impl/src/build.rs index a49afa35e46..b95c4a72019 100644 --- a/compiler/rustc_plugin_impl/src/build.rs +++ b/compiler/rustc_plugin_impl/src/build.rs @@ -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 { - tcx.plugin_registrar_fn(LOCAL_CRATE) -} - -fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option { - assert_eq!(cnum, LOCAL_CRATE); - +fn plugin_registrar_fn(tcx: TyCtxt<'_>, (): ()) -> Option { 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) { diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index c050bbc9b9d..afb83d08e62 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -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); }