@@ -1575,6 +1575,17 @@ pub(crate) mod attr {
15751575 #[ cfg( feature = "try_from" ) ]
15761576 pub ( crate ) use self :: { repr_conversion:: ReprConversion , repr_int:: ReprInt } ;
15771577
1578+ /// A callable expression accepted as an attribute argument: a function call
1579+ /// (`foo(arg)`), a path to a function (`foo::bar`), or a closure (`|x| ...`).
1580+ #[ cfg( any(
1581+ feature = "eq" ,
1582+ feature = "from_str" ,
1583+ feature = "hash" ,
1584+ feature = "try_into" ,
1585+ ) ) ]
1586+ pub ( crate ) type Callable =
1587+ Either < syn:: ExprCall , Either < syn:: Path , syn:: ExprClosure > > ;
1588+
15781589 /// [`Parse`]ing with additional state or metadata.
15791590 pub ( crate ) trait Parser {
15801591 /// [`Parse`]s an item, using additional state or metadata.
@@ -2173,10 +2184,10 @@ pub(crate) mod attr {
21732184 pub ( crate ) mod error {
21742185 use syn:: parse:: { Parse , ParseStream } ;
21752186
2176- use super :: { Either , ParseMultiple } ;
2187+ use super :: { Callable , ParseMultiple } ;
21772188
21782189 /// Representation of an attribute, specifying the error type and, optionally, a
2179- /// [`Conversion`] from a built-in error type.
2190+ /// [`Callable`] conversion from a built-in error type.
21802191 ///
21812192 /// ```rust,ignore
21822193 /// #[<attribute>(error(<ty>))]
@@ -2189,7 +2200,7 @@ pub(crate) mod attr {
21892200 /// Custom conversion.
21902201 ///
21912202 /// If [`None`], then [`Into`] conversion should be applied.
2192- pub ( crate ) conv : Option < Conversion > ,
2203+ pub ( crate ) conv : Option < Callable > ,
21932204 }
21942205
21952206 impl Parse for Error {
@@ -2212,7 +2223,7 @@ pub(crate) mod attr {
22122223
22132224 _ = syn:: token:: Comma :: parse ( & inner) ?;
22142225
2215- let conv = Conversion :: parse ( & inner) ?;
2226+ let conv = Callable :: parse ( & inner) ?;
22162227 if inner. is_empty ( ) {
22172228 Ok ( Self {
22182229 ty,
@@ -2228,12 +2239,6 @@ pub(crate) mod attr {
22282239 }
22292240
22302241 impl ParseMultiple for Error { }
2231-
2232- /// Possible conversions of an [`attr::Error`].
2233- ///
2234- /// [`attr::Error`]: Error
2235- pub ( crate ) type Conversion =
2236- Either < syn:: ExprCall , Either < syn:: Path , syn:: ExprClosure > > ;
22372242 }
22382243
22392244 #[ cfg( feature = "try_from" ) ]
@@ -2411,16 +2416,16 @@ pub(crate) mod attr {
24112416 use syn:: parenthesized;
24122417 use syn:: parse:: { Parse , ParseStream } ;
24132418
2414- use crate :: utils:: attr:: ParseMultiple ;
2419+ use crate :: utils:: attr:: { Callable , ParseMultiple } ;
24152420
24162421 /// Representation of an attribute, specifying a custom function for a trait method.
24172422 ///
24182423 /// ```rust,ignore
2419- /// #[<attribute>(with(<path >))]
2424+ /// #[<attribute>(with(<func >))]
24202425 /// ```
24212426 pub ( crate ) struct With {
24222427 /// Custom function.
2423- pub ( crate ) func : syn :: Path , // TODO: Support `syn::ExprCall` and `syn::ExprClosure` too.
2428+ pub ( crate ) func : Callable ,
24242429 }
24252430
24262431 impl Parse for With {
@@ -2432,9 +2437,9 @@ pub(crate) mod attr {
24322437 "unknown attribute argument, expected `with(...)` argument here" ,
24332438 ) ) ;
24342439 }
2435- let path_and_parents ;
2436- parenthesized ! ( path_and_parents in input) ;
2437- let func = path_and_parents . parse :: < syn :: Path > ( ) ?;
2440+ let func_tokens ;
2441+ parenthesized ! ( func_tokens in input) ;
2442+ let func = func_tokens . parse :: < Callable > ( ) ?;
24382443 Ok ( Self { func } )
24392444 }
24402445 }
0 commit comments