From 0ffb6438a6b19135cdfd3461dbd9efaf0011a149 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 29 Jun 2019 14:06:22 +0300 Subject: [PATCH 1/2] Make sure `#[rustc_doc_only_macro]` and other rustc attributes are registered --- src/libcore/lib.rs | 1 + src/librustc_resolve/macros.rs | 12 +---- src/libsyntax/ext/expand.rs | 4 +- src/libsyntax/feature_gate.rs | 52 ++++++++++++++----- .../run-pass-fulldeps/issue-15778-pass.rs | 5 +- src/test/run-pass/attr-on-generic-formals.rs | 52 ------------------- .../attrs-with-no-formal-in-generics-1.rs | 6 +-- .../attrs-with-no-formal-in-generics-1.stderr | 6 +-- .../attrs-with-no-formal-in-generics-2.rs | 2 +- .../attrs-with-no-formal-in-generics-2.stderr | 6 +-- .../allow_const_fn_ptr_feature_gate.rs | 2 +- .../allow_const_fn_ptr_feature_gate.stderr | 6 +-- .../feature-gates/feature-gate-rustc-attrs.rs | 4 +- .../feature-gate-rustc-attrs.stderr | 8 +-- src/test/ui/generic/generic-param-attrs.rs | 44 +++++++--------- .../ty-outlives/projection-implied-bounds.rs | 7 +-- .../projection-implied-bounds.stderr | 2 +- .../ty-outlives/ty-param-implied-bounds.rs | 4 -- .../object-lifetime-default.stderr | 48 ++++++++--------- .../ui/proc-macro/expand-to-unstable-2.rs | 4 +- .../ui/proc-macro/expand-to-unstable-2.stderr | 6 +-- .../ui/reserved/reserved-attr-on-macro.rs | 2 +- .../ui/reserved/reserved-attr-on-macro.stderr | 4 +- src/test/ui/suggestions/attribute-typos.rs | 17 +++--- .../ui/suggestions/attribute-typos.stderr | 8 +-- 25 files changed, 127 insertions(+), 185 deletions(-) delete mode 100644 src/test/run-pass/attr-on-generic-formals.rs diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 04c50329de3d0..1f31b65b3603b 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -74,6 +74,7 @@ #![feature(concat_idents)] #![feature(const_fn)] #![feature(const_fn_union)] +#![feature(custom_inner_attributes)] #![feature(doc_cfg)] #![feature(doc_spotlight)] #![feature(extern_types)] diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 392a46a262f50..08a105572376c 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -323,21 +323,13 @@ impl<'a> Resolver<'a> { let features = self.session.features_untracked(); if attr_kind == NonMacroAttrKind::Custom { assert!(path.segments.len() == 1); - let name = path.segments[0].ident.as_str(); - if name.starts_with("rustc_") { - if !features.rustc_attrs { - let msg = "unless otherwise specified, attributes with the prefix \ - `rustc_` are reserved for internal compiler diagnostics"; - self.report_unknown_attribute(path.span, &name, msg, - sym::rustc_attrs); - } - } else if !features.custom_attribute { + if !features.custom_attribute { let msg = format!("The attribute `{}` is currently unknown to the \ compiler and may have meaning added to it in the \ future", path); self.report_unknown_attribute( path.span, - &name, + &path.segments[0].ident.as_str(), &msg, sym::custom_attribute, ); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 5473f55aa3370..3f2bae50325d5 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1525,9 +1525,7 @@ impl<'feat> ExpansionConfig<'feat> { } fn enable_custom_inner_attributes(&self) -> bool { - self.features.map_or(false, |features| { - features.custom_inner_attributes || features.custom_attribute || features.rustc_attrs - }) + self.features.map_or(false, |features| features.custom_inner_attributes) } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index a6e8441a915e0..9aea995831edb 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1290,6 +1290,18 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ attribute is just used for rustc unit \ tests and will never be stable", cfg_fn!(rustc_attrs))), + (sym::rustc_dump_env_program_clauses, Whitelisted, template!(Word), Gated(Stability::Unstable, + sym::rustc_attrs, + "the `#[rustc_dump_env_program_clauses]` \ + attribute is just used for rustc unit \ + tests and will never be stable", + cfg_fn!(rustc_attrs))), + (sym::rustc_object_lifetime_default, Whitelisted, template!(Word), Gated(Stability::Unstable, + sym::rustc_attrs, + "the `#[rustc_object_lifetime_default]` \ + attribute is just used for rustc unit \ + tests and will never be stable", + cfg_fn!(rustc_attrs))), (sym::rustc_test_marker, Normal, template!(Word), Gated(Stability::Unstable, sym::rustc_attrs, "the `#[rustc_test_marker]` attribute \ @@ -1351,6 +1363,26 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ "internal implementation detail", cfg_fn!(rustc_attrs))), + (sym::rustc_allocator_nounwind, Whitelisted, template!(Word), Gated(Stability::Unstable, + sym::rustc_attrs, + "internal implementation detail", + cfg_fn!(rustc_attrs))), + + (sym::rustc_doc_only_macro, Whitelisted, template!(Word), Gated(Stability::Unstable, + sym::rustc_attrs, + "internal implementation detail", + cfg_fn!(rustc_attrs))), + + (sym::rustc_promotable, Whitelisted, template!(Word), Gated(Stability::Unstable, + sym::rustc_attrs, + "internal implementation detail", + cfg_fn!(rustc_attrs))), + + (sym::rustc_allow_const_fn_ptr, Whitelisted, template!(Word), Gated(Stability::Unstable, + sym::rustc_attrs, + "internal implementation detail", + cfg_fn!(rustc_attrs))), + (sym::rustc_dummy, Normal, template!(Word /* doesn't matter*/), Gated(Stability::Unstable, sym::rustc_attrs, "used by the test suite", @@ -1647,19 +1679,13 @@ impl<'a> Context<'a> { return; } } - if !attr::is_known(attr) { - if attr.name_or_empty().as_str().starts_with("rustc_") { - let msg = "unless otherwise specified, attributes with the prefix `rustc_` \ - are reserved for internal compiler diagnostics"; - gate_feature!(self, rustc_attrs, attr.span, msg); - } else if !is_macro { - // Only run the custom attribute lint during regular feature gate - // checking. Macro gating runs before the plugin attributes are - // registered, so we skip this in that case. - let msg = format!("The attribute `{}` is currently unknown to the compiler and \ - may have meaning added to it in the future", attr.path); - gate_feature!(self, custom_attribute, attr.span, &msg); - } + if !is_macro && !attr::is_known(attr) { + // Only run the custom attribute lint during regular feature gate + // checking. Macro gating runs before the plugin attributes are + // registered, so we skip this in that case. + let msg = format!("The attribute `{}` is currently unknown to the compiler and \ + may have meaning added to it in the future", attr.path); + gate_feature!(self, custom_attribute, attr.span, &msg); } } } diff --git a/src/test/run-pass-fulldeps/issue-15778-pass.rs b/src/test/run-pass-fulldeps/issue-15778-pass.rs index 2add3ccbe36f2..23c1c0766770b 100644 --- a/src/test/run-pass-fulldeps/issue-15778-pass.rs +++ b/src/test/run-pass-fulldeps/issue-15778-pass.rs @@ -2,7 +2,8 @@ // ignore-stage1 // compile-flags: -D crate-not-okay -#![feature(plugin, rustc_attrs)] +#![feature(plugin, custom_attribute, custom_inner_attributes)] + #![plugin(lint_for_crate)] #![rustc_crate_okay] #![rustc_crate_blue] @@ -10,4 +11,4 @@ #![rustc_crate_grey] #![rustc_crate_green] -pub fn main() { } +fn main() {} diff --git a/src/test/run-pass/attr-on-generic-formals.rs b/src/test/run-pass/attr-on-generic-formals.rs deleted file mode 100644 index 9ebf0fcb1c192..0000000000000 --- a/src/test/run-pass/attr-on-generic-formals.rs +++ /dev/null @@ -1,52 +0,0 @@ -#![allow(unused_attributes)] - -// This test ensures we can attach attributes to the formals in all -// places where generic parameter lists occur, assuming appropriate -// feature gates are enabled. -// -// (We are prefixing all tested features with `rustc_`, to ensure that -// the attributes themselves won't be rejected by the compiler when -// using `rustc_attrs` feature. There is a separate compile-fail/ test -// ensuring that the attribute feature-gating works in this context.) - -#![feature(rustc_attrs)] -#![allow(dead_code)] - -struct StLt<#[rustc_lt_struct] 'a>(&'a u32); -struct StTy<#[rustc_ty_struct] I>(I); - -enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B } -enum EnTy<#[rustc_ty_enum] J> { A(J), B } - -trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; } -trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); } - -type TyLt<#[rustc_lt_type] 'd> = &'d u32; -type TyTy<#[rustc_ty_type] L> = (L, ); - -impl<#[rustc_lt_inherent] 'e> StLt<'e> { } -impl<#[rustc_ty_inherent] M> StTy { } - -impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> { - fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } } -} -impl<#[rustc_ty_impl_for] N> TrTy for StTy { - fn foo(&self, _: N) { } -} - -fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } } -fn f_ty<#[rustc_ty_fn] O>(_: O) { } - -impl StTy { - fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } } - fn m_ty<#[rustc_ty_meth] P>(_: P) { } -} - -fn hof_lt(_: Q) - where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32 -{ -} - -fn main() { - -} diff --git a/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.rs b/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.rs index ca5fdd9da859b..df9c8d894652b 100644 --- a/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.rs +++ b/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.rs @@ -6,10 +6,8 @@ struct RefIntPair<'a, 'b>(&'a u32, &'b u32); -impl<#[rustc_1] 'a, 'b, #[oops]> RefIntPair<'a, 'b> { +impl<#[rustc_dummy] 'a, 'b, #[oops]> RefIntPair<'a, 'b> { //~^ ERROR trailing attribute after generic parameter } -fn main() { - -} +fn main() {} diff --git a/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.stderr b/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.stderr index 55e7a9877846f..5b4f5222a2b14 100644 --- a/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.stderr +++ b/src/test/ui/attributes/attrs-with-no-formal-in-generics-1.stderr @@ -1,8 +1,8 @@ error: trailing attribute after generic parameter - --> $DIR/attrs-with-no-formal-in-generics-1.rs:9:25 + --> $DIR/attrs-with-no-formal-in-generics-1.rs:9:29 | -LL | impl<#[rustc_1] 'a, 'b, #[oops]> RefIntPair<'a, 'b> { - | ^^^^^^^ attributes must go before parameters +LL | impl<#[rustc_dummy] 'a, 'b, #[oops]> RefIntPair<'a, 'b> { + | ^^^^^^^ attributes must go before parameters error: aborting due to previous error diff --git a/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.rs b/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.rs index c795612acf08c..d1d044035260b 100644 --- a/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.rs +++ b/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.rs @@ -6,7 +6,7 @@ struct RefAny<'a, T>(&'a T); -impl<#[rustc_1] 'a, #[rustc_2] T, #[oops]> RefAny<'a, T> {} +impl<#[rustc_dummy] 'a, #[rustc_dummy] T, #[oops]> RefAny<'a, T> {} //~^ ERROR trailing attribute after generic parameter fn main() {} diff --git a/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.stderr b/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.stderr index acd0ae3678a7c..fce3ff7de78e8 100644 --- a/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.stderr +++ b/src/test/ui/attributes/attrs-with-no-formal-in-generics-2.stderr @@ -1,8 +1,8 @@ error: trailing attribute after generic parameter - --> $DIR/attrs-with-no-formal-in-generics-2.rs:9:35 + --> $DIR/attrs-with-no-formal-in-generics-2.rs:9:43 | -LL | impl<#[rustc_1] 'a, #[rustc_2] T, #[oops]> RefAny<'a, T> {} - | ^^^^^^^ attributes must go before parameters +LL | impl<#[rustc_dummy] 'a, #[rustc_dummy] T, #[oops]> RefAny<'a, T> {} + | ^^^^^^^ attributes must go before parameters error: aborting due to previous error diff --git a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.rs b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.rs index 0395795ef7bfe..0f9d37292958a 100644 --- a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.rs +++ b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.rs @@ -5,7 +5,7 @@ const fn error(_: fn()) {} #[stable(feature = "rust1", since = "1.0.0")] #[rustc_allow_const_fn_ptr] -//~^ ERROR unless otherwise specified, attributes with the prefix `rustc_` are reserved +//~^ ERROR internal implementation detail const fn compiles(_: fn()) {} fn main() {} diff --git a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.stderr b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.stderr index c934307e918b9..d2ca0c8bc381b 100644 --- a/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.stderr +++ b/src/test/ui/consts/min_const_fn/allow_const_fn_ptr_feature_gate.stderr @@ -1,8 +1,8 @@ -error[E0658]: unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics - --> $DIR/allow_const_fn_ptr_feature_gate.rs:7:3 +error[E0658]: internal implementation detail + --> $DIR/allow_const_fn_ptr_feature_gate.rs:7:1 | LL | #[rustc_allow_const_fn_ptr] - | ^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(rustc_attrs)] to the crate attributes to enable diff --git a/src/test/ui/feature-gates/feature-gate-rustc-attrs.rs b/src/test/ui/feature-gates/feature-gate-rustc-attrs.rs index 5ec413cc71de0..95ff18213f797 100644 --- a/src/test/ui/feature-gates/feature-gate-rustc-attrs.rs +++ b/src/test/ui/feature-gates/feature-gate-rustc-attrs.rs @@ -1,6 +1,6 @@ // Test that `#[rustc_*]` attributes are gated by `rustc_attrs` feature gate. -#[rustc_foo] -//~^ ERROR unless otherwise specified, attributes with the prefix `rustc_` are reserved +#[rustc_dummy] +//~^ ERROR used by the test suite fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr b/src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr index 3c823c8d4e25f..57dcc77e518f3 100644 --- a/src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr +++ b/src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr @@ -1,8 +1,8 @@ -error[E0658]: unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics - --> $DIR/feature-gate-rustc-attrs.rs:3:3 +error[E0658]: used by the test suite + --> $DIR/feature-gate-rustc-attrs.rs:3:1 | -LL | #[rustc_foo] - | ^^^^^^^^^ +LL | #[rustc_dummy] + | ^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(rustc_attrs)] to the crate attributes to enable diff --git a/src/test/ui/generic/generic-param-attrs.rs b/src/test/ui/generic/generic-param-attrs.rs index 601d2a9e0a31f..6c628914f1f8d 100644 --- a/src/test/ui/generic/generic-param-attrs.rs +++ b/src/test/ui/generic/generic-param-attrs.rs @@ -1,44 +1,38 @@ // This test previously ensured that attributes on formals in generic parameter // lists are rejected without a feature gate. -// -// (We are prefixing all tested features with `rustc_`, to ensure that -// the attributes themselves won't be rejected by the compiler when -// using `rustc_attrs` feature. There is a separate compile-fail/ test -// ensuring that the attribute feature-gating works in this context.) // compile-pass #![feature(rustc_attrs)] -#![allow(dead_code)] - -struct StLt<#[rustc_lt_struct] 'a>(&'a u32); -struct StTy<#[rustc_ty_struct] I>(I); -enum EnLt<#[rustc_lt_enum] 'b> { A(&'b u32), B } -enum EnTy<#[rustc_ty_enum] J> { A(J), B } -trait TrLt<#[rustc_lt_trait] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; } -trait TrTy<#[rustc_ty_trait] K> { fn foo(&self, _: K); } -type TyLt<#[rustc_lt_type] 'd> = &'d u32; -type TyTy<#[rustc_ty_type] L> = (L, ); - -impl<#[rustc_lt_inherent] 'e> StLt<'e> { } -impl<#[rustc_ty_inherent] M> StTy { } -impl<#[rustc_lt_impl_for] 'f> TrLt<'f> for StLt<'f> { + +struct StLt<#[rustc_dummy] 'a>(&'a u32); +struct StTy<#[rustc_dummy] I>(I); +enum EnLt<#[rustc_dummy] 'b> { A(&'b u32), B } +enum EnTy<#[rustc_dummy] J> { A(J), B } +trait TrLt<#[rustc_dummy] 'c> { fn foo(&self, _: &'c [u32]) -> &'c u32; } +trait TrTy<#[rustc_dummy] K> { fn foo(&self, _: K); } +type TyLt<#[rustc_dummy] 'd> = &'d u32; +type TyTy<#[rustc_dummy] L> = (L, ); + +impl<#[rustc_dummy] 'e> StLt<'e> { } +impl<#[rustc_dummy] M> StTy { } +impl<#[rustc_dummy] 'f> TrLt<'f> for StLt<'f> { fn foo(&self, _: &'f [u32]) -> &'f u32 { loop { } } } -impl<#[rustc_ty_impl_for] N> TrTy for StTy { +impl<#[rustc_dummy] N> TrTy for StTy { fn foo(&self, _: N) { } } -fn f_lt<#[rustc_lt_fn] 'g>(_: &'g [u32]) -> &'g u32 { loop { } } -fn f_ty<#[rustc_ty_fn] O>(_: O) { } +fn f_lt<#[rustc_dummy] 'g>(_: &'g [u32]) -> &'g u32 { loop { } } +fn f_ty<#[rustc_dummy] O>(_: O) { } impl StTy { - fn m_lt<#[rustc_lt_meth] 'h>(_: &'h [u32]) -> &'h u32 { loop { } } - fn m_ty<#[rustc_ty_meth] P>(_: P) { } + fn m_lt<#[rustc_dummy] 'h>(_: &'h [u32]) -> &'h u32 { loop { } } + fn m_ty<#[rustc_dummy] P>(_: P) { } } fn hof_lt(_: Q) - where Q: for <#[rustc_lt_hof] 'i> Fn(&'i [u32]) -> &'i u32 + where Q: for <#[rustc_dummy] 'i> Fn(&'i [u32]) -> &'i u32 {} fn main() {} diff --git a/src/test/ui/nll/ty-outlives/projection-implied-bounds.rs b/src/test/ui/nll/ty-outlives/projection-implied-bounds.rs index 1245ce8583e29..fb50dce1af616 100644 --- a/src/test/ui/nll/ty-outlives/projection-implied-bounds.rs +++ b/src/test/ui/nll/ty-outlives/projection-implied-bounds.rs @@ -1,10 +1,7 @@ -// compile-flags:-Zborrowck=mir -Zverbose - // Test that we can deduce when projections like `T::Item` outlive the // function body. Test that this does not imply that `T: 'a` holds. -#![allow(warnings)] -#![feature(rustc_attrs)] +// compile-flags:-Zborrowck=mir -Zverbose use std::cell::Cell; @@ -18,7 +15,6 @@ where f(&value, Cell::new(&n)); } -#[rustc_errors] fn generic1(value: T) { // No error here: twice(value, |value_ref, item| invoke1(item)); @@ -30,7 +26,6 @@ where { } -#[rustc_errors] fn generic2(value: T) { twice(value, |value_ref, item| invoke2(value_ref, item)); //~^ ERROR the parameter type `T` may not live long enough diff --git a/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr b/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr index 9cdb78a10281c..9f0c60c1e1705 100644 --- a/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr +++ b/src/test/ui/nll/ty-outlives/projection-implied-bounds.stderr @@ -1,5 +1,5 @@ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/projection-implied-bounds.rs:35:18 + --> $DIR/projection-implied-bounds.rs:30:18 | LL | twice(value, |value_ref, item| invoke2(value_ref, item)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/nll/ty-outlives/ty-param-implied-bounds.rs b/src/test/ui/nll/ty-outlives/ty-param-implied-bounds.rs index f61f54f80a78b..6a9ef3b5ce07f 100644 --- a/src/test/ui/nll/ty-outlives/ty-param-implied-bounds.rs +++ b/src/test/ui/nll/ty-outlives/ty-param-implied-bounds.rs @@ -4,9 +4,6 @@ // Test that we assume that universal types like `T` outlive the // function body. -#![allow(warnings)] -#![feature(rustc_attrs)] - use std::cell::Cell; fn twice(value: T, mut f: F) @@ -17,7 +14,6 @@ where f(Cell::new(&value)); } -#[rustc_errors] fn generic(value: T) { // No error here: twice(value, |r| invoke(r)); diff --git a/src/test/ui/object-lifetime/object-lifetime-default.stderr b/src/test/ui/object-lifetime/object-lifetime-default.stderr index 2642cdff2bf6a..f71c8cd0e0c39 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default.stderr @@ -1,20 +1,20 @@ -error: 'a,Ambiguous - --> $DIR/object-lifetime-default.rs:24:1 +error: BaseDefault + --> $DIR/object-lifetime-default.rs:6:1 | -LL | struct G<'a,'b,T:'a,U:'a+'b>(&'a T, &'b U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | struct A(T); + | ^^^^^^^^^^^^^^^ -error: 'a,'b - --> $DIR/object-lifetime-default.rs:21:1 +error: BaseDefault + --> $DIR/object-lifetime-default.rs:9:1 | -LL | struct F<'a,'b,T:'a,U:'b>(&'a T, &'b U); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | struct B<'a,T>(&'a (), T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: 'b - --> $DIR/object-lifetime-default.rs:18:1 +error: 'a + --> $DIR/object-lifetime-default.rs:12:1 | -LL | struct E<'a,'b:'a,T:'b>(&'a T, &'b T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | struct C<'a,T:'a>(&'a T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: Ambiguous --> $DIR/object-lifetime-default.rs:15:1 @@ -22,23 +22,23 @@ error: Ambiguous LL | struct D<'a,'b,T:'a+'b>(&'a T, &'b T); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: 'a - --> $DIR/object-lifetime-default.rs:12:1 +error: 'b + --> $DIR/object-lifetime-default.rs:18:1 | -LL | struct C<'a,T:'a>(&'a T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | struct E<'a,'b:'a,T:'b>(&'a T, &'b T); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: BaseDefault - --> $DIR/object-lifetime-default.rs:9:1 +error: 'a,'b + --> $DIR/object-lifetime-default.rs:21:1 | -LL | struct B<'a,T>(&'a (), T); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | struct F<'a,'b,T:'a,U:'b>(&'a T, &'b U); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: BaseDefault - --> $DIR/object-lifetime-default.rs:6:1 +error: 'a,Ambiguous + --> $DIR/object-lifetime-default.rs:24:1 | -LL | struct A(T); - | ^^^^^^^^^^^^^^^ +LL | struct G<'a,'b,T:'a,U:'a+'b>(&'a T, &'b U); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors 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 4b4ba52ecd726..8ce3cde6f0432 100644 --- a/src/test/ui/proc-macro/expand-to-unstable-2.rs +++ b/src/test/ui/proc-macro/expand-to-unstable-2.rs @@ -1,12 +1,10 @@ // aux-build:derive-unstable-2.rs -#![allow(warnings)] - #[macro_use] extern crate derive_unstable_2; #[derive(Unstable)] -//~^ ERROR: reserved for internal compiler +//~^ ERROR attribute `rustc_foo` is currently unknown struct A; fn main() { 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 e2f51dd3d5dd2..77be3d5272394 100644 --- a/src/test/ui/proc-macro/expand-to-unstable-2.stderr +++ b/src/test/ui/proc-macro/expand-to-unstable-2.stderr @@ -1,11 +1,11 @@ -error[E0658]: unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics - --> $DIR/expand-to-unstable-2.rs:8:10 +error[E0658]: The attribute `rustc_foo` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/expand-to-unstable-2.rs:6:10 | LL | #[derive(Unstable)] | ^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 - = help: add #![feature(rustc_attrs)] to the crate attributes to enable + = help: add #![feature(custom_attribute)] to the crate attributes to enable error: aborting due to previous error diff --git a/src/test/ui/reserved/reserved-attr-on-macro.rs b/src/test/ui/reserved/reserved-attr-on-macro.rs index 96c63ba4db8c9..0ee6577f8a11d 100644 --- a/src/test/ui/reserved/reserved-attr-on-macro.rs +++ b/src/test/ui/reserved/reserved-attr-on-macro.rs @@ -1,5 +1,5 @@ #[rustc_attribute_should_be_reserved] -//~^ ERROR unless otherwise specified, attributes with the prefix `rustc_` are reserved +//~^ ERROR attribute `rustc_attribute_should_be_reserved` is currently unknown macro_rules! foo { () => (()); } diff --git a/src/test/ui/reserved/reserved-attr-on-macro.stderr b/src/test/ui/reserved/reserved-attr-on-macro.stderr index c8738d1ed3429..34b21ecd1265d 100644 --- a/src/test/ui/reserved/reserved-attr-on-macro.stderr +++ b/src/test/ui/reserved/reserved-attr-on-macro.stderr @@ -1,11 +1,11 @@ -error[E0658]: unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics +error[E0658]: The attribute `rustc_attribute_should_be_reserved` is currently unknown to the compiler and may have meaning added to it in the future --> $DIR/reserved-attr-on-macro.rs:1:3 | LL | #[rustc_attribute_should_be_reserved] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 - = help: add #![feature(rustc_attrs)] to the crate attributes to enable + = help: add #![feature(custom_attribute)] to the crate attributes to enable error: cannot determine resolution for the macro `foo` --> $DIR/reserved-attr-on-macro.rs:8:5 diff --git a/src/test/ui/suggestions/attribute-typos.rs b/src/test/ui/suggestions/attribute-typos.rs index 13c6308b97e85..b45acbdd9206c 100644 --- a/src/test/ui/suggestions/attribute-typos.rs +++ b/src/test/ui/suggestions/attribute-typos.rs @@ -1,13 +1,8 @@ -#[deprcated] //~ ERROR E0658 -fn foo() {} //~| HELP a built-in attribute with a similar name exists - //~| SUGGESTION deprecated - //~| HELP add #![feature(custom_attribute)] to the crate attributes to enable +#[deprcated] //~ ERROR attribute `deprcated` is currently unknown +fn foo() {} -#[tests] //~ ERROR E0658 -fn bar() {} //~| HELP a built-in attribute with a similar name exists - //~| SUGGESTION test - //~| HELP add #![feature(custom_attribute)] to the crate attributes to enable +#[tests] //~ ERROR attribute `tests` is currently unknown to the compiler +fn bar() {} -#[rustc_err] //~ ERROR E0658 -fn main() {} //~| HELP add #![feature(rustc_attrs)] to the crate attributes to enable - // don't suggest rustc attributes +#[rustc_err] //~ ERROR attribute `rustc_err` is currently unknown +fn main() {} diff --git a/src/test/ui/suggestions/attribute-typos.stderr b/src/test/ui/suggestions/attribute-typos.stderr index 8367ff20aa408..ee063aaa12220 100644 --- a/src/test/ui/suggestions/attribute-typos.stderr +++ b/src/test/ui/suggestions/attribute-typos.stderr @@ -1,14 +1,14 @@ -error[E0658]: unless otherwise specified, attributes with the prefix `rustc_` are reserved for internal compiler diagnostics - --> $DIR/attribute-typos.rs:11:3 +error[E0658]: The attribute `rustc_err` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/attribute-typos.rs:7:3 | LL | #[rustc_err] | ^^^^^^^^^ | = note: for more information, see https://github.com/rust-lang/rust/issues/29642 - = help: add #![feature(rustc_attrs)] to the crate attributes to enable + = help: add #![feature(custom_attribute)] to the crate attributes to enable error[E0658]: The attribute `tests` is currently unknown to the compiler and may have meaning added to it in the future - --> $DIR/attribute-typos.rs:6:3 + --> $DIR/attribute-typos.rs:4:3 | LL | #[tests] | ^^^^^ help: a built-in attribute with a similar name exists: `test` From e4e7eb2d5891ceb9241f769540dd413e90020971 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 30 Jun 2019 13:00:45 +0300 Subject: [PATCH 2/2] Feature gate `rustc` attributes harder --- src/librustc_resolve/macros.rs | 19 +++++-- src/libsyntax/feature_gate.rs | 8 +++ .../run-pass-fulldeps/issue-15778-pass.rs | 2 +- .../feature-gates/feature-gate-rustc-attrs.rs | 19 ++++++- .../feature-gate-rustc-attrs.stderr | 52 ++++++++++++++++++- .../ui/proc-macro/expand-to-unstable-2.rs | 4 +- .../ui/proc-macro/expand-to-unstable-2.stderr | 11 +++- .../ui/reserved/reserved-attr-on-macro.rs | 2 + .../ui/reserved/reserved-attr-on-macro.stderr | 13 ++++- src/test/ui/suggestions/attribute-typos.rs | 5 +- .../ui/suggestions/attribute-typos.stderr | 11 +++- 11 files changed, 132 insertions(+), 14 deletions(-) diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 08a105572376c..522dc1aa9f8de 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -19,9 +19,8 @@ use syntax::ext::base::{MacroKind, SyntaxExtension}; use syntax::ext::expand::{AstFragment, Invocation, InvocationKind}; use syntax::ext::hygiene::Mark; use syntax::ext::tt::macro_rules; -use syntax::feature_gate::{ - feature_err, is_builtin_attr_name, AttributeGate, GateIssue, Stability, BUILTIN_ATTRIBUTES, -}; +use syntax::feature_gate::{feature_err, emit_feature_err, is_builtin_attr_name}; +use syntax::feature_gate::{AttributeGate, GateIssue, Stability, BUILTIN_ATTRIBUTES}; use syntax::symbol::{Symbol, kw, sym}; use syntax::visit::Visitor; use syntax::util::lev_distance::find_best_match_for_name; @@ -298,12 +297,25 @@ impl<'a> Resolver<'a> { let res = self.resolve_macro_to_res_inner(path, kind, parent_scope, trace, force); // Report errors and enforce feature gates for the resolved macro. + let features = self.session.features_untracked(); if res != Err(Determinacy::Undetermined) { // Do not report duplicated errors on every undetermined resolution. for segment in &path.segments { if let Some(args) = &segment.args { self.session.span_err(args.span(), "generic arguments in macro path"); } + if kind == MacroKind::Attr && !features.rustc_attrs && + segment.ident.as_str().starts_with("rustc") { + let msg = "attributes starting with `rustc` are \ + reserved for use by the `rustc` compiler"; + emit_feature_err( + &self.session.parse_sess, + sym::rustc_attrs, + segment.ident.span, + GateIssue::Language, + msg, + ); + } } } @@ -320,7 +332,6 @@ impl<'a> Resolver<'a> { } Res::NonMacroAttr(attr_kind) => { if kind == MacroKind::Attr { - let features = self.session.features_untracked(); if attr_kind == NonMacroAttrKind::Custom { assert!(path.segments.len() == 1); if !features.custom_attribute { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9aea995831edb..6037b06eaf20e 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1669,6 +1669,14 @@ impl<'a> Context<'a> { } debug!("check_attribute: {:?} is builtin, {:?}, {:?}", attr.path, ty, gateage); return; + } else { + for segment in &attr.path.segments { + if segment.ident.as_str().starts_with("rustc") { + let msg = "attributes starting with `rustc` are \ + reserved for use by the `rustc` compiler"; + gate_feature!(self, rustc_attrs, segment.ident.span, msg); + } + } } for &(n, ty) in self.plugin_attributes { if attr.path == n { diff --git a/src/test/run-pass-fulldeps/issue-15778-pass.rs b/src/test/run-pass-fulldeps/issue-15778-pass.rs index 23c1c0766770b..35152e7f4babd 100644 --- a/src/test/run-pass-fulldeps/issue-15778-pass.rs +++ b/src/test/run-pass-fulldeps/issue-15778-pass.rs @@ -2,7 +2,7 @@ // ignore-stage1 // compile-flags: -D crate-not-okay -#![feature(plugin, custom_attribute, custom_inner_attributes)] +#![feature(plugin, custom_attribute, custom_inner_attributes, rustc_attrs)] #![plugin(lint_for_crate)] #![rustc_crate_okay] diff --git a/src/test/ui/feature-gates/feature-gate-rustc-attrs.rs b/src/test/ui/feature-gates/feature-gate-rustc-attrs.rs index 95ff18213f797..d3a2e486416af 100644 --- a/src/test/ui/feature-gates/feature-gate-rustc-attrs.rs +++ b/src/test/ui/feature-gates/feature-gate-rustc-attrs.rs @@ -1,6 +1,23 @@ // Test that `#[rustc_*]` attributes are gated by `rustc_attrs` feature gate. +#![feature(decl_macro)] + +mod rustc { pub macro unknown() {} } +mod unknown { pub macro rustc() {} } + +#[rustc::unknown] +//~^ ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler +//~| ERROR macro `rustc::unknown` may not be used in attributes +fn f() {} + +#[unknown::rustc] +//~^ ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler +//~| ERROR macro `unknown::rustc` may not be used in attributes +fn g() {} + #[rustc_dummy] //~^ ERROR used by the test suite - +#[rustc_unknown] +//~^ ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler +//~| ERROR attribute `rustc_unknown` is currently unknown fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr b/src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr index 57dcc77e518f3..cdc7b27a749e5 100644 --- a/src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr +++ b/src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr @@ -1,5 +1,53 @@ +error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler + --> $DIR/feature-gate-rustc-attrs.rs:8:3 + | +LL | #[rustc::unknown] + | ^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(rustc_attrs)] to the crate attributes to enable + +error: macro `rustc::unknown` may not be used in attributes + --> $DIR/feature-gate-rustc-attrs.rs:8:1 + | +LL | #[rustc::unknown] + | ^^^^^^^^^^^^^^^^^ + +error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler + --> $DIR/feature-gate-rustc-attrs.rs:13:12 + | +LL | #[unknown::rustc] + | ^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(rustc_attrs)] to the crate attributes to enable + +error: macro `unknown::rustc` may not be used in attributes + --> $DIR/feature-gate-rustc-attrs.rs:13:1 + | +LL | #[unknown::rustc] + | ^^^^^^^^^^^^^^^^^ + +error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler + --> $DIR/feature-gate-rustc-attrs.rs:20:3 + | +LL | #[rustc_unknown] + | ^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(rustc_attrs)] to the crate attributes to enable + +error[E0658]: The attribute `rustc_unknown` is currently unknown to the compiler and may have meaning added to it in the future + --> $DIR/feature-gate-rustc-attrs.rs:20:3 + | +LL | #[rustc_unknown] + | ^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(custom_attribute)] to the crate attributes to enable + error[E0658]: used by the test suite - --> $DIR/feature-gate-rustc-attrs.rs:3:1 + --> $DIR/feature-gate-rustc-attrs.rs:18:1 | LL | #[rustc_dummy] | ^^^^^^^^^^^^^^ @@ -7,6 +55,6 @@ LL | #[rustc_dummy] = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(rustc_attrs)] to the crate attributes to enable -error: aborting due to previous error +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. 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 8ce3cde6f0432..437ae93093470 100644 --- a/src/test/ui/proc-macro/expand-to-unstable-2.rs +++ b/src/test/ui/proc-macro/expand-to-unstable-2.rs @@ -4,7 +4,9 @@ extern crate derive_unstable_2; #[derive(Unstable)] -//~^ ERROR attribute `rustc_foo` is currently unknown +//~^ ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler +//~| ERROR attribute `rustc_foo` is currently unknown to the compiler + struct A; fn main() { 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 77be3d5272394..803773db88e96 100644 --- a/src/test/ui/proc-macro/expand-to-unstable-2.stderr +++ b/src/test/ui/proc-macro/expand-to-unstable-2.stderr @@ -1,3 +1,12 @@ +error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler + --> $DIR/expand-to-unstable-2.rs:6:10 + | +LL | #[derive(Unstable)] + | ^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(rustc_attrs)] to the crate attributes to enable + error[E0658]: The attribute `rustc_foo` is currently unknown to the compiler and may have meaning added to it in the future --> $DIR/expand-to-unstable-2.rs:6:10 | @@ -7,6 +16,6 @@ LL | #[derive(Unstable)] = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(custom_attribute)] to the crate attributes to enable -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/reserved/reserved-attr-on-macro.rs b/src/test/ui/reserved/reserved-attr-on-macro.rs index 0ee6577f8a11d..cb535362266c0 100644 --- a/src/test/ui/reserved/reserved-attr-on-macro.rs +++ b/src/test/ui/reserved/reserved-attr-on-macro.rs @@ -1,5 +1,7 @@ #[rustc_attribute_should_be_reserved] //~^ ERROR attribute `rustc_attribute_should_be_reserved` is currently unknown +//~| ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler + macro_rules! foo { () => (()); } diff --git a/src/test/ui/reserved/reserved-attr-on-macro.stderr b/src/test/ui/reserved/reserved-attr-on-macro.stderr index 34b21ecd1265d..0c62c82017e18 100644 --- a/src/test/ui/reserved/reserved-attr-on-macro.stderr +++ b/src/test/ui/reserved/reserved-attr-on-macro.stderr @@ -1,3 +1,12 @@ +error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler + --> $DIR/reserved-attr-on-macro.rs:1:3 + | +LL | #[rustc_attribute_should_be_reserved] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(rustc_attrs)] to the crate attributes to enable + error[E0658]: The attribute `rustc_attribute_should_be_reserved` is currently unknown to the compiler and may have meaning added to it in the future --> $DIR/reserved-attr-on-macro.rs:1:3 | @@ -8,13 +17,13 @@ LL | #[rustc_attribute_should_be_reserved] = help: add #![feature(custom_attribute)] to the crate attributes to enable error: cannot determine resolution for the macro `foo` - --> $DIR/reserved-attr-on-macro.rs:8:5 + --> $DIR/reserved-attr-on-macro.rs:10:5 | LL | foo!(); | ^^^ | = note: import resolution is stuck, try simplifying macro imports -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/suggestions/attribute-typos.rs b/src/test/ui/suggestions/attribute-typos.rs index b45acbdd9206c..0e10131ce8d1f 100644 --- a/src/test/ui/suggestions/attribute-typos.rs +++ b/src/test/ui/suggestions/attribute-typos.rs @@ -4,5 +4,8 @@ fn foo() {} #[tests] //~ ERROR attribute `tests` is currently unknown to the compiler fn bar() {} -#[rustc_err] //~ ERROR attribute `rustc_err` is currently unknown +#[rustc_err] +//~^ ERROR attribute `rustc_err` is currently unknown +//~| ERROR attributes starting with `rustc` are reserved for use by the `rustc` compiler + fn main() {} diff --git a/src/test/ui/suggestions/attribute-typos.stderr b/src/test/ui/suggestions/attribute-typos.stderr index ee063aaa12220..958688b4d3906 100644 --- a/src/test/ui/suggestions/attribute-typos.stderr +++ b/src/test/ui/suggestions/attribute-typos.stderr @@ -1,3 +1,12 @@ +error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler + --> $DIR/attribute-typos.rs:7:3 + | +LL | #[rustc_err] + | ^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/29642 + = help: add #![feature(rustc_attrs)] to the crate attributes to enable + error[E0658]: The attribute `rustc_err` is currently unknown to the compiler and may have meaning added to it in the future --> $DIR/attribute-typos.rs:7:3 | @@ -25,6 +34,6 @@ LL | #[deprcated] = note: for more information, see https://github.com/rust-lang/rust/issues/29642 = help: add #![feature(custom_attribute)] to the crate attributes to enable -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0658`.