Skip to content

Commit e9e1900

Browse files
committed
Use () for plugin_registrar_fn.
1 parent 829a9d3 commit e9e1900

File tree

8 files changed

+20
-37
lines changed

8 files changed

+20
-37
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
137137
reachable_non_generics.insert(id, SymbolExportLevel::C);
138138
}
139139

140-
if let Some(id) = tcx.plugin_registrar_fn(LOCAL_CRATE) {
141-
reachable_non_generics.insert(id, SymbolExportLevel::C);
140+
if let Some(id) = tcx.plugin_registrar_fn(()) {
141+
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
142142
}
143143

144144
reachable_non_generics

compiler/rustc_interface/src/passes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
822822
{
823823
entry_point = sess.time("looking_for_entry_point", || tcx.entry_fn(()));
824824

825-
sess.time("looking_for_plugin_registrar", || {
826-
plugin::build::find_plugin_registrar(tcx)
827-
});
825+
sess.time("looking_for_plugin_registrar", || tcx.ensure().plugin_registrar_fn(()));
828826

829827
sess.time("looking_for_derive_registrar", || proc_macro_decls::find(tcx));
830828

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
185185
}
186186
native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) }
187187
foreign_modules => { cdata.get_foreign_modules(tcx) }
188-
plugin_registrar_fn => {
189-
cdata.root.plugin_registrar_fn.map(|index| {
190-
DefId { krate: def_id.krate, index }
191-
})
192-
}
193188
proc_macro_decls_static => {
194189
cdata.root.proc_macro_data.as_ref().map(|data| {
195190
DefId {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
653653
has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE),
654654
has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE),
655655
has_default_lib_allocator,
656-
plugin_registrar_fn: tcx.plugin_registrar_fn(LOCAL_CRATE).map(|id| id.index),
657656
proc_macro_data,
658657
compiler_builtins: tcx.sess.contains_name(&attrs, sym::compiler_builtins),
659658
needs_allocator: tcx.sess.contains_name(&attrs, sym::needs_allocator),

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ crate struct CrateRoot<'tcx> {
209209
has_global_allocator: bool,
210210
has_panic_handler: bool,
211211
has_default_lib_allocator: bool,
212-
plugin_registrar_fn: Option<DefIndex>,
213212

214213
crate_deps: Lazy<[CrateDep]>,
215214
dylib_dependency_formats: Lazy<[Option<LinkagePreference>]>,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ rustc_queries! {
12041204
query entry_fn(_: ()) -> Option<(DefId, EntryFnType)> {
12051205
desc { "looking up the entry function of a crate" }
12061206
}
1207-
query plugin_registrar_fn(_: CrateNum) -> Option<DefId> {
1207+
query plugin_registrar_fn(_: ()) -> Option<LocalDefId> {
12081208
desc { "looking up the plugin registrar for a crate" }
12091209
}
12101210
query proc_macro_decls_static(_: CrateNum) -> Option<DefId> {

compiler/rustc_plugin_impl/src/build.rs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Used by `rustc` when compiling a plugin crate.
22
33
use rustc_hir as hir;
4-
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
4+
use rustc_hir::def_id::LocalDefId;
55
use rustc_hir::itemlikevisit::ItemLikeVisitor;
66
use rustc_middle::ty::query::Providers;
77
use rustc_middle::ty::TyCtxt;
@@ -31,33 +31,25 @@ impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> {
3131
}
3232

3333
/// Finds the function marked with `#[plugin_registrar]`, if any.
34-
pub fn find_plugin_registrar(tcx: TyCtxt<'_>) -> Option<DefId> {
35-
tcx.plugin_registrar_fn(LOCAL_CRATE)
36-
}
37-
38-
fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> {
39-
assert_eq!(cnum, LOCAL_CRATE);
40-
34+
fn plugin_registrar_fn(tcx: TyCtxt<'_>, (): ()) -> Option<LocalDefId> {
4135
let mut finder = RegistrarFinder { tcx, registrars: Vec::new() };
4236
tcx.hir().krate().visit_all_item_likes(&mut finder);
4337

44-
match finder.registrars.len() {
45-
0 => None,
46-
1 => {
47-
let (def_id, _) = finder.registrars.pop().unwrap();
48-
Some(def_id.to_def_id())
49-
}
50-
_ => {
51-
let diagnostic = tcx.sess.diagnostic();
52-
let mut e = diagnostic.struct_err("multiple plugin registration functions found");
53-
for &(_, span) in &finder.registrars {
54-
e.span_note(span, "one is here");
55-
}
56-
e.emit();
57-
diagnostic.abort_if_errors();
58-
unreachable!();
38+
let (def_id, span) = finder.registrars.pop()?;
39+
40+
if !finder.registrars.is_empty() {
41+
let diagnostic = tcx.sess.diagnostic();
42+
let mut e = diagnostic.struct_err("multiple plugin registration functions found");
43+
e.span_note(span, "one is here");
44+
for &(_, span) in &finder.registrars {
45+
e.span_note(span, "one is here");
5946
}
47+
e.emit();
48+
diagnostic.abort_if_errors();
49+
unreachable!();
6050
}
51+
52+
Some(def_id)
6153
}
6254

6355
pub fn provide(providers: &mut Providers) {

compiler/rustc_symbol_mangling/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn compute_symbol_name(
165165

166166
// FIXME(eddyb) Precompute a custom symbol name based on attributes.
167167
let is_foreign = if let Some(def_id) = def_id.as_local() {
168-
if tcx.plugin_registrar_fn(LOCAL_CRATE) == Some(def_id.to_def_id()) {
168+
if tcx.plugin_registrar_fn(()) == Some(def_id) {
169169
let disambiguator = tcx.sess.local_crate_disambiguator();
170170
return tcx.sess.generate_plugin_registrar_symbol(disambiguator);
171171
}

0 commit comments

Comments
 (0)