Update builtin tool list · rust-lang/rust@9ff4ffb (original) (raw)

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -12,9 +12,6 @@ use std::sync::OnceLock;
12 12
13 13 use rustc_hash::FxHashMap;
14 14
15 -/// Ignored attribute namespaces used by tools.
16 -pub const TOOL_MODULES: &[&str] = &["rustfmt", "clippy"];
17 -
18 15 pub struct BuiltinAttribute {
19 16 pub name: &'static str,
20 17 pub template: AttributeTemplate,
Original file line number Diff line number Diff line change
@@ -84,6 +84,14 @@ use crate::{
84 84 LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
85 85 };
86 86
87 +const PREDEFINED_TOOLS: &[SmolStr] = &[
88 +SmolStr::new_static("clippy"),
89 +SmolStr::new_static("rustfmt"),
90 +SmolStr::new_static("diagnostic"),
91 +SmolStr::new_static("miri"),
92 +SmolStr::new_static("rust_analyzer"),
93 +];
94 +
87 95 /// Contains the results of (early) name resolution.
88 96 ///
89 97 /// A `DefMap` stores the module tree and the definitions that are in scope in every module after
@@ -160,7 +168,7 @@ impl DefMapCrateData {
160 168 fn_proc_macro_mapping: FxHashMap::default(),
161 169 proc_macro_loading_error: None,
162 170 registered_attrs: Vec::new(),
163 -registered_tools: Vec::new(),
171 +registered_tools: PREDEFINED_TOOLS.into(),
164 172 unstable_features: FxHashSet::default(),
165 173 rustc_coherence_is_core: false,
166 174 no_core: false,
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ use syntax::{ast, SmolStr};
10 10 use triomphe::Arc;
11 11
12 12 use crate::{
13 - attr::builtin::{find_builtin_attr_idx, TOOL_MODULES},
13 + attr::builtin::find_builtin_attr_idx,
14 14 db::DefDatabase,
15 15 item_scope::BuiltinShadowMode,
16 16 nameres::path_resolution::ResolveMode,
@@ -82,8 +82,7 @@ impl DefMap {
82 82 let name = name.to_smol_str();
83 83 let pred = |n: &_
84 84
85 -let registered = self.data.registered_tools.iter().map(SmolStr::as_str);
86 -let is_tool = TOOL_MODULES.iter().copied().chain(registered).any(pred);
85 +let is_tool = self.data.registered_tools.iter().map(SmolStr::as_str).any(pred);
87 86 // FIXME: tool modules can be shadowed by actual modules
88 87 if is_tool {
89 88 return true;
Original file line number Diff line number Diff line change
@@ -3372,34 +3372,21 @@ impl BuiltinAttr {
3372 3372
3373 3373 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
3374 3374 pub struct ToolModule {
3375 -krate: Option<CrateId>,
3375 +krate: CrateId,
3376 3376 idx: u32,
3377 3377 }
3378 3378
3379 3379 impl ToolModule {
3380 -// FIXME: consider crates\hir_def\src\nameres\attr_resolution.rs?
3381 3380 pub(crate) fn by_name(db: &dyn HirDatabase, krate: Crate, name: &str) -> Option<Self> {
3382 -if let builtin @ Some(_) = Self::builtin(name) {
3383 -return builtin;
3384 -}
3381 +let krate = krate.id;
3385 3382 let idx =
3386 - db.crate_def_map(krate.id).registered_tools().iter().position(|it
3387 -Some(ToolModule { krate: Some(krate.id), idx })
3388 -}
3389 -
3390 -fn builtin(name: &str) -> Option<Self> {
3391 - hir_def::attr::builtin::TOOL_MODULES
3392 -.iter()
3393 -.position(|&tool
3394 -.map(|idx
3383 + db.crate_def_map(krate).registered_tools().iter().position(|it
3384 +Some(ToolModule { krate, idx })
3395 3385 }
3396 3386
3397 3387 pub fn name(&self, db: &dyn HirDatabase) -> SmolStr {
3398 3388 // FIXME: Return a `Name` here
3399 -match self.krate {
3400 -Some(krate) => db.crate_def_map(krate).registered_tools()[self.idx as usize].clone(),
3401 -None => SmolStr::new(hir_def::attr::builtin::TOOL_MODULES[self.idx as usize]),
3402 -}
3389 + db.crate_def_map(self.krate).registered_tools()[self.idx as usize].clone()
3403 3390 }
3404 3391 }
3405 3392