-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use core::convert::identity to simplify code generation
- Loading branch information
Showing
6 changed files
with
74 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use darling::{FromDeriveInput, FromMeta}; | ||
|
||
#[derive(FromDeriveInput)] | ||
#[darling(attributes(demo))] | ||
pub struct Receiver { | ||
example1: String, | ||
#[darling( | ||
// This should fail because `example1` is a local that's been captured | ||
// from the `FromDeriveInput` impl. That's disallowed because exposing | ||
// those internals would make any change to the derived method body a | ||
// potentially-breaking change. | ||
with = |m| Ok( | ||
String::from_meta(m)?.to_uppercase() | ||
+ example1.1.as_ref().map(|s| s.as_str()).unwrap_or("") | ||
), | ||
default | ||
)] | ||
example2: String, | ||
} | ||
|
||
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,30 @@ | ||
error[E0308]: mismatched types | ||
--> tests/compile-fail/with_closure_capture.rs:12:16 | ||
| | ||
12 | with = |m| Ok( | ||
| ^ arguments to this function are incorrect | ||
| ________________| | ||
| | | ||
13 | | String::from_meta(m)?.to_uppercase() | ||
14 | | + example1.1.as_ref().map(|s| s.as_str()).unwrap_or("") | ||
15 | | ), | ||
| |_________^ expected fn pointer, found closure | ||
| | ||
= note: expected fn pointer `for<'a> fn(&'a syn::Meta) -> Result<String, darling::Error>` | ||
found closure `{closure@$DIR/tests/compile-fail/with_closure_capture.rs:12:16: 12:19}` | ||
note: closures can only be coerced to `fn` types if they do not capture any variables | ||
--> tests/compile-fail/with_closure_capture.rs:14:15 | ||
| | ||
14 | + example1.1.as_ref().map(|s| s.as_str()).unwrap_or("") | ||
| ^^^^^^^^ `example1` captured here | ||
help: the return type of this call is `{closure@$DIR/tests/compile-fail/with_closure_capture.rs:12:16: 12:19}` due to the type of the argument passed | ||
--> tests/compile-fail/with_closure_capture.rs:12:16 | ||
| | ||
12 | with = |m| Ok( | ||
| ________________^ | ||
13 | | String::from_meta(m)?.to_uppercase() | ||
14 | | + example1.1.as_ref().map(|s| s.as_str()).unwrap_or("") | ||
15 | | ), | ||
| |_________- this argument influences the return type of `{{root}}` | ||
note: function defined here | ||
--> /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/convert/mod.rs:104:14 |