-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
94 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error[E0277]: the trait bound `NotMacroArgs: FromMeta` is not satisfied | ||
--> tests/compile-fail/parse_meta.rs:8:16 | ||
| | ||
8 | let args = parse_meta!(args as NotMacroArgs); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromMeta` is not implemented for `NotMacroArgs` | ||
| | ||
= help: the following other types implement trait `FromMeta`: | ||
() | ||
Arc<T> | ||
AtomicBool | ||
ExprArray | ||
ExprPath | ||
Flag | ||
HashMap<proc_macro2::Ident, V, S> | ||
HashMap<std::string::String, V, S> | ||
and $N others | ||
= note: this error originates in the macro `parse_meta` (in Nightly builds, run with -Z macro-backtrace for more info) |
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 @@ | ||
extern crate proc_macro; | ||
use darling::parse_meta; | ||
use proc_macro::TokenStream; | ||
|
||
struct NotMacroArgs; | ||
|
||
pub fn invalid_receiver_type(args: TokenStream, _input: TokenStream) -> TokenStream { | ||
let args = parse_meta!(args as NotMacroArgs); | ||
|
||
unimplemented!() | ||
} | ||
|
||
fn main() {} |
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,17 @@ | ||
error[E0277]: the trait bound `NotMacroArgs: FromMeta` is not satisfied | ||
--> tests/compile-fail/parse_meta_invalid_receiver.rs:8:16 | ||
| | ||
8 | let args = parse_meta!(args as NotMacroArgs); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromMeta` is not implemented for `NotMacroArgs` | ||
| | ||
= help: the following other types implement trait `FromMeta`: | ||
() | ||
Arc<T> | ||
AtomicBool | ||
ExprArray | ||
ExprPath | ||
Flag | ||
HashMap<proc_macro2::Ident, V, S> | ||
HashMap<std::string::String, V, S> | ||
and $N others | ||
= note: this error originates in the macro `parse_meta` (in Nightly builds, run with -Z macro-backtrace for more info) |
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,13 @@ | ||
error[E0282]: type annotations needed | ||
--> tests/compile-fail/parse_meta_no_type.rs:14:9 | ||
| | ||
14 | let args = parse_meta!(args); | ||
| ^^^^ | ||
... | ||
17 | println!("{:?}", args.timeout_ms); | ||
| ---- type must be known at this point | ||
| | ||
help: consider giving `args` an explicit type | ||
| | ||
14 | let args: _ = parse_meta!(args); | ||
| +++ |
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,31 @@ | ||
extern crate proc_macro; | ||
use darling::{parse_meta, FromMeta}; | ||
use proc_macro::TokenStream; | ||
use syn::ItemFn; | ||
|
||
#[derive(Debug, Clone, FromMeta)] | ||
struct MacroArgs { | ||
#[darling(default)] | ||
timeout_ms: Option<u16>, | ||
path: String, | ||
} | ||
|
||
pub fn with_explicit_type(args: TokenStream, input: TokenStream) -> TokenStream { | ||
let _args = parse_meta!(args as MacroArgs); | ||
let _input = syn::parse_macro_input!(input as ItemFn); | ||
|
||
// do things with `args` | ||
unimplemented!() | ||
} | ||
|
||
pub fn example_with_inferred_type(args: TokenStream, _input: TokenStream) -> TokenStream { | ||
fn takes_macro_args(args: MacroArgs) -> Option<u16> { | ||
args.timeout_ms | ||
} | ||
|
||
let _timeout = takes_macro_args(parse_meta!(args)); | ||
|
||
unimplemented!() | ||
} | ||
|
||
fn main() {} |
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