-
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.
Introduce proc_macro::DeriveExpansionOptions
- Loading branch information
Showing
11 changed files
with
198 additions
and
23 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
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
13 changes: 13 additions & 0 deletions
13
tests/ui/rfcs/rfc-2632-const-trait-impl/const_derives/auxiliary/is-derive-const.rs
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,13 @@ | ||
// force-host | ||
// no-prefer-dynamic | ||
#![crate_type = "proc-macro"] | ||
#![feature(derive_const)] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::{TokenStream, DeriveExpansionOptions}; | ||
|
||
#[proc_macro_derive(IsDeriveConst)] | ||
pub fn is_derive_const(_: TokenStream, options: DeriveExpansionOptions) -> TokenStream { | ||
format!("const IS_DERIVE_CONST: bool = {};", options.is_const()).parse().unwrap() | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/ui/rfcs/rfc-2632-const-trait-impl/const_derives/derive-const-custom.rs
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,20 @@ | ||
// check-pass | ||
// edition: 2021 | ||
// aux-crate:is_derive_const=is-derive-const.rs | ||
#![feature(derive_const)] | ||
|
||
const _: () = { | ||
#[derive(is_derive_const::IsDeriveConst)] | ||
struct _Type; | ||
|
||
assert!(!IS_DERIVE_CONST); | ||
}; | ||
|
||
const _: () = { | ||
#[derive_const(is_derive_const::IsDeriveConst)] | ||
struct _Type; | ||
|
||
assert!(IS_DERIVE_CONST); | ||
}; | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
tests/ui/rfcs/rfc-2632-const-trait-impl/const_derives/signature-proc-macro-derive.rs
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,19 @@ | ||
// Check that we suggest *both* possible signatures of derive proc macros, namely | ||
// fn(TokenStream) -> TokenStream | ||
// and | ||
// fn(TokenStream, DeriveExpansionOptions) -> TokenStream | ||
// provided libs feature `derive_const` is enabled. | ||
|
||
// force-host | ||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
#![feature(derive_const)] | ||
|
||
extern crate proc_macro; | ||
|
||
#[proc_macro_derive(Blah)] | ||
pub fn bad_input() -> proc_macro::TokenStream { | ||
//~^ ERROR derive proc macro has incorrect signature | ||
Default::default() | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/rfcs/rfc-2632-const-trait-impl/const_derives/signature-proc-macro-derive.stderr
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,16 @@ | ||
error: derive proc macro has incorrect signature | ||
--> $DIR/signature-proc-macro-derive.rs:16:1 | ||
| | ||
LL | pub fn bad_input() -> proc_macro::TokenStream { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| incorrect number of function parameters | ||
| incorrect number of function parameters | ||
| | ||
= note: expected signature `fn(proc_macro::TokenStream) -> proc_macro::TokenStream` | ||
found signature `fn() -> proc_macro::TokenStream` | ||
= note: expected signature `fn(proc_macro::TokenStream, DeriveExpansionOptions) -> proc_macro::TokenStream` | ||
found signature `fn() -> proc_macro::TokenStream` | ||
|
||
error: aborting due to 1 previous error | ||
|