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
This commit is contained in:
commit
354a29a5f1
10 changed files with 160 additions and 51 deletions
|
|
@ -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() {}
|
||||
|
|
|
|||
32
src/test/ui-fulldeps/attribute-order-restricted.rs
Normal file
32
src/test/ui-fulldeps/attribute-order-restricted.rs
Normal file
|
|
@ -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) {}
|
||||
32
src/test/ui-fulldeps/attribute-order-restricted.stderr
Normal file
32
src/test/ui-fulldeps/attribute-order-restricted.stderr
Normal file
|
|
@ -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
|
||||
|
||||
|
|
@ -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() {}
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
| ^^^^^^^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue