From 441e5aed2501de4dcafff8c1e2442ee4145737be Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 4 Nov 2019 00:36:45 +0300 Subject: [PATCH] Remove `#[feature(custom_attribute)]` --- src/librustc/hir/def.rs | 3 -- src/librustc_plugin/registry.rs | 1 - src/librustc_resolve/macros.rs | 26 ++------------ src/libsyntax/feature_gate/active.rs | 3 -- src/libsyntax/feature_gate/removed.rs | 3 ++ src/test/ui-fulldeps/issue-15778-pass.rs | 10 +++++- src/test/ui-fulldeps/issue-15778-pass.stderr | 2 +- .../feature-gate-custom_attribute2.rs | 2 -- .../feature-gate-custom_attribute2.stderr | 34 +++++++++---------- .../ui/proc-macro/expand-to-unstable-2.rs | 4 ++- .../ui/proc-macro/expand-to-unstable-2.stderr | 2 +- src/test/ui/proc-macro/issue-41211.rs | 6 ++-- src/test/ui/proc-macro/issue-41211.stderr | 19 +++++++++-- src/test/ui/span/issue-36530.rs | 4 ++- src/test/ui/span/issue-36530.stderr | 2 +- 15 files changed, 60 insertions(+), 61 deletions(-) diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index 486d6dfb0950..9eb6baeb4ba8 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -44,8 +44,6 @@ pub enum NonMacroAttrKind { Registered, /// Single-segment custom attribute registered by a legacy plugin (`register_attribute`). LegacyPluginHelper, - /// Single-segment custom attribute not registered in any way (`#[my_attr]`). - Custom, } #[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)] @@ -333,7 +331,6 @@ impl NonMacroAttrKind { NonMacroAttrKind::DeriveHelper => "derive helper attribute", NonMacroAttrKind::Registered => "explicitly registered attribute", NonMacroAttrKind::LegacyPluginHelper => "legacy plugin helper attribute", - NonMacroAttrKind::Custom => "custom attribute", } } } diff --git a/src/librustc_plugin/registry.rs b/src/librustc_plugin/registry.rs index 2e23b8c870cf..3f4b87a97c77 100644 --- a/src/librustc_plugin/registry.rs +++ b/src/librustc_plugin/registry.rs @@ -101,7 +101,6 @@ impl<'a> Registry<'a> { /// Register an attribute with an attribute type. /// - /// Registered attributes will bypass the `custom_attribute` feature gate. /// `Whitelisted` attributes will additionally not trigger the `unused_attribute` /// lint. `CrateLevel` attributes will not be allowed on anything other than a crate. pub fn register_attribute(&mut self, name: Symbol, ty: AttributeType) { diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 9d8d035ab701..1138716d591c 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -732,20 +732,7 @@ impl<'a> Resolver<'a> { return Ok(binding); } - let determinacy = Determinacy::determined(determinacy == Determinacy::Determined || force); - if determinacy == Determinacy::Determined && macro_kind == Some(MacroKind::Attr) && - self.session.features_untracked().custom_attribute { - // For single-segment attributes interpret determinate "no resolution" as a custom - // attribute. (Lexical resolution implies the first segment and attr kind should imply - // the last segment, so we are certainly working with a single-segment attribute here.) - assert!(ns == MacroNS); - let binding = (Res::NonMacroAttr(NonMacroAttrKind::Custom), - ty::Visibility::Public, orig_ident.span, ExpnId::root()) - .to_name_binding(self.arenas); - Ok(binding) - } else { - Err(determinacy) - } + Err(Determinacy::determined(determinacy == Determinacy::Determined || force)) } crate fn finalize_macro_resolutions(&mut self) { @@ -756,16 +743,7 @@ impl<'a> Resolver<'a> { // Make sure compilation does not succeed if preferred macro resolution // has changed after the macro had been expanded. In theory all such // situations should be reported as ambiguity errors, so this is a bug. - if initial_res == Res::NonMacroAttr(NonMacroAttrKind::Custom) { - // Yeah, legacy custom attributes are implemented using forced resolution - // (which is a best effort error recovery tool, basically), so we can't - // promise their resolution won't change later. - let msg = format!("inconsistent resolution for a macro: first {}, then {}", - initial_res.descr(), res.descr()); - this.session.span_err(span, &msg); - } else { - span_bug!(span, "inconsistent resolution for a macro"); - } + span_bug!(span, "inconsistent resolution for a macro"); } } else { // It's possible that the macro was unresolved (indeterminate) and silently diff --git a/src/libsyntax/feature_gate/active.rs b/src/libsyntax/feature_gate/active.rs index 087a754b27ee..319ca5fd3e22 100644 --- a/src/libsyntax/feature_gate/active.rs +++ b/src/libsyntax/feature_gate/active.rs @@ -265,9 +265,6 @@ declare_features! ( /// Allows the use of SIMD types in functions declared in `extern` blocks. (active, simd_ffi, "1.0.0", Some(27731), None), - /// Allows using custom attributes (RFC 572). - (active, custom_attribute, "1.0.0", Some(29642), None), - /// Allows using non lexical lifetimes (RFC 2094). (active, nll, "1.0.0", Some(43234), None), diff --git a/src/libsyntax/feature_gate/removed.rs b/src/libsyntax/feature_gate/removed.rs index c7b931a6f702..f0aa74c65df6 100644 --- a/src/libsyntax/feature_gate/removed.rs +++ b/src/libsyntax/feature_gate/removed.rs @@ -67,6 +67,9 @@ declare_features! ( Some("merged into `#![feature(slice_patterns)]`")), (removed, macro_reexport, "1.0.0", Some(29638), None, Some("subsumed by `pub use`")), + /// Allows using custom attributes (RFC 572). + (removed, custom_attribute, "1.0.0", Some(29642), None, + Some("removed in favor of `#![register_tool]` and `#![register_attr]`")), (removed, pushpop_unsafe, "1.2.0", None, None, None), (removed, needs_allocator, "1.4.0", Some(27389), None, Some("subsumed by `#![feature(allocator_internals)]`")), diff --git a/src/test/ui-fulldeps/issue-15778-pass.rs b/src/test/ui-fulldeps/issue-15778-pass.rs index b93630d56b0a..55f19ab4ee31 100644 --- a/src/test/ui-fulldeps/issue-15778-pass.rs +++ b/src/test/ui-fulldeps/issue-15778-pass.rs @@ -3,7 +3,15 @@ // ignore-stage1 // compile-flags: -D crate-not-okay -#![feature(plugin, custom_attribute, custom_inner_attributes, rustc_attrs)] +#![feature(plugin, register_attr, custom_inner_attributes, rustc_attrs)] + +#![register_attr( + rustc_crate_okay, + rustc_crate_blue, + rustc_crate_red, + rustc_crate_grey, + rustc_crate_green, +)] #![plugin(lint_for_crate_rpass)] #![rustc_crate_okay] diff --git a/src/test/ui-fulldeps/issue-15778-pass.stderr b/src/test/ui-fulldeps/issue-15778-pass.stderr index 0c30d2cdcbf1..48b42958489e 100644 --- a/src/test/ui-fulldeps/issue-15778-pass.stderr +++ b/src/test/ui-fulldeps/issue-15778-pass.stderr @@ -1,5 +1,5 @@ warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675 - --> $DIR/issue-15778-pass.rs:8:1 + --> $DIR/issue-15778-pass.rs:16:1 | LL | #![plugin(lint_for_crate_rpass)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: may be removed in a future compiler version diff --git a/src/test/ui/feature-gates/feature-gate-custom_attribute2.rs b/src/test/ui/feature-gates/feature-gate-custom_attribute2.rs index e4c80141aa2a..724e53debeb0 100644 --- a/src/test/ui/feature-gates/feature-gate-custom_attribute2.rs +++ b/src/test/ui/feature-gates/feature-gate-custom_attribute2.rs @@ -1,8 +1,6 @@ // This test ensures that attributes on formals in generic parameter // lists are included when we are checking for unstable attributes. -// gate-test-custom_attribute - struct StLt<#[lt_struct] 'a>(&'a u32); //~^ ERROR cannot find attribute `lt_struct` in this scope struct StTy<#[ty_struct] I>(I); diff --git a/src/test/ui/feature-gates/feature-gate-custom_attribute2.stderr b/src/test/ui/feature-gates/feature-gate-custom_attribute2.stderr index bc89caddb443..b33710ce0495 100644 --- a/src/test/ui/feature-gates/feature-gate-custom_attribute2.stderr +++ b/src/test/ui/feature-gates/feature-gate-custom_attribute2.stderr @@ -1,101 +1,101 @@ error: cannot find attribute `lt_hof` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:53:21 + --> $DIR/feature-gate-custom_attribute2.rs:51:21 | LL | where Q: for <#[lt_hof] 'i> Fn(&'i [u32]) -> &'i u32 | ^^^^^^ error: cannot find attribute `ty_meth` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:48:15 + --> $DIR/feature-gate-custom_attribute2.rs:46:15 | LL | fn m_ty<#[ty_meth] P>(_: P) { } | ^^^^^^^ error: cannot find attribute `lt_meth` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:46:15 + --> $DIR/feature-gate-custom_attribute2.rs:44:15 | LL | fn m_lt<#[lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } } | ^^^^^^^ error: cannot find attribute `ty_fn` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:42:11 + --> $DIR/feature-gate-custom_attribute2.rs:40:11 | LL | fn f_ty<#[ty_fn] O>(_: O) { } | ^^^^^ error: cannot find attribute `lt_fn` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:40:11 + --> $DIR/feature-gate-custom_attribute2.rs:38:11 | LL | fn f_lt<#[lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } } | ^^^^^ error: cannot find attribute `ty_impl_for` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:35:8 + --> $DIR/feature-gate-custom_attribute2.rs:33:8 | LL | impl<#[ty_impl_for] N> TrTy for StTy { | ^^^^^^^^^^^ error: cannot find attribute `lt_impl_for` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:31:8 + --> $DIR/feature-gate-custom_attribute2.rs:29:8 | LL | impl<#[lt_impl_for] 'f> TrLt<'f> for StLt<'f> { | ^^^^^^^^^^^ error: cannot find attribute `ty_inherent` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:28:8 + --> $DIR/feature-gate-custom_attribute2.rs:26:8 | LL | impl<#[ty_inherent] M> StTy { } | ^^^^^^^^^^^ error: cannot find attribute `lt_inherent` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:26:8 + --> $DIR/feature-gate-custom_attribute2.rs:24:8 | LL | impl<#[lt_inherent] 'e> StLt<'e> { } | ^^^^^^^^^^^ error: cannot find attribute `ty_type` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:23:13 + --> $DIR/feature-gate-custom_attribute2.rs:21:13 | LL | type TyTy<#[ty_type] L> = (L, ); | ^^^^^^^ error: cannot find attribute `lt_type` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:21:13 + --> $DIR/feature-gate-custom_attribute2.rs:19:13 | LL | type TyLt<#[lt_type] 'd> = &'d u32; | ^^^^^^^ error: cannot find attribute `ty_trait` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:18:14 + --> $DIR/feature-gate-custom_attribute2.rs:16:14 | LL | trait TrTy<#[ty_trait] K> { fn foo(&self, _: K); } | ^^^^^^^^ error: cannot find attribute `lt_trait` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:16:14 + --> $DIR/feature-gate-custom_attribute2.rs:14:14 | LL | trait TrLt<#[lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; } | ^^^^^^^^ error: cannot find attribute `ty_enum` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:13:13 + --> $DIR/feature-gate-custom_attribute2.rs:11:13 | LL | enum EnTy<#[ty_enum] J> { A(J), B } | ^^^^^^^ error: cannot find attribute `lt_enum` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:11:13 + --> $DIR/feature-gate-custom_attribute2.rs:9:13 | LL | enum EnLt<#[lt_enum] 'b> { A(&'b u32), B } | ^^^^^^^ error: cannot find attribute `ty_struct` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:8:15 + --> $DIR/feature-gate-custom_attribute2.rs:6:15 | LL | struct StTy<#[ty_struct] I>(I); | ^^^^^^^^^ error: cannot find attribute `lt_struct` in this scope - --> $DIR/feature-gate-custom_attribute2.rs:6:15 + --> $DIR/feature-gate-custom_attribute2.rs:4:15 | LL | struct StLt<#[lt_struct] 'a>(&'a u32); | ^^^^^^^^^ diff --git a/src/test/ui/proc-macro/expand-to-unstable-2.rs b/src/test/ui/proc-macro/expand-to-unstable-2.rs index da7c89fdd46d..4160e5418b78 100644 --- a/src/test/ui/proc-macro/expand-to-unstable-2.rs +++ b/src/test/ui/proc-macro/expand-to-unstable-2.rs @@ -1,6 +1,8 @@ // aux-build:derive-unstable-2.rs -#![feature(custom_attribute)] +#![feature(register_attr)] + +#![register_attr(rustc_foo)] #[macro_use] extern crate derive_unstable_2; diff --git a/src/test/ui/proc-macro/expand-to-unstable-2.stderr b/src/test/ui/proc-macro/expand-to-unstable-2.stderr index 01e6a4a8ab95..5b6184afacdd 100644 --- a/src/test/ui/proc-macro/expand-to-unstable-2.stderr +++ b/src/test/ui/proc-macro/expand-to-unstable-2.stderr @@ -1,5 +1,5 @@ error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler - --> $DIR/expand-to-unstable-2.rs:8:10 + --> $DIR/expand-to-unstable-2.rs:10:10 | LL | #[derive(Unstable)] | ^^^^^^^^ diff --git a/src/test/ui/proc-macro/issue-41211.rs b/src/test/ui/proc-macro/issue-41211.rs index 491b89b2f559..072a63baf3a4 100644 --- a/src/test/ui/proc-macro/issue-41211.rs +++ b/src/test/ui/proc-macro/issue-41211.rs @@ -3,11 +3,13 @@ // FIXME: https://github.com/rust-lang/rust/issues/41430 // This is a temporary regression test for the ICE reported in #41211 -#![feature(custom_attribute)] #![feature(custom_inner_attributes)] +#![feature(register_attr)] + +#![register_attr(identity_attr)] #![identity_attr] -//~^ ERROR inconsistent resolution for a macro: first custom attribute, then attribute macro +//~^ ERROR `identity_attr` is ambiguous extern crate test_macros; use test_macros::identity_attr; diff --git a/src/test/ui/proc-macro/issue-41211.stderr b/src/test/ui/proc-macro/issue-41211.stderr index f01cba0c9303..22ad4aa147b6 100644 --- a/src/test/ui/proc-macro/issue-41211.stderr +++ b/src/test/ui/proc-macro/issue-41211.stderr @@ -1,8 +1,21 @@ -error: inconsistent resolution for a macro: first custom attribute, then attribute macro - --> $DIR/issue-41211.rs:9:4 +error[E0659]: `identity_attr` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution) + --> $DIR/issue-41211.rs:11:4 | LL | #![identity_attr] - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ ambiguous name + | +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`. diff --git a/src/test/ui/span/issue-36530.rs b/src/test/ui/span/issue-36530.rs index 14b2c8644e0b..4776740d8de9 100644 --- a/src/test/ui/span/issue-36530.rs +++ b/src/test/ui/span/issue-36530.rs @@ -1,6 +1,8 @@ // gate-test-custom_inner_attributes -#![feature(custom_attribute)] +#![feature(register_attr)] + +#![register_attr(foo)] #[foo] mod foo { diff --git a/src/test/ui/span/issue-36530.stderr b/src/test/ui/span/issue-36530.stderr index c6b7895e65a0..2d3972917dfe 100644 --- a/src/test/ui/span/issue-36530.stderr +++ b/src/test/ui/span/issue-36530.stderr @@ -1,5 +1,5 @@ error[E0658]: non-builtin inner attributes are unstable - --> $DIR/issue-36530.rs:7:5 + --> $DIR/issue-36530.rs:9:5 | LL | #![foo] | ^^^^^^^