Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve: Remove rustc_attrs as a standalone feature gate #70364

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use rustc_feature::is_builtin_attr_name;
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};
Expand Down Expand Up @@ -397,20 +396,16 @@ impl<'a> Resolver<'a> {
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",
);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui-fulldeps/auxiliary/lint-for-crate-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),*) => {
Expand Down Expand Up @@ -50,17 +50,17 @@ declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");

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]
Expand Down
33 changes: 0 additions & 33 deletions src/test/ui-fulldeps/auxiliary/macro-crate-test.rs

This file was deleted.

24 changes: 12 additions & 12 deletions src/test/ui-fulldeps/issue-15778-pass.rs
Original file line number Diff line number Diff line change
@@ -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() {}
12 changes: 3 additions & 9 deletions src/test/ui/feature-gates/feature-gate-rustc-attrs.stderr
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
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
|
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
|
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
Expand Down
32 changes: 32 additions & 0 deletions src/test/ui/proc-macro/auxiliary/duplicate.rs
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 1 addition & 3 deletions src/test/ui/proc-macro/expand-to-unstable-2.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
// check-pass
// aux-build:macro-crate-test.rs
// ignore-stage1
// The duplicate macro will create a copy of the item with the given identifier.

#![feature(rustc_attrs)]
// check-pass
// aux-build:duplicate.rs

#[macro_use]
extern crate macro_crate_test;

// The duplicate macro will create a copy of the item with the given identifier.
extern crate duplicate;

#[rustc_duplicate(MyCopy)]
#[duplicate(MyCopy)]
struct MyStruct {
number: i32
number: i32,
}

trait TestTrait {
#[rustc_duplicate(TestType2)]
#[duplicate(TestType2)]
type TestType;

#[rustc_duplicate(required_fn2)]
#[duplicate(required_fn2)]
fn required_fn(&self);

#[rustc_duplicate(provided_fn2)]
fn provided_fn(&self) { }
#[duplicate(provided_fn2)]
fn provided_fn(&self) {}
}

impl TestTrait for MyStruct {
#[rustc_duplicate(TestType2)]
#[duplicate(TestType2)]
type TestType = f64;

#[rustc_duplicate(required_fn2)]
fn required_fn(&self) { }
#[duplicate(required_fn2)]
fn required_fn(&self) {}
}

fn main() {
Expand Down
5 changes: 1 addition & 4 deletions src/test/ui/reserved/reserved-attr-on-macro.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`.
5 changes: 1 addition & 4 deletions src/test/ui/suggestions/attribute-typos.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -31,4 +29,3 @@ LL | #[deprcated]

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0658`.