Skip to content

Commit 82bf36e

Browse files
Merge pull request #20631 from Wilfred/remove_register_attr
Remove support for register_attr
2 parents a91fb2b + bca5d59 commit 82bf36e

File tree

7 files changed

+14
-62
lines changed

7 files changed

+14
-62
lines changed

crates/hir-def/src/nameres.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ struct DefMapCrateData {
192192
exported_derives: FxHashMap<MacroId, Box<[Name]>>,
193193
fn_proc_macro_mapping: FxHashMap<FunctionId, ProcMacroId>,
194194

195-
/// Custom attributes registered with `#![register_attr]`.
196-
registered_attrs: Vec<Symbol>,
197195
/// Custom tool modules registered with `#![register_tool]`.
198196
registered_tools: Vec<Symbol>,
199197
/// Unstable features of Rust enabled with `#![feature(A, B)]`.
@@ -212,7 +210,6 @@ impl DefMapCrateData {
212210
Self {
213211
exported_derives: FxHashMap::default(),
214212
fn_proc_macro_mapping: FxHashMap::default(),
215-
registered_attrs: Vec::new(),
216213
registered_tools: PREDEFINED_TOOLS.iter().map(|it| Symbol::intern(it)).collect(),
217214
unstable_features: FxHashSet::default(),
218215
rustc_coherence_is_core: false,
@@ -227,7 +224,6 @@ impl DefMapCrateData {
227224
let Self {
228225
exported_derives,
229226
fn_proc_macro_mapping,
230-
registered_attrs,
231227
registered_tools,
232228
unstable_features,
233229
rustc_coherence_is_core: _,
@@ -238,7 +234,6 @@ impl DefMapCrateData {
238234
} = self;
239235
exported_derives.shrink_to_fit();
240236
fn_proc_macro_mapping.shrink_to_fit();
241-
registered_attrs.shrink_to_fit();
242237
registered_tools.shrink_to_fit();
243238
unstable_features.shrink_to_fit();
244239
}
@@ -529,10 +524,6 @@ impl DefMap {
529524
&self.data.registered_tools
530525
}
531526

532-
pub fn registered_attrs(&self) -> &[Symbol] {
533-
&self.data.registered_attrs
534-
}
535-
536527
pub fn is_unstable_feature_enabled(&self, feature: &Symbol) -> bool {
537528
self.data.unstable_features.contains(feature)
538529
}

crates/hir-def/src/nameres/attr_resolution.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,8 @@ impl DefMap {
9090
return true;
9191
}
9292

93-
if segments.len() == 1 {
94-
if find_builtin_attr_idx(name).is_some() {
95-
return true;
96-
}
97-
if self.data.registered_attrs.iter().any(pred) {
98-
return true;
99-
}
93+
if segments.len() == 1 && find_builtin_attr_idx(name).is_some() {
94+
return true;
10095
}
10196
}
10297
false

crates/hir-def/src/nameres/collector.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,6 @@ impl<'db> DefCollector<'db> {
298298
);
299299
crate_data.unstable_features.extend(features);
300300
}
301-
() if *attr_name == sym::register_attr => {
302-
if let Some(ident) = attr.single_ident_value() {
303-
crate_data.registered_attrs.push(ident.sym.clone());
304-
cov_mark::hit!(register_attr);
305-
}
306-
}
307301
() if *attr_name == sym::register_tool => {
308302
if let Some(ident) = attr.single_ident_value() {
309303
crate_data.registered_tools.push(ident.sym.clone());

crates/hir/src/lib.rs

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,49 +4060,25 @@ impl DeriveHelper {
40604060
}
40614061
}
40624062

4063-
// FIXME: Wrong name? This is could also be a registered attribute
40644063
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
40654064
pub struct BuiltinAttr {
4066-
krate: Option<base_db::Crate>,
40674065
idx: u32,
40684066
}
40694067

40704068
impl BuiltinAttr {
4071-
// FIXME: consider crates\hir_def\src\nameres\attr_resolution.rs?
4072-
pub(crate) fn by_name(db: &dyn HirDatabase, krate: Crate, name: &str) -> Option<Self> {
4073-
if let builtin @ Some(_) = Self::builtin(name) {
4074-
return builtin;
4075-
}
4076-
let idx = crate_def_map(db, krate.id)
4077-
.registered_attrs()
4078-
.iter()
4079-
.position(|it| it.as_str() == name)? as u32;
4080-
Some(BuiltinAttr { krate: Some(krate.id), idx })
4081-
}
4082-
40834069
fn builtin(name: &str) -> Option<Self> {
40844070
hir_expand::inert_attr_macro::find_builtin_attr_idx(&Symbol::intern(name))
4085-
.map(|idx| BuiltinAttr { krate: None, idx: idx as u32 })
4071+
.map(|idx| BuiltinAttr { idx: idx as u32 })
40864072
}
40874073

4088-
pub fn name(&self, db: &dyn HirDatabase) -> Name {
4089-
match self.krate {
4090-
Some(krate) => Name::new_symbol_root(
4091-
crate_def_map(db, krate).registered_attrs()[self.idx as usize].clone(),
4092-
),
4093-
None => Name::new_symbol_root(Symbol::intern(
4094-
hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].name,
4095-
)),
4096-
}
4074+
pub fn name(&self) -> Name {
4075+
Name::new_symbol_root(Symbol::intern(
4076+
hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].name,
4077+
))
40974078
}
40984079

4099-
pub fn template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
4100-
match self.krate {
4101-
Some(_) => None,
4102-
None => {
4103-
Some(hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].template)
4104-
}
4105-
}
4080+
pub fn template(&self) -> Option<AttributeTemplate> {
4081+
Some(hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].template)
41064082
}
41074083
}
41084084

crates/hir/src/source_analyzer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,7 @@ impl<'db> SourceAnalyzer<'db> {
10621062
// in this case we have to check for inert/builtin attributes and tools and prioritize
10631063
// resolution of attributes over other namespaces
10641064
if let Some(name_ref) = path.as_single_name_ref() {
1065-
let builtin =
1066-
BuiltinAttr::by_name(db, self.resolver.krate().into(), &name_ref.text());
1065+
let builtin = BuiltinAttr::builtin(&name_ref.text());
10671066
if builtin.is_some() {
10681067
return builtin.map(|it| (PathResolution::BuiltinAttr(it), None));
10691068
}

crates/ide-db/src/defs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ impl Definition {
259259
Definition::ExternCrateDecl(it) => it.docs_with_rangemap(db),
260260

261261
Definition::BuiltinAttr(it) => {
262-
let name = it.name(db);
263-
let AttributeTemplate { word, list, name_value_str } = it.template(db)?;
262+
let name = it.name();
263+
let AttributeTemplate { word, list, name_value_str } = it.template()?;
264264
let mut docs = "Valid forms are:".to_owned();
265265
if word {
266266
format_to!(docs, "\n - #\\[{}]", name.display(db, display_target.edition));
@@ -348,7 +348,7 @@ impl Definition {
348348
Definition::Label(it) => it.name(db).display(db, display_target.edition).to_string(),
349349
Definition::ExternCrateDecl(it) => it.display(db, display_target).to_string(),
350350
Definition::BuiltinAttr(it) => {
351-
format!("#[{}]", it.name(db).display(db, display_target.edition))
351+
format!("#[{}]", it.name().display(db, display_target.edition))
352352
}
353353
Definition::ToolModule(it) => {
354354
it.name(db).display(db, display_target.edition).to_string()

crates/ide-diagnostics/src/handlers/macro_error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,13 @@ macro_rules! concat { () => {} }
144144
}
145145

146146
#[test]
147-
fn register_attr_and_tool() {
148-
cov_mark::check!(register_attr);
147+
fn register_tool() {
149148
cov_mark::check!(register_tool);
150149
check_diagnostics(
151150
r#"
152151
#![register_tool(tool)]
153-
#![register_attr(attr)]
154152
155153
#[tool::path]
156-
#[attr]
157154
struct S;
158155
"#,
159156
);

0 commit comments

Comments
 (0)