Rollup merge of #101123 - JohnTitor:rm-register-attr, r=TaKO8Ki

Remove `register_attr` feature

Closes #66080

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
This commit is contained in:
Dylan DPC 2022-08-30 11:26:52 +05:30 committed by GitHub
commit c18292f6a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 288 additions and 659 deletions

View File

@ -479,8 +479,6 @@ declare_features! (
(incomplete, raw_dylib, "1.40.0", Some(58713), None),
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
(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.
(active, register_tool, "1.41.0", Some(66079), None),
/// 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_const, Normal, template!(Word), WarnFollowing, experimental!(ffi_const)),
gated!(
register_attr, CrateLevel, template!(List: "attr1, attr2, ..."), DuplicatesOk,
experimental!(register_attr),
),
gated!(
register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk,
experimental!(register_tool),

View File

@ -163,6 +163,9 @@ declare_features! (
(removed, quad_precision_float, "1.0.0", None, None, None),
(removed, quote, "1.33.0", Some(29601), 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:
/// + `__diagnostic_used`
/// + `__register_diagnostic`

View File

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

View File

@ -1172,16 +1172,6 @@ impl<'a> Resolver<'a> {
Scope::Module(module, _) => {
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 => {
suggestions.extend(this.macro_use_prelude.iter().filter_map(
|(name, binding)| {

View File

@ -127,7 +127,6 @@ impl<'a> Resolver<'a> {
}
Scope::CrateRoot => true,
Scope::Module(..) => true,
Scope::RegisteredAttrs => use_prelude,
Scope::MacroUsePrelude => use_prelude || rust_2015,
Scope::BuiltinAttrs => true,
Scope::ExternPrelude => use_prelude || is_absolute_path,
@ -187,12 +186,11 @@ impl<'a> Resolver<'a> {
match ns {
TypeNS => Scope::ExternPrelude,
ValueNS => Scope::StdLibPrelude,
MacroNS => Scope::RegisteredAttrs,
MacroNS => Scope::MacroUsePrelude,
}
}
}
}
Scope::RegisteredAttrs => Scope::MacroUsePrelude,
Scope::MacroUsePrelude => Scope::StdLibPrelude,
Scope::BuiltinAttrs => break, // nowhere else to search
Scope::ExternPrelude if is_absolute_path => break,
@ -556,14 +554,6 @@ impl<'a> Resolver<'a> {
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 => {
match this.macro_use_prelude.get(&ident.name).cloned() {
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`
// lint if it should be reported.
Module(Module<'a>, Option<NodeId>),
RegisteredAttrs,
MacroUsePrelude,
BuiltinAttrs,
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
/// the surface (`macro` items in libcore), but are actually attributes or derives.
builtin_macro_kinds: FxHashMap<LocalDefId, MacroKind>,
registered_attrs: FxHashSet<Ident>,
registered_tools: RegisteredTools,
macro_use_prelude: FxHashMap<Symbol, &'a NameBinding<'a>>,
macro_map: FxHashMap<DefId, MacroData>,
@ -1252,8 +1250,7 @@ impl<'a> Resolver<'a> {
}
}
let (registered_attrs, registered_tools) =
macros::registered_attrs_and_tools(session, &krate.attrs);
let registered_tools = macros::registered_tools(session, &krate.attrs);
let features = session.features_untracked();
@ -1318,7 +1315,6 @@ impl<'a> Resolver<'a> {
macro_names: FxHashSet::default(),
builtin_macros: Default::default(),
builtin_macro_kinds: Default::default(),
registered_attrs,
registered_tools,
macro_use_prelude: 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]`.
fn registered_idents(
sess: &Session,
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) {
pub(crate) fn registered_tools(sess: &Session, attrs: &[ast::Attribute]) -> FxHashSet<Ident> {
let mut registered_tools = FxHashSet::default();
for attr in sess.filter_by_name(attrs, sym::register_tool) {
for nested_meta in attr.meta_item_list().unwrap_or_default() {
match nested_meta.ident() {
Some(ident) => {
if let Some(old_ident) = registered.replace(ident) {
let msg = format!("{} `{}` was already registered", descr, ident);
if let Some(old_ident) = registered_tools.replace(ident) {
let msg = format!("{} `{}` was already registered", "tool", ident);
sess.struct_span_err(ident.span, &msg)
.span_label(old_ident.span, "already registered here")
.emit();
}
}
None => {
let msg = format!("`{}` only accepts identifiers", attr_name);
let msg = format!("`{}` only accepts identifiers", sym::register_tool);
let span = nested_meta.span();
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,
// but it's not an error to register them explicitly.
let predefined_tools = [sym::clippy, sym::rustfmt];
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.

View File

@ -1,23 +0,0 @@
// check-pass
// aux-build:lint-for-crate-rpass.rs
// ignore-stage1
// compile-flags: -D crate-not-okay
#![feature(plugin, register_attr, custom_inner_attributes)]
#![register_attr(
crate_okay,
crate_blue,
crate_red,
crate_grey,
crate_green,
)]
#![plugin(lint_for_crate_rpass)] //~ WARNING compiler plugins are deprecated
#![crate_okay]
#![crate_blue]
#![crate_red]
#![crate_grey]
#![crate_green]
fn main() {}

View File

@ -1,10 +0,0 @@
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
--> $DIR/issue-15778-pass.rs:16:1
|
LL | #![plugin(lint_for_crate_rpass)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: may be removed in a future compiler version
|
= note: `#[warn(deprecated)]` on by default
warning: 1 warning emitted

View File

@ -1,13 +0,0 @@
#![feature(register_attr)]
#![feature(register_tool)]
#![register_attr] //~ ERROR malformed `register_attr` attribute input
#![register_tool] //~ ERROR malformed `register_tool` attribute input
#![register_attr(a::b)] //~ ERROR `register_attr` only accepts identifiers
#![register_tool(a::b)] //~ ERROR `register_tool` only accepts identifiers
#![register_attr(attr, attr)] //~ ERROR attribute `attr` was already registered
#![register_tool(tool, tool)] //~ ERROR tool `tool` was already registered
fn main() {}

View File

@ -1,42 +0,0 @@
error: `register_attr` only accepts identifiers
--> $DIR/register-attr-tool-fail.rs:7:18
|
LL | #![register_attr(a::b)]
| ^^^^ not an identifier
error: attribute `attr` was already registered
--> $DIR/register-attr-tool-fail.rs:10:24
|
LL | #![register_attr(attr, attr)]
| ---- ^^^^
| |
| already registered here
error: `register_tool` only accepts identifiers
--> $DIR/register-attr-tool-fail.rs:8:18
|
LL | #![register_tool(a::b)]
| ^^^^ not an identifier
error: tool `tool` was already registered
--> $DIR/register-attr-tool-fail.rs:11:24
|
LL | #![register_tool(tool, tool)]
| ---- ^^^^
| |
| already registered here
error: malformed `register_attr` attribute input
--> $DIR/register-attr-tool-fail.rs:4:1
|
LL | #![register_attr]
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#![register_attr(attr1, attr2, ...)]`
error: malformed `register_tool` attribute input
--> $DIR/register-attr-tool-fail.rs:5:1
|
LL | #![register_tool]
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#![register_tool(tool1, tool2, ...)]`
error: aborting due to 6 previous errors

View File

@ -1,17 +0,0 @@
// edition:2018
// compile-flags: -Zsave-analysis
// ~^ Also regression test for #69588
#![feature(register_attr)]
#![feature(register_tool)]
#![register_attr(attr)]
#![register_tool(tool)]
use attr as renamed_attr; // OK
use tool as renamed_tool; // OK
#[renamed_attr] //~ ERROR cannot use an explicitly registered attribute through an import
#[renamed_tool::attr] //~ ERROR cannot use a tool module through an import
//~| ERROR cannot use a tool module through an import
fn main() {}

View File

@ -1,38 +0,0 @@
error: cannot use an explicitly registered attribute through an import
--> $DIR/register-attr-tool-import.rs:14:3
|
LL | #[renamed_attr]
| ^^^^^^^^^^^^
|
note: the explicitly registered attribute imported here
--> $DIR/register-attr-tool-import.rs:11:5
|
LL | use attr as renamed_attr; // OK
| ^^^^^^^^^^^^^^^^^^^^
error: cannot use a tool module through an import
--> $DIR/register-attr-tool-import.rs:15:3
|
LL | #[renamed_tool::attr]
| ^^^^^^^^^^^^
|
note: the tool module imported here
--> $DIR/register-attr-tool-import.rs:12:5
|
LL | use tool as renamed_tool; // OK
| ^^^^^^^^^^^^^^^^^^^^
error: cannot use a tool module through an import
--> $DIR/register-attr-tool-import.rs:15:3
|
LL | #[renamed_tool::attr]
| ^^^^^^^^^^^^
|
note: the tool module imported here
--> $DIR/register-attr-tool-import.rs:12:5
|
LL | use tool as renamed_tool; // OK
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors

View File

@ -1,14 +0,0 @@
#![feature(register_attr)]
#![feature(register_tool)]
#![register_attr(attr)]
#![register_tool(tool)]
#[no_implicit_prelude]
mod m {
#[attr] //~ ERROR cannot find attribute `attr` in this scope
#[tool::attr] //~ ERROR failed to resolve: use of undeclared crate or module `tool`
fn check() {}
}
fn main() {}

View File

@ -1,15 +0,0 @@
error[E0433]: failed to resolve: use of undeclared crate or module `tool`
--> $DIR/register-attr-tool-prelude.rs:10:7
|
LL | #[tool::attr]
| ^^^^ use of undeclared crate or module `tool`
error: cannot find attribute `attr` in this scope
--> $DIR/register-attr-tool-prelude.rs:9:7
|
LL | #[attr]
| ^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0433`.

View File

@ -1,8 +0,0 @@
#![deny(unused)]
#![feature(register_attr)]
#![feature(register_tool)]
#[register_attr(attr)] //~ ERROR crate-level attribute should be an inner attribute
#[register_tool(tool)] //~ ERROR crate-level attribute should be an inner attribute
fn main() {}

View File

@ -1,21 +0,0 @@
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
--> $DIR/register-attr-tool-unused.rs:6:1
|
LL | #[register_attr(attr)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/register-attr-tool-unused.rs:1:9
|
LL | #![deny(unused)]
| ^^^^^^
= note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]`
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
--> $DIR/register-attr-tool-unused.rs:7:1
|
LL | #[register_tool(tool)]
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors

View File

@ -1,19 +0,0 @@
// check-pass
// compile-flags: --cfg foo
#![feature(register_attr)]
#![feature(register_tool)]
#![register_attr(attr)]
#![register_tool(tool)]
#![register_tool(rustfmt, clippy)] // OK
#![cfg_attr(foo, register_attr(conditional_attr))]
#![cfg_attr(foo, register_tool(conditional_tool))]
#[attr]
#[tool::attr]
#[rustfmt::attr]
#[clippy::attr]
#[conditional_attr]
#[conditional_tool::attr]
fn main() {}

View File

@ -1,3 +0,0 @@
#![register_attr(attr)] //~ ERROR the `#[register_attr]` attribute is an experimental feature
fn main() {}

View File

@ -1,12 +0,0 @@
error[E0658]: the `#[register_attr]` attribute is an experimental feature
--> $DIR/feature-gate-register_attr.rs:1:1
|
LL | #![register_attr(attr)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #66080 <https://github.com/rust-lang/rust/issues/66080> for more information
= help: add `#![feature(register_attr)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,17 +0,0 @@
// aux-build:derive-unstable-2.rs
#![feature(register_attr)]
#![register_attr(rustc_foo)]
#[macro_use]
extern crate derive_unstable_2;
#[derive(Unstable)]
//~^ ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler
struct A;
fn main() {
foo();
}

View File

@ -1,10 +0,0 @@
error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
--> $DIR/expand-to-unstable-2.rs:10:10
|
LL | #[derive(Unstable)]
| ^^^^^^^^
|
= note: this error originates in the derive macro `Unstable` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error

View File

@ -1,3 +1,4 @@
// gate-test-custom_inner_attributes
// compile-flags: -Z span-debug --error-format human
// aux-build:test-macros.rs
// edition:2018

View File

@ -1,23 +1,23 @@
error: expected non-macro inner attribute, found attribute macro `print_attr`
--> $DIR/inner-attrs.rs:63:12
--> $DIR/inner-attrs.rs:64:12
|
LL | #![print_attr]
| ^^^^^^^^^^ not a non-macro inner attribute
error: expected non-macro inner attribute, found attribute macro `print_attr`
--> $DIR/inner-attrs.rs:67:12
--> $DIR/inner-attrs.rs:68:12
|
LL | #![print_attr]
| ^^^^^^^^^^ not a non-macro inner attribute
error: expected non-macro inner attribute, found attribute macro `print_attr`
--> $DIR/inner-attrs.rs:71:12
--> $DIR/inner-attrs.rs:72:12
|
LL | #![print_attr]
| ^^^^^^^^^^ not a non-macro inner attribute
error: expected non-macro inner attribute, found attribute macro `print_attr`
--> $DIR/inner-attrs.rs:75:12
--> $DIR/inner-attrs.rs:76:12
|
LL | #![print_attr]
| ^^^^^^^^^^ not a non-macro inner attribute

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +0,0 @@
// aux-build:test-macros.rs
// FIXME: https://github.com/rust-lang/rust/issues/41430
// This is a temporary regression test for the ICE reported in #41211
#![feature(custom_inner_attributes)]
#![feature(register_attr)]
#![register_attr(identity_attr)]
#![identity_attr]
//~^ ERROR `identity_attr` is ambiguous
extern crate test_macros;
use test_macros::identity_attr;
fn main() {}

View File

@ -1,22 +0,0 @@
error[E0659]: `identity_attr` is ambiguous
--> $DIR/issue-41211.rs:11:4
|
LL | #![identity_attr]
| ^^^^^^^^^^^^^ ambiguous name
|
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
note: `identity_attr` could refer to the attribute macro imported here
--> $DIR/issue-41211.rs:14:5
|
LL | use test_macros::identity_attr;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `crate::identity_attr` to refer to this attribute macro unambiguously
note: `identity_attr` could also refer to the explicitly registered attribute defined here
--> $DIR/issue-41211.rs:9:18
|
LL | #![register_attr(identity_attr)]
| ^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0659`.

View File

@ -1,12 +0,0 @@
// gate-test-custom_inner_attributes
#![feature(register_attr)]
#![register_attr(foo)]
#[foo]
mod foo {
#![foo] //~ ERROR custom inner attributes are unstable
}
fn main() {}

View File

@ -1,12 +0,0 @@
error[E0658]: custom inner attributes are unstable
--> $DIR/issue-36530.rs:9:8
|
LL | #![foo]
| ^^^
|
= note: see issue #54726 <https://github.com/rust-lang/rust/issues/54726> for more information
= help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.