Skip to content

Commit 69cb0a9

Browse files
committed
Expose registered_tools directly without TyCtxt-query
1 parent 1238a20 commit 69cb0a9

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/rustc_resolve/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ mod late;
8888
mod macros;
8989
pub mod rustdoc;
9090

91+
pub use macros::registered_tools_ast;
92+
9193
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
9294

9395
#[derive(Debug)]

compiler/rustc_resolve/src/macros.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_ast::{self as ast, Crate, NodeId, attr};
1010
use rustc_ast_pretty::pprust;
1111
use rustc_attr_parsing::{AttributeKind, StabilityLevel, find_attr};
1212
use rustc_data_structures::intern::Interned;
13-
use rustc_errors::{Applicability, StashKey};
13+
use rustc_errors::{Applicability, DiagCtxtHandle, StashKey};
1414
use rustc_expand::base::{
1515
DeriveResolution, Indeterminate, ResolverExpand, SyntaxExtension, SyntaxExtensionKind,
1616
};
@@ -124,22 +124,29 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
124124
}
125125

126126
pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
127-
let mut registered_tools = RegisteredTools::default();
128127
let (_, pre_configured_attrs) = &*tcx.crate_for_resolver(()).borrow();
128+
registered_tools_ast(tcx.dcx(), pre_configured_attrs)
129+
}
130+
131+
pub fn registered_tools_ast(
132+
dcx: DiagCtxtHandle<'_>,
133+
pre_configured_attrs: &[ast::Attribute],
134+
) -> RegisteredTools {
135+
let mut registered_tools = RegisteredTools::default();
129136
for attr in attr::filter_by_name(pre_configured_attrs, sym::register_tool) {
130137
for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
131138
match meta_item_inner.ident() {
132139
Some(ident) => {
133140
if let Some(old_ident) = registered_tools.replace(ident) {
134-
tcx.dcx().emit_err(errors::ToolWasAlreadyRegistered {
141+
dcx.emit_err(errors::ToolWasAlreadyRegistered {
135142
span: ident.span,
136143
tool: ident,
137144
old_ident_span: old_ident.span,
138145
});
139146
}
140147
}
141148
None => {
142-
tcx.dcx().emit_err(errors::ToolOnlyAcceptsIdentifiers {
149+
dcx.emit_err(errors::ToolOnlyAcceptsIdentifiers {
143150
span: meta_item_inner.span(),
144151
tool: sym::register_tool,
145152
});

0 commit comments

Comments
 (0)