rustc: Tweak expansion order of custom derive

This commit alters the expansion order of custom macros-1.1 style `#[derive]`
modes. Instead of left-to-right the expansion now happens in three categories,
each of which is internally left-to-right:

* Old-style custom derive (`#[derive_Foo]`) is expanded
* New-style custom derive (macros 1.1) is expanded
* Built in derive modes are expanded

This gives built in derive modes maximal knowledge about the struct that's being
expanded and also avoids pesky issues like exposing `#[structural_match]` or
`#[rustc_copy_clone_marker]`.

cc #35900
This commit is contained in:
Alex Crichton 2016-09-27 11:51:56 -07:00
parent ea65ab6c7e
commit e5e7021ca5
4 changed files with 123 additions and 96 deletions

View file

@ -24,7 +24,6 @@ trait Append {
Append,
Eq)]
struct A {
//~^ ERROR: the semantics of constant patterns is not yet settled
inner: u32,
}

View file

@ -22,6 +22,6 @@ use rustc_macro::TokenStream;
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert!(input.contains("struct A;"));
assert!(input.contains("#[derive(Eq, Copy, Clone)]"));
"#[derive(Eq, Copy, Clone)] struct A;".parse().unwrap()
assert!(input.contains("#[derive(Debug, PartialEq, Eq, Copy, Clone)]"));
"#[derive(Debug, PartialEq, Eq, Copy, Clone)] struct A;".parse().unwrap()
}