1
Fork 0

Remove register_attr feature

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
This commit is contained in:
Yuki Okushi 2022-08-28 21:23:23 +09:00
parent d5ef528beb
commit 76dd5c58a0
No known key found for this signature in database
8 changed files with 14 additions and 62 deletions

View file

@ -479,8 +479,6 @@ declare_features! (
(incomplete, raw_dylib, "1.40.0", Some(58713), None), (incomplete, raw_dylib, "1.40.0", Some(58713), None),
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions. /// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
(active, raw_ref_op, "1.41.0", Some(64490), None), (active, raw_ref_op, "1.41.0", Some(64490), None),
/// Allows using the `#[register_attr]` attribute.
(active, register_attr, "1.41.0", Some(66080), None),
/// Allows using the `#[register_tool]` attribute. /// Allows using the `#[register_tool]` attribute.
(active, register_tool, "1.41.0", Some(66079), None), (active, register_tool, "1.41.0", Some(66079), None),
/// Allows the `#[repr(i128)]` attribute for enums. /// Allows the `#[repr(i128)]` attribute for enums.

View file

@ -458,10 +458,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
), ),
gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)), gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)),
gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)), gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
gated!(
register_attr, CrateLevel, template!(List: "attr1, attr2, ..."), DuplicatesOk,
experimental!(register_attr),
),
gated!( gated!(
register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk, register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
experimental!(register_tool), experimental!(register_tool),

View file

@ -163,6 +163,9 @@ declare_features! (
(removed, quad_precision_float, "1.0.0", None, None, None), (removed, quad_precision_float, "1.0.0", None, None, None),
(removed, quote, "1.33.0", Some(29601), None, None), (removed, quote, "1.33.0", Some(29601), None, None),
(removed, reflect, "1.0.0", Some(27749), None, None), (removed, reflect, "1.0.0", Some(27749), None, None),
/// Allows using the `#[register_attr]` attribute.
(removed, register_attr, "CURRENT_RUSTC_VERSION", Some(66080), None,
Some("removed in favor of `#![register_tool]`")),
/// Allows using the macros: /// Allows using the macros:
/// + `__diagnostic_used` /// + `__diagnostic_used`
/// + `__register_diagnostic` /// + `__register_diagnostic`

View file

@ -45,8 +45,6 @@ pub enum NonMacroAttrKind {
/// Single-segment custom attribute registered by a derive macro /// Single-segment custom attribute registered by a derive macro
/// but used before that derive macro was expanded (deprecated). /// but used before that derive macro was expanded (deprecated).
DeriveHelperCompat, DeriveHelperCompat,
/// Single-segment custom attribute registered with `#[register_attr]`.
Registered,
} }
/// What kind of definition something is; e.g., `mod` vs `struct`. /// What kind of definition something is; e.g., `mod` vs `struct`.
@ -564,15 +562,11 @@ impl NonMacroAttrKind {
NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => { NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => {
"derive helper attribute" "derive helper attribute"
} }
NonMacroAttrKind::Registered => "explicitly registered attribute",
} }
} }
pub fn article(self) -> &'static str { pub fn article(self) -> &'static str {
match self { "a"
NonMacroAttrKind::Registered => "an",
_ => "a",
}
} }
/// Users of some attributes cannot mark them as used, so they are considered always used. /// Users of some attributes cannot mark them as used, so they are considered always used.
@ -581,7 +575,7 @@ impl NonMacroAttrKind {
NonMacroAttrKind::Tool NonMacroAttrKind::Tool
| NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelper
| NonMacroAttrKind::DeriveHelperCompat => true, | NonMacroAttrKind::DeriveHelperCompat => true,
NonMacroAttrKind::Builtin(..) | NonMacroAttrKind::Registered => false, NonMacroAttrKind::Builtin(..) => false,
} }
} }
} }

View file

@ -1172,16 +1172,6 @@ impl<'a> Resolver<'a> {
Scope::Module(module, _) => { Scope::Module(module, _) => {
this.add_module_candidates(module, &mut suggestions, filter_fn); this.add_module_candidates(module, &mut suggestions, filter_fn);
} }
Scope::RegisteredAttrs => {
let res = Res::NonMacroAttr(NonMacroAttrKind::Registered);
if filter_fn(res) {
suggestions.extend(
this.registered_attrs
.iter()
.map(|ident| TypoSuggestion::typo_from_res(ident.name, res)),
);
}
}
Scope::MacroUsePrelude => { Scope::MacroUsePrelude => {
suggestions.extend(this.macro_use_prelude.iter().filter_map( suggestions.extend(this.macro_use_prelude.iter().filter_map(
|(name, binding)| { |(name, binding)| {

View file

@ -127,7 +127,6 @@ impl<'a> Resolver<'a> {
} }
Scope::CrateRoot => true, Scope::CrateRoot => true,
Scope::Module(..) => true, Scope::Module(..) => true,
Scope::RegisteredAttrs => use_prelude,
Scope::MacroUsePrelude => use_prelude || rust_2015, Scope::MacroUsePrelude => use_prelude || rust_2015,
Scope::BuiltinAttrs => true, Scope::BuiltinAttrs => true,
Scope::ExternPrelude => use_prelude || is_absolute_path, Scope::ExternPrelude => use_prelude || is_absolute_path,
@ -187,12 +186,11 @@ impl<'a> Resolver<'a> {
match ns { match ns {
TypeNS => Scope::ExternPrelude, TypeNS => Scope::ExternPrelude,
ValueNS => Scope::StdLibPrelude, ValueNS => Scope::StdLibPrelude,
MacroNS => Scope::RegisteredAttrs, MacroNS => Scope::MacroUsePrelude,
} }
} }
} }
} }
Scope::RegisteredAttrs => Scope::MacroUsePrelude,
Scope::MacroUsePrelude => Scope::StdLibPrelude, Scope::MacroUsePrelude => Scope::StdLibPrelude,
Scope::BuiltinAttrs => break, // nowhere else to search Scope::BuiltinAttrs => break, // nowhere else to search
Scope::ExternPrelude if is_absolute_path => break, Scope::ExternPrelude if is_absolute_path => break,
@ -556,14 +554,6 @@ impl<'a> Resolver<'a> {
Err((Determinacy::Determined, _)) => Err(Determinacy::Determined), Err((Determinacy::Determined, _)) => Err(Determinacy::Determined),
} }
} }
Scope::RegisteredAttrs => match this.registered_attrs.get(&ident).cloned() {
Some(ident) => ok(
Res::NonMacroAttr(NonMacroAttrKind::Registered),
ident.span,
this.arenas,
),
None => Err(Determinacy::Determined),
},
Scope::MacroUsePrelude => { Scope::MacroUsePrelude => {
match this.macro_use_prelude.get(&ident.name).cloned() { match this.macro_use_prelude.get(&ident.name).cloned() {
Some(binding) => Ok((binding, Flags::MISC_FROM_PRELUDE)), Some(binding) => Ok((binding, Flags::MISC_FROM_PRELUDE)),

View file

@ -107,7 +107,6 @@ enum Scope<'a> {
// The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK` // The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK`
// lint if it should be reported. // lint if it should be reported.
Module(Module<'a>, Option<NodeId>), Module(Module<'a>, Option<NodeId>),
RegisteredAttrs,
MacroUsePrelude, MacroUsePrelude,
BuiltinAttrs, BuiltinAttrs,
ExternPrelude, ExternPrelude,
@ -975,7 +974,6 @@ pub struct Resolver<'a> {
/// A small map keeping true kinds of built-in macros that appear to be fn-like on /// A small map keeping true kinds of built-in macros that appear to be fn-like on
/// the surface (`macro` items in libcore), but are actually attributes or derives. /// the surface (`macro` items in libcore), but are actually attributes or derives.
builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>, builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
registered_attrs: FxHashSet<Ident>,
registered_tools: RegisteredTools, registered_tools: RegisteredTools,
macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>, macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>,
macro_map: FxHashMap<DefId, MacroData>, macro_map: FxHashMap<DefId, MacroData>,
@ -1252,8 +1250,7 @@ impl<'a> Resolver<'a> {
} }
} }
let (registered_attrs, registered_tools) = let registered_tools = macros::registered_tools(session, &krate.attrs);
macros::registered_attrs_and_tools(session, &krate.attrs);
let features = session.features_untracked(); let features = session.features_untracked();
@ -1318,7 +1315,6 @@ impl<'a> Resolver<'a> {
macro_names: FxHashSet::default(), macro_names: FxHashSet::default(),
builtin_macros: Default::default(), builtin_macros: Default::default(),
builtin_macro_kinds: Default::default(), builtin_macro_kinds: Default::default(),
registered_attrs,
registered_tools, registered_tools,
macro_use_prelude: FxHashMap::default(), macro_use_prelude: FxHashMap::default(),
macro_map: FxHashMap::default(), macro_map: FxHashMap::default(),

View file

@ -112,47 +112,32 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
} }
} }
/// The code common between processing `#![register_tool]` and `#![register_attr]`. pub(crate) fn registered_tools(sess: &Session, attrs: &[ast::Attribute]) -> FxHashSet<Ident> {
fn registered_idents( let mut registered_tools = FxHashSet::default();
sess: &Session, for attr in sess.filter_by_name(attrs, sym::register_tool) {
attrs: &[ast::Attribute],
attr_name: Symbol,
descr: &str,
) -> FxHashSet<Ident> {
let mut registered = FxHashSet::default();
for attr in sess.filter_by_name(attrs, attr_name) {
for nested_meta in attr.meta_item_list().unwrap_or_default() { for nested_meta in attr.meta_item_list().unwrap_or_default() {
match nested_meta.ident() { match nested_meta.ident() {
Some(ident) => { Some(ident) => {
if let Some(old_ident) = registered.replace(ident) { if let Some(old_ident) = registered_tools.replace(ident) {
let msg = format!("{} `{}` was already registered", descr, ident); let msg = format!("{} `{}` was already registered", "tool", ident);
sess.struct_span_err(ident.span, &msg) sess.struct_span_err(ident.span, &msg)
.span_label(old_ident.span, "already registered here") .span_label(old_ident.span, "already registered here")
.emit(); .emit();
} }
} }
None => { None => {
let msg = format!("`{}` only accepts identifiers", attr_name); let msg = format!("`{}` only accepts identifiers", sym::register_tool);
let span = nested_meta.span(); let span = nested_meta.span();
sess.struct_span_err(span, &msg).span_label(span, "not an identifier").emit(); sess.struct_span_err(span, &msg).span_label(span, "not an identifier").emit();
} }
} }
} }
} }
registered
}
pub(crate) fn registered_attrs_and_tools(
sess: &Session,
attrs: &[ast::Attribute],
) -> (FxHashSet<Ident>, FxHashSet<Ident>) {
let registered_attrs = registered_idents(sess, attrs, sym::register_attr, "attribute");
let mut registered_tools = registered_idents(sess, attrs, sym::register_tool, "tool");
// We implicitly add `rustfmt` and `clippy` to known tools, // We implicitly add `rustfmt` and `clippy` to known tools,
// but it's not an error to register them explicitly. // but it's not an error to register them explicitly.
let predefined_tools = [sym::clippy, sym::rustfmt]; let predefined_tools = [sym::clippy, sym::rustfmt];
registered_tools.extend(predefined_tools.iter().cloned().map(Ident::with_dummy_span)); registered_tools.extend(predefined_tools.iter().cloned().map(Ident::with_dummy_span));
(registered_attrs, registered_tools) registered_tools
} }
// Some feature gates for inner attributes are reported as lints for backward compatibility. // Some feature gates for inner attributes are reported as lints for backward compatibility.