Skip to content

Commit 9ff4ffb

Browse files
committed
Update builtin tool list
1 parent b7e194e commit 9ff4ffb

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ use std::sync::OnceLock;
1212

1313
use rustc_hash::FxHashMap;
1414

15-
/// Ignored attribute namespaces used by tools.
16-
pub const TOOL_MODULES: &[&str] = &["rustfmt", "clippy"];
17-
1815
pub struct BuiltinAttribute {
1916
pub name: &'static str,
2017
pub template: AttributeTemplate,

src/tools/rust-analyzer/crates/hir-def/src/nameres.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ use crate::{
8484
LocalModuleId, Lookup, MacroExpander, MacroId, ModuleId, ProcMacroId, UseId,
8585
};
8686

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+
8795
/// Contains the results of (early) name resolution.
8896
///
8997
/// A `DefMap` stores the module tree and the definitions that are in scope in every module after
@@ -160,7 +168,7 @@ impl DefMapCrateData {
160168
fn_proc_macro_mapping: FxHashMap::default(),
161169
proc_macro_loading_error: None,
162170
registered_attrs: Vec::new(),
163-
registered_tools: Vec::new(),
171+
registered_tools: PREDEFINED_TOOLS.into(),
164172
unstable_features: FxHashSet::default(),
165173
rustc_coherence_is_core: false,
166174
no_core: false,

src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use syntax::{ast, SmolStr};
1010
use triomphe::Arc;
1111

1212
use crate::{
13-
attr::builtin::{find_builtin_attr_idx, TOOL_MODULES},
13+
attr::builtin::find_builtin_attr_idx,
1414
db::DefDatabase,
1515
item_scope::BuiltinShadowMode,
1616
nameres::path_resolution::ResolveMode,
@@ -82,8 +82,7 @@ impl DefMap {
8282
let name = name.to_smol_str();
8383
let pred = |n: &_| *n == name;
8484

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);
8786
// FIXME: tool modules can be shadowed by actual modules
8887
if is_tool {
8988
return true;

src/tools/rust-analyzer/crates/hir/src/lib.rs

+5-18
Original file line numberDiff line numberDiff line change
@@ -3372,34 +3372,21 @@ impl BuiltinAttr {
33723372

33733373
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
33743374
pub struct ToolModule {
3375-
krate: Option<CrateId>,
3375+
krate: CrateId,
33763376
idx: u32,
33773377
}
33783378

33793379
impl ToolModule {
3380-
// FIXME: consider crates\hir_def\src\nameres\attr_resolution.rs?
33813380
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;
33853382
let idx =
3386-
db.crate_def_map(krate.id).registered_tools().iter().position(|it| it == name)? as u32;
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| tool == name)
3394-
.map(|idx| ToolModule { krate: None, idx: idx as u32 })
3383+
db.crate_def_map(krate).registered_tools().iter().position(|it| it == name)? as u32;
3384+
Some(ToolModule { krate, idx })
33953385
}
33963386

33973387
pub fn name(&self, db: &dyn HirDatabase) -> SmolStr {
33983388
// 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()
34033390
}
34043391
}
34053392

0 commit comments

Comments
 (0)