]> git.lizzy.rs Git - rust.git/commitdiff
resolve: Remove `rustc_attrs` as a standalone feature gate
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 24 Mar 2020 17:41:16 +0000 (20:41 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Tue, 24 Mar 2020 18:37:29 +0000 (21:37 +0300)
Now it only gates specific built-in attributes

src/librustc_resolve/macros.rs
src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs
src/test/ui-fulldeps/auxiliary/macro-crate-test.rs [deleted file]
src/test/ui-fulldeps/issue-15778-pass.rs
src/test/ui-fulldeps/macro-crate-multi-decorator.rs [deleted file]
src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr
src/test/ui/proc-macro/auxiliary/duplicate.rs [new file with mode: 0644]
src/test/ui/proc-macro/expand-to-unstable-2.stderr
src/test/ui/proc-macro/macro-crate-multi-decorator.rs [new file with mode: 0644]
src/test/ui/reserved/reserved-attr-on-macro.stderr
src/test/ui/suggestions/attribute-typos.stderr

index 166fc48b44c4c87533a98d70638923557c56a937..a783cfa4811fd8988cb3852dbbb2cbeca1ae9c65 100644 (file)
@@ -20,7 +20,6 @@
 use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
 use rustc_hir::def_id;
 use rustc_session::lint::builtin::UNUSED_MACROS;
-use rustc_session::parse::feature_err;
 use rustc_session::Session;
 use rustc_span::edition::Edition;
 use rustc_span::hygiene::{self, ExpnData, ExpnId, ExpnKind};
@@ -397,20 +396,16 @@ fn smart_resolve_macro_path(
             Err(Determinacy::Undetermined) => return Err(Indeterminate),
         };
 
-        // Report errors and enforce feature gates for the resolved macro.
-        let features = self.session.features_untracked();
+        // Report errors for the resolved macro.
         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";
-                feature_err(&self.session.parse_sess, sym::rustc_attrs, segment.ident.span, msg)
-                    .emit();
+            if kind == MacroKind::Attr && segment.ident.as_str().starts_with("rustc") {
+                self.session.span_err(
+                    segment.ident.span,
+                    "attributes starting with `rustc` are reserved for use by the `rustc` compiler",
+                );
             }
         }
 
index 52620b2464bd667cf41223eec8dc8653244ada23..f8cb1640cb4c16d8a7dc770cb610bd22d9298a3c 100644 (file)
@@ -2,19 +2,19 @@
 
 #![feature(plugin_registrar, rustc_private)]
 #![feature(box_syntax)]
+
 extern crate rustc_driver;
 extern crate rustc_hir;
-extern crate rustc_span;
-#[macro_use]
 extern crate rustc_lint;
+extern crate rustc_span;
 #[macro_use]
 extern crate rustc_session;
 extern crate rustc_ast;
 
+use rustc_ast::attr;
 use rustc_driver::plugin::Registry;
 use rustc_lint::{LateContext, LateLintPass, LintContext, LintPass};
 use rustc_span::symbol::Symbol;
-use rustc_ast::attr;
 
 macro_rules! fake_lint_pass {
     ($struct:ident, $($attr:expr),*) => {
@@ -50,17 +50,17 @@ fn check_crate(&mut self, cx: &LateContext, krate: &rustc_hir::Crate) {
 
 fake_lint_pass! {
     PassOkay,
-    Symbol::intern("rustc_crate_okay")
+    Symbol::intern("crate_okay")
 }
 
 fake_lint_pass! {
     PassRedBlue,
-    Symbol::intern("rustc_crate_red"), Symbol::intern("rustc_crate_blue")
+    Symbol::intern("crate_red"), Symbol::intern("crate_blue")
 }
 
 fake_lint_pass! {
     PassGreyGreen,
-    Symbol::intern("rustc_crate_grey"), Symbol::intern("rustc_crate_green")
+    Symbol::intern("crate_grey"), Symbol::intern("crate_green")
 }
 
 #[plugin_registrar]
diff --git a/src/test/ui-fulldeps/auxiliary/macro-crate-test.rs b/src/test/ui-fulldeps/auxiliary/macro-crate-test.rs
deleted file mode 100644 (file)
index 56a560a..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-// force-host
-// no-prefer-dynamic
-
-#![crate_type = "proc-macro"]
-#![feature(rustc_private)]
-
-extern crate rustc_ast;
-extern crate rustc;
-extern crate rustc_driver;
-extern crate proc_macro;
-
-use proc_macro::{TokenTree, TokenStream};
-
-#[proc_macro_attribute]
-pub fn rustc_duplicate(attr: TokenStream, item: TokenStream) -> TokenStream {
-    let mut new_name = Some(attr.into_iter().nth(0).unwrap());
-    let mut encountered_idents = 0;
-    let input = item.to_string();
-    let ret = item.into_iter().map(move |token| match token {
-        TokenTree::Ident(_) if encountered_idents == 1 => {
-            encountered_idents += 1;
-            new_name.take().unwrap()
-        }
-        TokenTree::Ident(_) => {
-            encountered_idents += 1;
-            token
-        }
-        _ => token
-    }).collect::<TokenStream>();
-    let mut input_again = input.parse::<TokenStream>().unwrap();
-    input_again.extend(ret);
-    input_again
-}
index 4b3cf07e2830d26d3035765396c899687ce41b9a..c031dbc7155db2c49888f7c8f91340f8ecb9a289 100644 (file)
@@ -1,23 +1,23 @@
-// run-pass
+// check-pass
 // aux-build:lint-for-crate-rpass.rs
 // ignore-stage1
 // compile-flags: -D crate-not-okay
 
-#![feature(plugin, register_attr, custom_inner_attributes, rustc_attrs)]
+#![feature(plugin, register_attr, custom_inner_attributes)]
 
 #![register_attr(
-    rustc_crate_okay,
-    rustc_crate_blue,
-    rustc_crate_red,
-    rustc_crate_grey,
-    rustc_crate_green,
+    crate_okay,
+    crate_blue,
+    crate_red,
+    crate_grey,
+    crate_green,
 )]
 
 #![plugin(lint_for_crate_rpass)] //~ WARNING compiler plugins are deprecated
-#![rustc_crate_okay]
-#![rustc_crate_blue]
-#![rustc_crate_red]
-#![rustc_crate_grey]
-#![rustc_crate_green]
+#![crate_okay]
+#![crate_blue]
+#![crate_red]
+#![crate_grey]
+#![crate_green]
 
 fn main() {}
diff --git a/src/test/ui-fulldeps/macro-crate-multi-decorator.rs b/src/test/ui-fulldeps/macro-crate-multi-decorator.rs
deleted file mode 100644 (file)
index f21617b..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// check-pass
-// aux-build:macro-crate-test.rs
-// ignore-stage1
-
-#![feature(rustc_attrs)]
-
-#[macro_use]
-extern crate macro_crate_test;
-
-// The duplicate macro will create a copy of the item with the given identifier.
-
-#[rustc_duplicate(MyCopy)]
-struct MyStruct {
-    number: i32
-}
-
-trait TestTrait {
-    #[rustc_duplicate(TestType2)]
-    type TestType;
-
-    #[rustc_duplicate(required_fn2)]
-    fn required_fn(&self);
-
-    #[rustc_duplicate(provided_fn2)]
-    fn provided_fn(&self) { }
-}
-
-impl TestTrait for MyStruct {
-    #[rustc_duplicate(TestType2)]
-    type TestType = f64;
-
-    #[rustc_duplicate(required_fn2)]
-    fn required_fn(&self) { }
-}
-
-fn main() {
-    let s = MyStruct { number: 42 };
-    s.required_fn();
-    s.required_fn2();
-    s.provided_fn();
-    s.provided_fn2();
-
-    let s = MyCopy { number: 42 };
-}
index 1e039f17a0d115f3b080805791d3b600908633c9..1517a7a5c731ab0dfc42d2fae861f97c3698894d 100644 (file)
@@ -1,10 +1,8 @@
-error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
+error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
   --> $DIR/feature-gate-rustc-attrs.rs:8:3
    |
 LL | #[rustc::unknown]
    |   ^^^^^
-   |
-   = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
 
 error: expected attribute, found macro `rustc::unknown`
   --> $DIR/feature-gate-rustc-attrs.rs:8:3
@@ -12,13 +10,11 @@ error: expected attribute, found macro `rustc::unknown`
 LL | #[rustc::unknown]
    |   ^^^^^^^^^^^^^^ not an attribute
 
-error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
+error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
   --> $DIR/feature-gate-rustc-attrs.rs:13:12
    |
 LL | #[unknown::rustc]
    |            ^^^^^
-   |
-   = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
 
 error: expected attribute, found macro `unknown::rustc`
   --> $DIR/feature-gate-rustc-attrs.rs:13:3
@@ -26,13 +22,11 @@ error: expected attribute, found macro `unknown::rustc`
 LL | #[unknown::rustc]
    |   ^^^^^^^^^^^^^^ not an attribute
 
-error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
+error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
   --> $DIR/feature-gate-rustc-attrs.rs:20:3
    |
 LL | #[rustc_unknown]
    |   ^^^^^^^^^^^^^
-   |
-   = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
 
 error: cannot find attribute `rustc_unknown` in this scope
   --> $DIR/feature-gate-rustc-attrs.rs:20:3
diff --git a/src/test/ui/proc-macro/auxiliary/duplicate.rs b/src/test/ui/proc-macro/auxiliary/duplicate.rs
new file mode 100644 (file)
index 0000000..b8f82b4
--- /dev/null
@@ -0,0 +1,32 @@
+// force-host
+// no-prefer-dynamic
+
+#![deny(unused)]
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+use proc_macro::*;
+
+#[proc_macro_attribute]
+pub fn duplicate(attr: TokenStream, item: TokenStream) -> TokenStream {
+    let mut new_name = Some(attr.into_iter().nth(0).unwrap());
+    let mut encountered_idents = 0;
+    let input = item.to_string();
+    let ret = item
+        .into_iter()
+        .map(move |token| match token {
+            TokenTree::Ident(_) if encountered_idents == 1 => {
+                encountered_idents += 1;
+                new_name.take().unwrap()
+            }
+            TokenTree::Ident(_) => {
+                encountered_idents += 1;
+                token
+            }
+            _ => token,
+        })
+        .collect::<TokenStream>();
+    let mut input_again = input.parse::<TokenStream>().unwrap();
+    input_again.extend(ret);
+    input_again
+}
index 19144b210a12740bbf6f7e55e40d9e737f7e55a7..5974fa4c554ca33974d48832bfbe3a991e610de6 100644 (file)
@@ -1,12 +1,10 @@
-error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
+error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
   --> $DIR/expand-to-unstable-2.rs:10:10
    |
 LL | #[derive(Unstable)]
    |          ^^^^^^^^
    |
-   = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/proc-macro/macro-crate-multi-decorator.rs b/src/test/ui/proc-macro/macro-crate-multi-decorator.rs
new file mode 100644 (file)
index 0000000..ec57dec
--- /dev/null
@@ -0,0 +1,41 @@
+// The duplicate macro will create a copy of the item with the given identifier.
+
+// check-pass
+// aux-build:duplicate.rs
+
+#[macro_use]
+extern crate duplicate;
+
+#[duplicate(MyCopy)]
+struct MyStruct {
+    number: i32,
+}
+
+trait TestTrait {
+    #[duplicate(TestType2)]
+    type TestType;
+
+    #[duplicate(required_fn2)]
+    fn required_fn(&self);
+
+    #[duplicate(provided_fn2)]
+    fn provided_fn(&self) {}
+}
+
+impl TestTrait for MyStruct {
+    #[duplicate(TestType2)]
+    type TestType = f64;
+
+    #[duplicate(required_fn2)]
+    fn required_fn(&self) {}
+}
+
+fn main() {
+    let s = MyStruct { number: 42 };
+    s.required_fn();
+    s.required_fn2();
+    s.provided_fn();
+    s.provided_fn2();
+
+    let s = MyCopy { number: 42 };
+}
index c387bba0a13102c9fbb424a6021f4c34a00786dc..e55b58bef28554fda81ac849b1b2b7e4b574c9de 100644 (file)
@@ -1,10 +1,8 @@
-error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
+error: 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]
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
 
 error: cannot determine resolution for the macro `foo`
   --> $DIR/reserved-attr-on-macro.rs:10:5
@@ -22,4 +20,3 @@ LL | #[rustc_attribute_should_be_reserved]
 
 error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0658`.
index c7c257ba5fe5386ace366ae430588704de0b3fb1..1c307f0e2c19cb9278196a34a763ec8153c166f5 100644 (file)
@@ -1,10 +1,8 @@
-error[E0658]: attributes starting with `rustc` are reserved for use by the `rustc` compiler
+error: attributes starting with `rustc` are reserved for use by the `rustc` compiler
   --> $DIR/attribute-typos.rs:11:3
    |
 LL | #[rustc_err]
    |   ^^^^^^^^^
-   |
-   = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
 
 error: cannot find attribute `rustc_err` in this scope
   --> $DIR/attribute-typos.rs:11:3
@@ -31,4 +29,3 @@ LL | #[deprcated]
 
 error: aborting due to 4 previous errors
 
-For more information about this error, try `rustc --explain E0658`.