Skip to content

Commit

Permalink
Enable macro modularization implicitly if one of "advanced" macro fea…
Browse files Browse the repository at this point in the history
…tures is enabled

Do not mark all builtin attributes as used when macro modularization is enabled
  • Loading branch information
petrochenkov committed Aug 6, 2018
1 parent f60d96a commit cb64672
Show file tree
Hide file tree
Showing 38 changed files with 44 additions and 50 deletions.
12 changes: 8 additions & 4 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ macro_rules! declare_features {
}

pub fn use_extern_macros(&self) -> bool {
// The `decl_macro`, `tool_attributes` and `custom_attributes`
// features imply `use_extern_macros`.
// A number of "advanced" macro features enable
// macro modularization (`use_extern_macros`) implicitly.
self.use_extern_macros || self.decl_macro ||
self.tool_attributes || self.custom_attribute
self.tool_attributes || self.custom_attribute ||
self.macros_in_extern || self.proc_macro_path_invoc ||
self.proc_macro_mod || self.proc_macro_expr ||
self.proc_macro_non_items || self.proc_macro_gen ||
self.stmt_expr_attributes
}
}
};
Expand Down Expand Up @@ -700,7 +704,7 @@ pub fn is_builtin_attr_name(name: ast::Name) -> bool {
}

pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
BUILTIN_ATTRIBUTES.iter().any(|&(builtin_name, _, _)| attr.check_name(builtin_name)) ||
BUILTIN_ATTRIBUTES.iter().any(|&(builtin_name, _, _)| attr.path == builtin_name) ||
attr.name().as_str().starts_with("rustc_")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

//! Attributes producing expressions in invalid locations
#![feature(use_extern_macros, stmt_expr_attributes, proc_macro_expr)]
#![feature(stmt_expr_attributes, proc_macro_expr)]

extern crate attr_stmt_expr;
use attr_stmt_expr::{duplicate, no_output};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:attr-stmt-expr.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_expr)]
#![feature(proc_macro_expr)]

extern crate attr_stmt_expr;
use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr};
Expand Down
2 changes: 0 additions & 2 deletions src/test/compile-fail-fulldeps/proc-macro/issue-50493.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// aux-build:issue_50493.rs
// ignore-stage1

#![feature(proc_macro)]

#[macro_use]
extern crate issue_50493;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:bang_proc_macro2.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_non_items)]
#![feature(proc_macro_non_items)]
#![allow(unused_macros)]

extern crate bang_proc_macro2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:attr_proc_macro.rs
// ignore-tidy-linelength

#![feature(use_extern_macros, custom_attribute)]
#![feature(custom_attribute)]
//~^ ERROR Cannot use `#![feature(use_extern_macros)]` and `#![feature(custom_attribute)] at the same time

extern crate attr_proc_macro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// gate-test-proc_macro_mod
// gate-test-proc_macro_gen

#![feature(use_extern_macros, stmt_expr_attributes)]
#![feature(stmt_expr_attributes)]

extern crate proc_macro_gates as foo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:proc-macro-gates.rs

#![feature(use_extern_macros, stmt_expr_attributes)]
#![feature(stmt_expr_attributes)]

extern crate proc_macro_gates as foo;

Expand Down
4 changes: 0 additions & 4 deletions src/test/compile-fail/macro-with-seps-err-msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

// gate-test-use_extern_macros

#![feature(proc_macro_path_invoc)]

fn main() {
globnar::brotz!(); //~ ERROR non-ident macro paths are experimental
#[derive(foo::Bar)] struct T; //~ ERROR non-ident macro paths are experimental
::foo!(); //~ ERROR non-ident macro paths are experimental
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/unknown-tool-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(use_extern_macros, proc_macro_path_invoc)]
#![feature(proc_macro_path_invoc)]

#[foo::bar] //~ ERROR failed to resolve. Use of undeclared type or module `foo`
fn main() {}
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/auxiliary/cond_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// no-prefer-dynamic

#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate proc_macro;

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/auxiliary/hello_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// no-prefer-dynamic

#![crate_type = "proc-macro"]
#![feature(use_extern_macros, proc_macro_non_items, proc_macro_quote)]
#![feature(proc_macro_non_items, proc_macro_quote)]

extern crate proc_macro;

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/auxiliary/proc_macro_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// no-prefer-dynamic

#![crate_type = "proc-macro"]
#![feature(proc_macro, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate proc_macro;

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/macro-quote-cond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:cond_plugin.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate cond_plugin;

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/macro-quote-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// aux-build:hello_macro.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_non_items, proc_macro_gen)]
#![feature(proc_macro_non_items, proc_macro_gen)]

extern crate hello_macro;

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/proc-macro/attr-stmt-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:attr-stmt-expr.rs
// ignore-stage1

#![feature(use_extern_macros, stmt_expr_attributes, proc_macro_expr)]
#![feature(stmt_expr_attributes, proc_macro_expr)]

extern crate attr_stmt_expr;
use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// no-prefer-dynamic

#![feature(proc_macro_non_items, proc_macro_quote, use_extern_macros)]
#![feature(proc_macro_non_items, proc_macro_quote)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// no-prefer-dynamic

#![feature(use_extern_macros, proc_macro_quote, proc_macro_non_items)]
#![feature(proc_macro_quote, proc_macro_non_items)]
#![crate_type = "proc-macro"]

extern crate proc_macro as proc_macro_renamed; // This does not break `quote!`
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/proc-macro/bang-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:bang-macro.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate bang_macro;
use bang_macro::rewrite;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/proc-macro/call-site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:call-site.rs
// ignore-stage1

#![feature(proc_macro_non_items, use_extern_macros)]
#![feature(proc_macro_non_items)]

extern crate call_site;
use call_site::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:count_compound_ops.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate count_compound_ops;
use count_compound_ops::count_compound_ops;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/proc-macro/derive-b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:derive-b.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_path_invoc)]
#![feature(proc_macro_path_invoc)]

extern crate derive_b;

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/proc-macro/hygiene_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// aux-build:hygiene_example.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate hygiene_example;
use hygiene_example::hello;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/proc-macro/macros-in-extern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// ignore-stage1
// ignore-wasm32

#![feature(use_extern_macros, macros_in_extern)]
#![feature(macros_in_extern)]

extern crate test_macros;

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass-fulldeps/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// ignore-stage1
// ignore-cross-compile

#![feature(use_extern_macros, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate proc_macro_def;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/auxiliary/attr_proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// force-host
// no-prefer-dynamic
#![feature(proc_macro)]

#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/auxiliary/bang_proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// force-host
// no-prefer-dynamic
#![feature(proc_macro)]

#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui-fulldeps/auxiliary/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// no-prefer-dynamic

#![feature(proc_macro)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:lifetimes.rs

#![feature(use_extern_macros, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate lifetimes;

Expand Down
1 change: 0 additions & 1 deletion src/test/ui-fulldeps/proc-macro/auxiliary/generate-mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// run-pass
// no-prefer-dynamic

#![feature(proc_macro)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/proc-macro/generate-mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// aux-build:generate-mod.rs

#![feature(use_extern_macros, proc_macro_gen, proc_macro_path_invoc)]
#![feature(proc_macro_gen, proc_macro_path_invoc)]

extern crate generate_mod;

Expand Down
1 change: 0 additions & 1 deletion src/test/ui-fulldeps/proc-macro/invalid-attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// no-prefer-dynamic

#![crate_type = "proc-macro"]
#![feature(proc_macro)]

extern crate proc_macro;

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui-fulldeps/proc-macro/invalid-attributes.stderr
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
error: `#[proc_macro]` attribute does not take any arguments
--> $DIR/invalid-attributes.rs:20:1
--> $DIR/invalid-attributes.rs:19:1
|
LL | #[proc_macro = "test"] //~ ERROR: does not take any arguments
| ^^^^^^^^^^^^^^^^^^^^^^

error: `#[proc_macro]` attribute does not take any arguments
--> $DIR/invalid-attributes.rs:23:1
--> $DIR/invalid-attributes.rs:22:1
|
LL | #[proc_macro()] //~ ERROR: does not take any arguments
| ^^^^^^^^^^^^^^^

error: `#[proc_macro]` attribute does not take any arguments
--> $DIR/invalid-attributes.rs:26:1
--> $DIR/invalid-attributes.rs:25:1
|
LL | #[proc_macro(x)] //~ ERROR: does not take any arguments
| ^^^^^^^^^^^^^^^^

error: `#[proc_macro_attribute]` attribute does not take any arguments
--> $DIR/invalid-attributes.rs:29:1
--> $DIR/invalid-attributes.rs:28:1
|
LL | #[proc_macro_attribute = "test"] //~ ERROR: does not take any arguments
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: `#[proc_macro_attribute]` attribute does not take any arguments
--> $DIR/invalid-attributes.rs:32:1
--> $DIR/invalid-attributes.rs:31:1
|
LL | #[proc_macro_attribute()] //~ ERROR: does not take any arguments
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: `#[proc_macro_attribute]` attribute does not take any arguments
--> $DIR/invalid-attributes.rs:35:1
--> $DIR/invalid-attributes.rs:34:1
|
LL | #[proc_macro_attribute(x)] //~ ERROR: does not take any arguments
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// no-prefer-dynamic

#![feature(proc_macro, decl_macro)]
#![feature(decl_macro)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui-fulldeps/proc-macro/non-root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// no-prefer-dynamic

#![feature(proc_macro)]
#![crate_type = "proc-macro"]

extern crate proc_macro;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/proc-macro/non-root.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: functions tagged with `#[proc_macro]` must currently reside in the root of the crate
--> $DIR/non-root.rs:21:5
--> $DIR/non-root.rs:20:5
|
LL | pub fn foo(arg: TokenStream) -> TokenStream { arg }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui-fulldeps/proc-macro/three-equals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:three-equals.rs
// ignore-stage1

#![feature(use_extern_macros, proc_macro_non_items)]
#![feature(proc_macro_non_items)]

extern crate three_equals;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/imports/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// aux-build:two_macros.rs

#![feature(item_like_imports, use_extern_macros)]
#![feature(use_extern_macros)]

extern crate two_macros; // two identity macros `m` and `n`

Expand Down

0 comments on commit cb64672

Please sign in to comment.