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:
commit
4d141f5e4c
6 changed files with 144 additions and 81 deletions
36
src/test/ui/deriving/deriving-with-helper.rs
Normal file
36
src/test/ui/deriving/deriving-with-helper.rs
Normal 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,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue