Move hir_def::builtin_attr to hir_def::attr::builtin

This commit is contained in:
Lukas Wirth 2023-04-06 19:55:49 +02:00
parent 12b069f434
commit 3f5c9920d6
5 changed files with 12 additions and 12 deletions

View File

@ -1,5 +1,7 @@
//! A higher level attributes based on TokenTree, with also some shortcuts.
pub mod builtin;
#[cfg(test)]
mod tests;

View File

@ -19,7 +19,6 @@ pub mod db;
pub mod attr;
pub mod path;
pub mod builtin_type;
pub mod builtin_attr;
pub mod per_ns;
pub mod item_scope;

View File

@ -4,7 +4,8 @@ use hir_expand::{attrs::Attr, MacroCallId};
use syntax::{ast, SmolStr};
use crate::{
attr_macro_as_call_id, builtin_attr,
attr::builtin::{find_builtin_attr_idx, TOOL_MODULES},
attr_macro_as_call_id,
db::DefDatabase,
item_scope::BuiltinShadowMode,
macro_id_to_def_id,
@ -76,7 +77,7 @@ impl DefMap {
let pred = |n: &_| *n == name;
let registered = self.registered_tools.iter().map(SmolStr::as_str);
let is_tool = builtin_attr::TOOL_MODULES.iter().copied().chain(registered).any(pred);
let is_tool = TOOL_MODULES.iter().copied().chain(registered).any(pred);
// FIXME: tool modules can be shadowed by actual modules
if is_tool {
return true;
@ -84,8 +85,7 @@ impl DefMap {
if segments.len() == 1 {
let mut registered = self.registered_attrs.iter().map(SmolStr::as_str);
let is_inert =
builtin_attr::find_builtin_attr_idx(&name).is_some() || registered.any(pred);
let is_inert = find_builtin_attr_idx(&name).is_some() || registered.any(pred);
return is_inert;
}
}

View File

@ -109,8 +109,7 @@ pub use crate::{
pub use {
cfg::{CfgAtom, CfgExpr, CfgOptions},
hir_def::{
attr::{Attrs, AttrsWithOwner, Documentation},
builtin_attr::AttributeTemplate,
attr::{builtin::AttributeTemplate, Attrs, AttrsWithOwner, Documentation},
data::adt::StructKind,
find_path::PrefixKind,
import_map,
@ -2697,7 +2696,7 @@ impl BuiltinAttr {
}
fn builtin(name: &str) -> Option<Self> {
hir_def::builtin_attr::find_builtin_attr_idx(name)
hir_def::attr::builtin::find_builtin_attr_idx(name)
.map(|idx| BuiltinAttr { krate: None, idx: idx as u32 })
}
@ -2705,14 +2704,14 @@ impl BuiltinAttr {
// FIXME: Return a `Name` here
match self.krate {
Some(krate) => db.crate_def_map(krate).registered_attrs()[self.idx as usize].clone(),
None => SmolStr::new(hir_def::builtin_attr::INERT_ATTRIBUTES[self.idx as usize].name),
None => SmolStr::new(hir_def::attr::builtin::INERT_ATTRIBUTES[self.idx as usize].name),
}
}
pub fn template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
match self.krate {
Some(_) => None,
None => Some(hir_def::builtin_attr::INERT_ATTRIBUTES[self.idx as usize].template),
None => Some(hir_def::attr::builtin::INERT_ATTRIBUTES[self.idx as usize].template),
}
}
}
@ -2735,7 +2734,7 @@ impl ToolModule {
}
fn builtin(name: &str) -> Option<Self> {
hir_def::builtin_attr::TOOL_MODULES
hir_def::attr::builtin::TOOL_MODULES
.iter()
.position(|&tool| tool == name)
.map(|idx| ToolModule { krate: None, idx: idx as u32 })
@ -2745,7 +2744,7 @@ impl ToolModule {
// FIXME: Return a `Name` here
match self.krate {
Some(krate) => db.crate_def_map(krate).registered_tools()[self.idx as usize].clone(),
None => SmolStr::new(hir_def::builtin_attr::TOOL_MODULES[self.idx as usize]),
None => SmolStr::new(hir_def::attr::builtin::TOOL_MODULES[self.idx as usize]),
}
}
}