Merge pull request #20631 from Wilfred/remove_register_attr
Remove support for register_attr
This commit is contained in:
commit
e665f6fbe9
7 changed files with 14 additions and 62 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
"#,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue