mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Move hir_def::builtin_attr to hir_def::attr::builtin
This commit is contained in:
parent
12b069f434
commit
3f5c9920d6
5 changed files with 12 additions and 12 deletions
|
@ -1,5 +1,7 @@
|
||||||
//! A higher level attributes based on TokenTree, with also some shortcuts.
|
//! A higher level attributes based on TokenTree, with also some shortcuts.
|
||||||
|
|
||||||
|
pub mod builtin;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ pub mod db;
|
||||||
pub mod attr;
|
pub mod attr;
|
||||||
pub mod path;
|
pub mod path;
|
||||||
pub mod builtin_type;
|
pub mod builtin_type;
|
||||||
pub mod builtin_attr;
|
|
||||||
pub mod per_ns;
|
pub mod per_ns;
|
||||||
pub mod item_scope;
|
pub mod item_scope;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,8 @@ use hir_expand::{attrs::Attr, MacroCallId};
|
||||||
use syntax::{ast, SmolStr};
|
use syntax::{ast, SmolStr};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
attr_macro_as_call_id, builtin_attr,
|
attr::builtin::{find_builtin_attr_idx, TOOL_MODULES},
|
||||||
|
attr_macro_as_call_id,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::BuiltinShadowMode,
|
item_scope::BuiltinShadowMode,
|
||||||
macro_id_to_def_id,
|
macro_id_to_def_id,
|
||||||
|
@ -76,7 +77,7 @@ impl DefMap {
|
||||||
let pred = |n: &_| *n == name;
|
let pred = |n: &_| *n == name;
|
||||||
|
|
||||||
let registered = self.registered_tools.iter().map(SmolStr::as_str);
|
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
|
// FIXME: tool modules can be shadowed by actual modules
|
||||||
if is_tool {
|
if is_tool {
|
||||||
return true;
|
return true;
|
||||||
|
@ -84,8 +85,7 @@ impl DefMap {
|
||||||
|
|
||||||
if segments.len() == 1 {
|
if segments.len() == 1 {
|
||||||
let mut registered = self.registered_attrs.iter().map(SmolStr::as_str);
|
let mut registered = self.registered_attrs.iter().map(SmolStr::as_str);
|
||||||
let is_inert =
|
let is_inert = find_builtin_attr_idx(&name).is_some() || registered.any(pred);
|
||||||
builtin_attr::find_builtin_attr_idx(&name).is_some() || registered.any(pred);
|
|
||||||
return is_inert;
|
return is_inert;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,7 @@ pub use crate::{
|
||||||
pub use {
|
pub use {
|
||||||
cfg::{CfgAtom, CfgExpr, CfgOptions},
|
cfg::{CfgAtom, CfgExpr, CfgOptions},
|
||||||
hir_def::{
|
hir_def::{
|
||||||
attr::{Attrs, AttrsWithOwner, Documentation},
|
attr::{builtin::AttributeTemplate, Attrs, AttrsWithOwner, Documentation},
|
||||||
builtin_attr::AttributeTemplate,
|
|
||||||
data::adt::StructKind,
|
data::adt::StructKind,
|
||||||
find_path::PrefixKind,
|
find_path::PrefixKind,
|
||||||
import_map,
|
import_map,
|
||||||
|
@ -2697,7 +2696,7 @@ impl BuiltinAttr {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn builtin(name: &str) -> Option<Self> {
|
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 })
|
.map(|idx| BuiltinAttr { krate: None, idx: idx as u32 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2705,14 +2704,14 @@ impl BuiltinAttr {
|
||||||
// FIXME: Return a `Name` here
|
// FIXME: Return a `Name` here
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(krate) => db.crate_def_map(krate).registered_attrs()[self.idx as usize].clone(),
|
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> {
|
pub fn template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(_) => None,
|
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> {
|
fn builtin(name: &str) -> Option<Self> {
|
||||||
hir_def::builtin_attr::TOOL_MODULES
|
hir_def::attr::builtin::TOOL_MODULES
|
||||||
.iter()
|
.iter()
|
||||||
.position(|&tool| tool == name)
|
.position(|&tool| tool == name)
|
||||||
.map(|idx| ToolModule { krate: None, idx: idx as u32 })
|
.map(|idx| ToolModule { krate: None, idx: idx as u32 })
|
||||||
|
@ -2745,7 +2744,7 @@ impl ToolModule {
|
||||||
// FIXME: Return a `Name` here
|
// FIXME: Return a `Name` here
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(krate) => db.crate_def_map(krate).registered_tools()[self.idx as usize].clone(),
|
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]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue