Rollup merge of #87027 - petrochenkov:builderhelp, r=oli-obk

expand: Support helper attributes for built-in derive macros

This is needed for https://github.com/rust-lang/rust/pull/86735 (derive macro `Default` should have a helper attribute `default`).

With this PR we can specify helper attributes for built-in derives using syntax `#[rustc_builtin_macro(MacroName, attributes(attr1, attr2, ...))]` which mirrors equivalent syntax for proc macros `#[proc_macro_derive(MacroName, attributes(attr1, attr2, ...))]`.
Otherwise expansion infra was already ready for this.
The attribute parsing code is shared between proc macro derives and built-in macros (`fn parse_macro_name_and_helper_attrs`).
This commit is contained in:
Guillaume Gomez 2021-07-14 19:53:35 +02:00 committed by GitHub
commit 4d141f5e4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 144 additions and 81 deletions

View file

@ -0,0 +1,36 @@
// check-pass
// compile-flags: --crate-type=lib
#![feature(decl_macro)]
#![feature(lang_items)]
#![feature(no_core)]
#![feature(rustc_attrs)]
#![no_core]
#[rustc_builtin_macro]
macro derive() {}
#[rustc_builtin_macro(Default, attributes(default))]
macro Default() {}
mod default {
pub trait Default {
fn default() -> Self;
}
impl Default for u8 {
fn default() -> u8 {
0
}
}
}
#[lang = "sized"]
trait Sized {}
#[derive(Default)]
struct S {
#[default] // OK
field: u8,
}