Skip to content

Commit d9ca6d9

Browse files
authored
Rollup merge of rust-lang#101123 - JohnTitor:rm-register-attr, r=TaKO8Ki
Remove `register_attr` feature Closes rust-lang#66080 Signed-off-by: Yuki Okushi <[email protected]>
2 parents 7a67d99 + 382fa62 commit d9ca6d9

30 files changed

+197
-568
lines changed

compiler/rustc_feature/src/active.rs

-2
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,6 @@ declare_features! (
481481
(incomplete, raw_dylib, "1.40.0", Some(58713), None),
482482
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
483483
(active, raw_ref_op, "1.41.0", Some(64490), None),
484-
/// Allows using the `#[register_attr]` attribute.
485-
(active, register_attr, "1.41.0", Some(66080), None),
486484
/// Allows using the `#[register_tool]` attribute.
487485
(active, register_tool, "1.41.0", Some(66079), None),
488486
/// Allows the `#[repr(i128)]` attribute for enums.

compiler/rustc_feature/src/builtin_attrs.rs

-4
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
458458
),
459459
gated!(ffi_pure, Normal, template!(Word), WarnFollowing, experimental!(ffi_pure)),
460460
gated!(ffi_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
461-
gated!(
462-
register_attr, CrateLevel, template!(List: "attr1, attr2, ..."), DuplicatesOk,
463-
experimental!(register_attr),
464-
),
465461
gated!(
466462
register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
467463
experimental!(register_tool),

compiler/rustc_feature/src/removed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ declare_features! (
163163
(removed, quad_precision_float, "1.0.0", None, None, None),
164164
(removed, quote, "1.33.0", Some(29601), None, None),
165165
(removed, reflect, "1.0.0", Some(27749), None, None),
166+
/// Allows using the `#[register_attr]` attribute.
167+
(removed, register_attr, "CURRENT_RUSTC_VERSION", Some(66080), None,
168+
Some("removed in favor of `#![register_tool]`")),
166169
/// Allows using the macros:
167170
/// + `__diagnostic_used`
168171
/// + `__register_diagnostic`

compiler/rustc_hir/src/def.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ pub enum NonMacroAttrKind {
4545
/// Single-segment custom attribute registered by a derive macro
4646
/// but used before that derive macro was expanded (deprecated).
4747
DeriveHelperCompat,
48-
/// Single-segment custom attribute registered with `#[register_attr]`.
49-
Registered,
5048
}
5149

5250
/// What kind of definition something is; e.g., `mod` vs `struct`.
@@ -564,15 +562,11 @@ impl NonMacroAttrKind {
564562
NonMacroAttrKind::DeriveHelper | NonMacroAttrKind::DeriveHelperCompat => {
565563
"derive helper attribute"
566564
}
567-
NonMacroAttrKind::Registered => "explicitly registered attribute",
568565
}
569566
}
570567

571568
pub fn article(self) -> &'static str {
572-
match self {
573-
NonMacroAttrKind::Registered => "an",
574-
_ => "a",
575-
}
569+
"a"
576570
}
577571

578572
/// Users of some attributes cannot mark them as used, so they are considered always used.
@@ -581,7 +575,7 @@ impl NonMacroAttrKind {
581575
NonMacroAttrKind::Tool
582576
| NonMacroAttrKind::DeriveHelper
583577
| NonMacroAttrKind::DeriveHelperCompat => true,
584-
NonMacroAttrKind::Builtin(..) | NonMacroAttrKind::Registered => false,
578+
NonMacroAttrKind::Builtin(..) => false,
585579
}
586580
}
587581
}

compiler/rustc_resolve/src/diagnostics.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1172,16 +1172,6 @@ impl<'a> Resolver<'a> {
11721172
Scope::Module(module, _) => {
11731173
this.add_module_candidates(module, &mut suggestions, filter_fn);
11741174
}
1175-
Scope::RegisteredAttrs => {
1176-
let res = Res::NonMacroAttr(NonMacroAttrKind::Registered);
1177-
if filter_fn(res) {
1178-
suggestions.extend(
1179-
this.registered_attrs
1180-
.iter()
1181-
.map(|ident| TypoSuggestion::typo_from_res(ident.name, res)),
1182-
);
1183-
}
1184-
}
11851175
Scope::MacroUsePrelude => {
11861176
suggestions.extend(this.macro_use_prelude.iter().filter_map(
11871177
|(name, binding)| {

compiler/rustc_resolve/src/ident.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ impl<'a> Resolver<'a> {
127127
}
128128
Scope::CrateRoot => true,
129129
Scope::Module(..) => true,
130-
Scope::RegisteredAttrs => use_prelude,
131130
Scope::MacroUsePrelude => use_prelude || rust_2015,
132131
Scope::BuiltinAttrs => true,
133132
Scope::ExternPrelude => use_prelude || is_absolute_path,
@@ -187,12 +186,11 @@ impl<'a> Resolver<'a> {
187186
match ns {
188187
TypeNS => Scope::ExternPrelude,
189188
ValueNS => Scope::StdLibPrelude,
190-
MacroNS => Scope::RegisteredAttrs,
189+
MacroNS => Scope::MacroUsePrelude,
191190
}
192191
}
193192
}
194193
}
195-
Scope::RegisteredAttrs => Scope::MacroUsePrelude,
196194
Scope::MacroUsePrelude => Scope::StdLibPrelude,
197195
Scope::BuiltinAttrs => break, // nowhere else to search
198196
Scope::ExternPrelude if is_absolute_path => break,
@@ -556,14 +554,6 @@ impl<'a> Resolver<'a> {
556554
Err((Determinacy::Determined, _)) => Err(Determinacy::Determined),
557555
}
558556
}
559-
Scope::RegisteredAttrs => match this.registered_attrs.get(&ident).cloned() {
560-
Some(ident) => ok(
561-
Res::NonMacroAttr(NonMacroAttrKind::Registered),
562-
ident.span,
563-
this.arenas,
564-
),
565-
None => Err(Determinacy::Determined),
566-
},
567557
Scope::MacroUsePrelude => {
568558
match this.macro_use_prelude.get(&ident.name).cloned() {
569559
Some(binding) => Ok((binding, Flags::MISC_FROM_PRELUDE)),

compiler/rustc_resolve/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ enum Scope<'a> {
107107
// The node ID is for reporting the `PROC_MACRO_DERIVE_RESOLUTION_FALLBACK`
108108
// lint if it should be reported.
109109
Module(Module<'a>, Option<NodeId>),
110-
RegisteredAttrs,
111110
MacroUsePrelude,
112111
BuiltinAttrs,
113112
ExternPrelude,
@@ -975,7 +974,6 @@ pub struct Resolver<'a> {
975974
/// A small map keeping true kinds of built-in macros that appear to be fn-like on
976975
/// the surface (`macro` items in libcore), but are actually attributes or derives.
977976
builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
978-
registered_attrs: FxHashSet<Ident>,
979977
registered_tools: RegisteredTools,
980978
macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>,
981979
macro_map: FxHashMap<DefId, MacroData>,
@@ -1252,8 +1250,7 @@ impl<'a> Resolver<'a> {
12521250
}
12531251
}
12541252

1255-
let (registered_attrs, registered_tools) =
1256-
macros::registered_attrs_and_tools(session, &krate.attrs);
1253+
let registered_tools = macros::registered_tools(session, &krate.attrs);
12571254

12581255
let features = session.features_untracked();
12591256

@@ -1318,7 +1315,6 @@ impl<'a> Resolver<'a> {
13181315
macro_names: FxHashSet::default(),
13191316
builtin_macros: Default::default(),
13201317
builtin_macro_kinds: Default::default(),
1321-
registered_attrs,
13221318
registered_tools,
13231319
macro_use_prelude: FxHashMap::default(),
13241320
macro_map: FxHashMap::default(),

compiler/rustc_resolve/src/macros.rs

+7-22
Original file line numberDiff line numberDiff line change
@@ -112,47 +112,32 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
112112
}
113113
}
114114

115-
/// The code common between processing `#![register_tool]` and `#![register_attr]`.
116-
fn registered_idents(
117-
sess: &Session,
118-
attrs: &[ast::Attribute],
119-
attr_name: Symbol,
120-
descr: &str,
121-
) -> FxHashSet<Ident> {
122-
let mut registered = FxHashSet::default();
123-
for attr in sess.filter_by_name(attrs, attr_name) {
115+
pub(crate) fn registered_tools(sess: &Session, attrs: &[ast::Attribute]) -> FxHashSet<Ident> {
116+
let mut registered_tools = FxHashSet::default();
117+
for attr in sess.filter_by_name(attrs, sym::register_tool) {
124118
for nested_meta in attr.meta_item_list().unwrap_or_default() {
125119
match nested_meta.ident() {
126120
Some(ident) => {
127-
if let Some(old_ident) = registered.replace(ident) {
128-
let msg = format!("{} `{}` was already registered", descr, ident);
121+
if let Some(old_ident) = registered_tools.replace(ident) {
122+
let msg = format!("{} `{}` was already registered", "tool", ident);
129123
sess.struct_span_err(ident.span, &msg)
130124
.span_label(old_ident.span, "already registered here")
131125
.emit();
132126
}
133127
}
134128
None => {
135-
let msg = format!("`{}` only accepts identifiers", attr_name);
129+
let msg = format!("`{}` only accepts identifiers", sym::register_tool);
136130
let span = nested_meta.span();
137131
sess.struct_span_err(span, &msg).span_label(span, "not an identifier").emit();
138132
}
139133
}
140134
}
141135
}
142-
registered
143-
}
144-
145-
pub(crate) fn registered_attrs_and_tools(
146-
sess: &Session,
147-
attrs: &[ast::Attribute],
148-
) -> (FxHashSet<Ident>, FxHashSet<Ident>) {
149-
let registered_attrs = registered_idents(sess, attrs, sym::register_attr, "attribute");
150-
let mut registered_tools = registered_idents(sess, attrs, sym::register_tool, "tool");
151136
// We implicitly add `rustfmt` and `clippy` to known tools,
152137
// but it's not an error to register them explicitly.
153138
let predefined_tools = [sym::clippy, sym::rustfmt];
154139
registered_tools.extend(predefined_tools.iter().cloned().map(Ident::with_dummy_span));
155-
(registered_attrs, registered_tools)
140+
registered_tools
156141
}
157142

158143
// Some feature gates for inner attributes are reported as lints for backward compatibility.

src/test/ui-fulldeps/issue-15778-pass.rs

-23
This file was deleted.

src/test/ui-fulldeps/issue-15778-pass.stderr

-10
This file was deleted.

src/test/ui/attributes/register-attr-tool-fail.rs

-13
This file was deleted.

src/test/ui/attributes/register-attr-tool-fail.stderr

-42
This file was deleted.

src/test/ui/attributes/register-attr-tool-import.rs

-17
This file was deleted.

src/test/ui/attributes/register-attr-tool-import.stderr

-38
This file was deleted.

src/test/ui/attributes/register-attr-tool-prelude.rs

-14
This file was deleted.

src/test/ui/attributes/register-attr-tool-prelude.stderr

-15
This file was deleted.

src/test/ui/attributes/register-attr-tool-unused.rs

-8
This file was deleted.

0 commit comments

Comments
 (0)