diff options
| author | bors <bors@rust-lang.org> | 2018-09-17 18:13:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-09-17 18:13:26 +0000 |
| commit | 354a29a5f1feb55bd799f874786e013beddfd645 (patch) | |
| tree | 5d8b8dc7b289b1af380df5fdbe86751fe9f42693 /src/test | |
| parent | 186fe091434b4c20c160b8098a56bb6a841bf6b1 (diff) | |
| parent | 229df02c0b85c33465d7191a6e085e964e56c1c9 (diff) | |
| download | rust-354a29a5f1feb55bd799f874786e013beddfd645.tar.gz rust-354a29a5f1feb55bd799f874786e013beddfd645.zip | |
Auto merge of #54277 - petrochenkov:afterder, r=alexcrichton
Temporarily prohibit proc macro attributes placed after derives ... and also proc macro attributes used together with `#[test]`/`#[bench]`. Addresses item 6 from https://github.com/rust-lang/rust/pull/50911#issuecomment-411605393. The end goal is straightforward predictable left-to-right expansion order for attributes. Right now derives are expanded last regardless of their relative ordering with macro attributes and right now it's simpler to temporarily prohibit macro attributes placed after derives than changing the expansion order. I'm not sure whether the new beta is already released or not, but if it's released, then this patch needs to be backported, so the solution needs to be minimal. How to fix broken code (derives): - Move macro attributes above derives. This won't change expansion order, they are expanded before derives anyway. Using attribute macros on same items with `#[test]` and `#[bench]` is prohibited for similar expansion order reasons, but this one is going to be reverted much sooner than restrictions on derives. How to fix broken code (test/bench): - Enable `#![feature(plugin)]` (don't ask why). r? @ghost
Diffstat (limited to 'src/test')
5 files changed, 68 insertions, 4 deletions
diff --git a/src/test/compile-fail-fulldeps/proc-macro/proc-macro-attributes.rs b/src/test/compile-fail-fulldeps/proc-macro/proc-macro-attributes.rs index 215d51c2270..83bbb7c13c4 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/proc-macro-attributes.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/proc-macro-attributes.rs @@ -16,12 +16,12 @@ #[macro_use] extern crate derive_b; -#[derive(B)] #[B] //~ ERROR `B` is a derive mode #[C] #[B(D)] #[B(E = "foo")] #[B(arbitrary tokens)] +#[derive(B)] struct B; fn main() {} diff --git a/src/test/ui-fulldeps/attribute-order-restricted.rs b/src/test/ui-fulldeps/attribute-order-restricted.rs new file mode 100644 index 00000000000..553cd86e620 --- /dev/null +++ b/src/test/ui-fulldeps/attribute-order-restricted.rs @@ -0,0 +1,32 @@ +// aux-build:attr_proc_macro.rs +// compile-flags:--test + +#![feature(test)] + +extern crate test; +extern crate attr_proc_macro; +use attr_proc_macro::*; + +#[attr_proc_macro] // OK +#[derive(Clone)] +struct Before; + +#[derive(Clone)] +#[attr_proc_macro] //~ ERROR macro attributes must be placed before `#[derive]` +struct After; + +#[attr_proc_macro] //~ ERROR macro attributes cannot be used together with `#[test]` or `#[bench]` +#[test] +fn test_before() {} + +#[test] +#[attr_proc_macro] //~ ERROR macro attributes cannot be used together with `#[test]` or `#[bench]` +fn test_after() {} + +#[attr_proc_macro] //~ ERROR macro attributes cannot be used together with `#[test]` or `#[bench]` +#[bench] +fn bench_before(b: &mut test::Bencher) {} + +#[bench] +#[attr_proc_macro] //~ ERROR macro attributes cannot be used together with `#[test]` or `#[bench]` +fn bench_after(b: &mut test::Bencher) {} diff --git a/src/test/ui-fulldeps/attribute-order-restricted.stderr b/src/test/ui-fulldeps/attribute-order-restricted.stderr new file mode 100644 index 00000000000..841fc630b22 --- /dev/null +++ b/src/test/ui-fulldeps/attribute-order-restricted.stderr @@ -0,0 +1,32 @@ +error: macro attributes must be placed before `#[derive]` + --> $DIR/attribute-order-restricted.rs:15:1 + | +LL | #[attr_proc_macro] //~ ERROR macro attributes must be placed before `#[derive]` + | ^^^^^^^^^^^^^^^^^^ + +error: macro attributes cannot be used together with `#[test]` or `#[bench]` + --> $DIR/attribute-order-restricted.rs:18:1 + | +LL | #[attr_proc_macro] //~ ERROR macro attributes cannot be used together with `#[test]` or `#[bench]` + | ^^^^^^^^^^^^^^^^^^ + +error: macro attributes cannot be used together with `#[test]` or `#[bench]` + --> $DIR/attribute-order-restricted.rs:23:1 + | +LL | #[attr_proc_macro] //~ ERROR macro attributes cannot be used together with `#[test]` or `#[bench]` + | ^^^^^^^^^^^^^^^^^^ + +error: macro attributes cannot be used together with `#[test]` or `#[bench]` + --> $DIR/attribute-order-restricted.rs:26:1 + | +LL | #[attr_proc_macro] //~ ERROR macro attributes cannot be used together with `#[test]` or `#[bench]` + | ^^^^^^^^^^^^^^^^^^ + +error: macro attributes cannot be used together with `#[test]` or `#[bench]` + --> $DIR/attribute-order-restricted.rs:31:1 + | +LL | #[attr_proc_macro] //~ ERROR macro attributes cannot be used together with `#[test]` or `#[bench]` + | ^^^^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + diff --git a/src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.rs b/src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.rs index c2357d501ee..aa9eae0ba31 100644 --- a/src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.rs +++ b/src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.rs @@ -3,8 +3,8 @@ extern crate derive_helper_shadowing; use derive_helper_shadowing::*; -#[derive(MyTrait)] #[my_attr] //~ ERROR `my_attr` is ambiguous +#[derive(MyTrait)] struct S; fn main() {} diff --git a/src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.stderr b/src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.stderr index d597b577bb7..cdfecb3d101 100644 --- a/src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.stderr +++ b/src/test/ui-fulldeps/proc-macro/derive-helper-shadowing.stderr @@ -1,5 +1,5 @@ error[E0659]: `my_attr` is ambiguous - --> $DIR/derive-helper-shadowing.rs:7:3 + --> $DIR/derive-helper-shadowing.rs:6:3 | LL | #[my_attr] //~ ERROR `my_attr` is ambiguous | ^^^^^^^ ambiguous name @@ -10,7 +10,7 @@ note: `my_attr` could refer to the name imported here LL | use derive_helper_shadowing::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: `my_attr` could also refer to the name defined here - --> $DIR/derive-helper-shadowing.rs:6:10 + --> $DIR/derive-helper-shadowing.rs:7:10 | LL | #[derive(MyTrait)] | ^^^^^^^ |
