about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/nameres.rs9
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs9
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs6
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/lib.rs38
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs3
-rw-r--r--src/tools/rust-analyzer/crates/ide-db/src/defs.rs6
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/macro_error.rs5
7 files changed, 14 insertions, 62 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs
index bf6fc15b7d1..7d5e627964e 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres.rs
@@ -192,8 +192,6 @@ struct DefMapCrateData {
     exported_derives: FxHashMap<MacroId, Box<[Name]>>,
     fn_proc_macro_mapping: FxHashMap<FunctionId, ProcMacroId>,
 
-    /// Custom attributes registered with `#![register_attr]`.
-    registered_attrs: Vec<Symbol>,
     /// Custom tool modules registered with `#![register_tool]`.
     registered_tools: Vec<Symbol>,
     /// Unstable features of Rust enabled with `#![feature(A, B)]`.
@@ -212,7 +210,6 @@ impl DefMapCrateData {
         Self {
             exported_derives: FxHashMap::default(),
             fn_proc_macro_mapping: FxHashMap::default(),
-            registered_attrs: Vec::new(),
             registered_tools: PREDEFINED_TOOLS.iter().map(|it| Symbol::intern(it)).collect(),
             unstable_features: FxHashSet::default(),
             rustc_coherence_is_core: false,
@@ -227,7 +224,6 @@ impl DefMapCrateData {
         let Self {
             exported_derives,
             fn_proc_macro_mapping,
-            registered_attrs,
             registered_tools,
             unstable_features,
             rustc_coherence_is_core: _,
@@ -238,7 +234,6 @@ impl DefMapCrateData {
         } = self;
         exported_derives.shrink_to_fit();
         fn_proc_macro_mapping.shrink_to_fit();
-        registered_attrs.shrink_to_fit();
         registered_tools.shrink_to_fit();
         unstable_features.shrink_to_fit();
     }
@@ -529,10 +524,6 @@ impl DefMap {
         &self.data.registered_tools
     }
 
-    pub fn registered_attrs(&self) -> &[Symbol] {
-        &self.data.registered_attrs
-    }
-
     pub fn is_unstable_feature_enabled(&self, feature: &Symbol) -> bool {
         self.data.unstable_features.contains(feature)
     }
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs
index e7e96804ae7..2f56d608fcb 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/attr_resolution.rs
@@ -90,13 +90,8 @@ impl DefMap {
                 return true;
             }
 
-            if segments.len() == 1 {
-                if find_builtin_attr_idx(name).is_some() {
-                    return true;
-                }
-                if self.data.registered_attrs.iter().any(pred) {
-                    return true;
-                }
+            if segments.len() == 1 && find_builtin_attr_idx(name).is_some() {
+                return true;
             }
         }
         false
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
index 0f84728dcb4..a2ce5383565 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs
@@ -298,12 +298,6 @@ impl<'db> DefCollector<'db> {
                         );
                     crate_data.unstable_features.extend(features);
                 }
-                () if *attr_name == sym::register_attr => {
-                    if let Some(ident) = attr.single_ident_value() {
-                        crate_data.registered_attrs.push(ident.sym.clone());
-                        cov_mark::hit!(register_attr);
-                    }
-                }
                 () if *attr_name == sym::register_tool => {
                     if let Some(ident) = attr.single_ident_value() {
                         crate_data.registered_tools.push(ident.sym.clone());
diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs
index 6610375451d..6eb8a8bf60f 100644
--- a/src/tools/rust-analyzer/crates/hir/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs
@@ -4060,49 +4060,25 @@ impl DeriveHelper {
     }
 }
 
-// FIXME: Wrong name? This is could also be a registered attribute
 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
 pub struct BuiltinAttr {
-    krate: Option<base_db::Crate>,
     idx: u32,
 }
 
 impl BuiltinAttr {
-    // FIXME: consider crates\hir_def\src\nameres\attr_resolution.rs?
-    pub(crate) fn by_name(db: &dyn HirDatabase, krate: Crate, name: &str) -> Option<Self> {
-        if let builtin @ Some(_) = Self::builtin(name) {
-            return builtin;
-        }
-        let idx = crate_def_map(db, krate.id)
-            .registered_attrs()
-            .iter()
-            .position(|it| it.as_str() == name)? as u32;
-        Some(BuiltinAttr { krate: Some(krate.id), idx })
-    }
-
     fn builtin(name: &str) -> Option<Self> {
         hir_expand::inert_attr_macro::find_builtin_attr_idx(&Symbol::intern(name))
-            .map(|idx| BuiltinAttr { krate: None, idx: idx as u32 })
+            .map(|idx| BuiltinAttr { idx: idx as u32 })
     }
 
-    pub fn name(&self, db: &dyn HirDatabase) -> Name {
-        match self.krate {
-            Some(krate) => Name::new_symbol_root(
-                crate_def_map(db, krate).registered_attrs()[self.idx as usize].clone(),
-            ),
-            None => Name::new_symbol_root(Symbol::intern(
-                hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].name,
-            )),
-        }
+    pub fn name(&self) -> Name {
+        Name::new_symbol_root(Symbol::intern(
+            hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].name,
+        ))
     }
 
-    pub fn template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
-        match self.krate {
-            Some(_) => None,
-            None => {
-                Some(hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].template)
-            }
-        }
+    pub fn template(&self) -> Option<AttributeTemplate> {
+        Some(hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].template)
     }
 }
 
diff --git a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs
index dbc2539a9b9..539b25387ae 100644
--- a/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/source_analyzer.rs
@@ -1062,8 +1062,7 @@ impl<'db> SourceAnalyzer<'db> {
             // in this case we have to check for inert/builtin attributes and tools and prioritize
             // resolution of attributes over other namespaces
             if let Some(name_ref) = path.as_single_name_ref() {
-                let builtin =
-                    BuiltinAttr::by_name(db, self.resolver.krate().into(), &name_ref.text());
+                let builtin = BuiltinAttr::builtin(&name_ref.text());
                 if builtin.is_some() {
                     return builtin.map(|it| (PathResolution::BuiltinAttr(it), None));
                 }
diff --git a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs
index 61a21ccf2f7..44ff9d6006d 100644
--- a/src/tools/rust-analyzer/crates/ide-db/src/defs.rs
+++ b/src/tools/rust-analyzer/crates/ide-db/src/defs.rs
@@ -259,8 +259,8 @@ impl Definition {
             Definition::ExternCrateDecl(it) => it.docs_with_rangemap(db),
 
             Definition::BuiltinAttr(it) => {
-                let name = it.name(db);
-                let AttributeTemplate { word, list, name_value_str } = it.template(db)?;
+                let name = it.name();
+                let AttributeTemplate { word, list, name_value_str } = it.template()?;
                 let mut docs = "Valid forms are:".to_owned();
                 if word {
                     format_to!(docs, "\n - #\\[{}]", name.display(db, display_target.edition));
@@ -348,7 +348,7 @@ impl Definition {
             Definition::Label(it) => it.name(db).display(db, display_target.edition).to_string(),
             Definition::ExternCrateDecl(it) => it.display(db, display_target).to_string(),
             Definition::BuiltinAttr(it) => {
-                format!("#[{}]", it.name(db).display(db, display_target.edition))
+                format!("#[{}]", it.name().display(db, display_target.edition))
             }
             Definition::ToolModule(it) => {
                 it.name(db).display(db, display_target.edition).to_string()
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/macro_error.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/macro_error.rs
index c39e00e178f..6a1ecae6515 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/macro_error.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/macro_error.rs
@@ -144,16 +144,13 @@ macro_rules! concat { () => {} }
     }
 
     #[test]
-    fn register_attr_and_tool() {
-        cov_mark::check!(register_attr);
+    fn register_tool() {
         cov_mark::check!(register_tool);
         check_diagnostics(
             r#"
 #![register_tool(tool)]
-#![register_attr(attr)]
 
 #[tool::path]
-#[attr]
 struct S;
 "#,
         );