mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 04:18:20 +00:00
Remove support for register_attr
This was removed in rustc in 2022: https://github.com/rust-lang/rust/pull/101123 Closes #20525.
This commit is contained in:
parent
a91fb2b9a1
commit
bca5d59627
7 changed files with 14 additions and 62 deletions
|
|
@ -192,8 +192,6 @@ struct DefMapCrateData {
|
||||||
exported_derives: FxHashMap<MacroId, Box<[Name]>>,
|
exported_derives: FxHashMap<MacroId, Box<[Name]>>,
|
||||||
fn_proc_macro_mapping: FxHashMap<FunctionId, ProcMacroId>,
|
fn_proc_macro_mapping: FxHashMap<FunctionId, ProcMacroId>,
|
||||||
|
|
||||||
/// Custom attributes registered with `#![register_attr]`.
|
|
||||||
registered_attrs: Vec<Symbol>,
|
|
||||||
/// Custom tool modules registered with `#![register_tool]`.
|
/// Custom tool modules registered with `#![register_tool]`.
|
||||||
registered_tools: Vec<Symbol>,
|
registered_tools: Vec<Symbol>,
|
||||||
/// Unstable features of Rust enabled with `#![feature(A, B)]`.
|
/// Unstable features of Rust enabled with `#![feature(A, B)]`.
|
||||||
|
|
@ -212,7 +210,6 @@ impl DefMapCrateData {
|
||||||
Self {
|
Self {
|
||||||
exported_derives: FxHashMap::default(),
|
exported_derives: FxHashMap::default(),
|
||||||
fn_proc_macro_mapping: FxHashMap::default(),
|
fn_proc_macro_mapping: FxHashMap::default(),
|
||||||
registered_attrs: Vec::new(),
|
|
||||||
registered_tools: PREDEFINED_TOOLS.iter().map(|it| Symbol::intern(it)).collect(),
|
registered_tools: PREDEFINED_TOOLS.iter().map(|it| Symbol::intern(it)).collect(),
|
||||||
unstable_features: FxHashSet::default(),
|
unstable_features: FxHashSet::default(),
|
||||||
rustc_coherence_is_core: false,
|
rustc_coherence_is_core: false,
|
||||||
|
|
@ -227,7 +224,6 @@ impl DefMapCrateData {
|
||||||
let Self {
|
let Self {
|
||||||
exported_derives,
|
exported_derives,
|
||||||
fn_proc_macro_mapping,
|
fn_proc_macro_mapping,
|
||||||
registered_attrs,
|
|
||||||
registered_tools,
|
registered_tools,
|
||||||
unstable_features,
|
unstable_features,
|
||||||
rustc_coherence_is_core: _,
|
rustc_coherence_is_core: _,
|
||||||
|
|
@ -238,7 +234,6 @@ impl DefMapCrateData {
|
||||||
} = self;
|
} = self;
|
||||||
exported_derives.shrink_to_fit();
|
exported_derives.shrink_to_fit();
|
||||||
fn_proc_macro_mapping.shrink_to_fit();
|
fn_proc_macro_mapping.shrink_to_fit();
|
||||||
registered_attrs.shrink_to_fit();
|
|
||||||
registered_tools.shrink_to_fit();
|
registered_tools.shrink_to_fit();
|
||||||
unstable_features.shrink_to_fit();
|
unstable_features.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
@ -529,10 +524,6 @@ impl DefMap {
|
||||||
&self.data.registered_tools
|
&self.data.registered_tools
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn registered_attrs(&self) -> &[Symbol] {
|
|
||||||
&self.data.registered_attrs
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_unstable_feature_enabled(&self, feature: &Symbol) -> bool {
|
pub fn is_unstable_feature_enabled(&self, feature: &Symbol) -> bool {
|
||||||
self.data.unstable_features.contains(feature)
|
self.data.unstable_features.contains(feature)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,13 +90,8 @@ impl DefMap {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if segments.len() == 1 {
|
if segments.len() == 1 && find_builtin_attr_idx(name).is_some() {
|
||||||
if find_builtin_attr_idx(name).is_some() {
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if self.data.registered_attrs.iter().any(pred) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -298,12 +298,6 @@ impl<'db> DefCollector<'db> {
|
||||||
);
|
);
|
||||||
crate_data.unstable_features.extend(features);
|
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 *attr_name == sym::register_tool => {
|
||||||
if let Some(ident) = attr.single_ident_value() {
|
if let Some(ident) = attr.single_ident_value() {
|
||||||
crate_data.registered_tools.push(ident.sym.clone());
|
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)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct BuiltinAttr {
|
pub struct BuiltinAttr {
|
||||||
krate: Option<base_db::Crate>,
|
|
||||||
idx: u32,
|
idx: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuiltinAttr {
|
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> {
|
fn builtin(name: &str) -> Option<Self> {
|
||||||
hir_expand::inert_attr_macro::find_builtin_attr_idx(&Symbol::intern(name))
|
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 {
|
pub fn name(&self) -> Name {
|
||||||
match self.krate {
|
Name::new_symbol_root(Symbol::intern(
|
||||||
Some(krate) => Name::new_symbol_root(
|
hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].name,
|
||||||
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 template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
|
pub fn template(&self) -> Option<AttributeTemplate> {
|
||||||
match self.krate {
|
Some(hir_expand::inert_attr_macro::INERT_ATTRIBUTES[self.idx as usize].template)
|
||||||
Some(_) => None,
|
|
||||||
None => {
|
|
||||||
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
|
// in this case we have to check for inert/builtin attributes and tools and prioritize
|
||||||
// resolution of attributes over other namespaces
|
// resolution of attributes over other namespaces
|
||||||
if let Some(name_ref) = path.as_single_name_ref() {
|
if let Some(name_ref) = path.as_single_name_ref() {
|
||||||
let builtin =
|
let builtin = BuiltinAttr::builtin(&name_ref.text());
|
||||||
BuiltinAttr::by_name(db, self.resolver.krate().into(), &name_ref.text());
|
|
||||||
if builtin.is_some() {
|
if builtin.is_some() {
|
||||||
return builtin.map(|it| (PathResolution::BuiltinAttr(it), None));
|
return builtin.map(|it| (PathResolution::BuiltinAttr(it), None));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -259,8 +259,8 @@ impl Definition {
|
||||||
Definition::ExternCrateDecl(it) => it.docs_with_rangemap(db),
|
Definition::ExternCrateDecl(it) => it.docs_with_rangemap(db),
|
||||||
|
|
||||||
Definition::BuiltinAttr(it) => {
|
Definition::BuiltinAttr(it) => {
|
||||||
let name = it.name(db);
|
let name = it.name();
|
||||||
let AttributeTemplate { word, list, name_value_str } = it.template(db)?;
|
let AttributeTemplate { word, list, name_value_str } = it.template()?;
|
||||||
let mut docs = "Valid forms are:".to_owned();
|
let mut docs = "Valid forms are:".to_owned();
|
||||||
if word {
|
if word {
|
||||||
format_to!(docs, "\n - #\\[{}]", name.display(db, display_target.edition));
|
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::Label(it) => it.name(db).display(db, display_target.edition).to_string(),
|
||||||
Definition::ExternCrateDecl(it) => it.display(db, display_target).to_string(),
|
Definition::ExternCrateDecl(it) => it.display(db, display_target).to_string(),
|
||||||
Definition::BuiltinAttr(it) => {
|
Definition::BuiltinAttr(it) => {
|
||||||
format!("#[{}]", it.name(db).display(db, display_target.edition))
|
format!("#[{}]", it.name().display(db, display_target.edition))
|
||||||
}
|
}
|
||||||
Definition::ToolModule(it) => {
|
Definition::ToolModule(it) => {
|
||||||
it.name(db).display(db, display_target.edition).to_string()
|
it.name(db).display(db, display_target.edition).to_string()
|
||||||
|
|
|
||||||
|
|
@ -144,16 +144,13 @@ macro_rules! concat { () => {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn register_attr_and_tool() {
|
fn register_tool() {
|
||||||
cov_mark::check!(register_attr);
|
|
||||||
cov_mark::check!(register_tool);
|
cov_mark::check!(register_tool);
|
||||||
check_diagnostics(
|
check_diagnostics(
|
||||||
r#"
|
r#"
|
||||||
#![register_tool(tool)]
|
#![register_tool(tool)]
|
||||||
#![register_attr(attr)]
|
|
||||||
|
|
||||||
#[tool::path]
|
#[tool::path]
|
||||||
#[attr]
|
|
||||||
struct S;
|
struct S;
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue