-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #87027 - petrochenkov:builderhelp, r=oli-obk
expand: Support helper attributes for built-in derive macros This is needed for #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`).
- Loading branch information
Showing
6 changed files
with
144 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} |