rust-parse-generics icon indicating copy to clipboard operation
rust-parse-generics copied to clipboard

Does not handle type parameter defaults (parse-generics-shim)

Open bluss opened this issue 9 years ago • 0 comments

(Type parameter defaults is a stable feature since Rust 1.0)

Input code was something like this:

macro_rules! DebugBounds {
    (
        ($($bounds:tt)*) $($tail:tt)+
    ) => {
        parse_item! {
            then DebugBounds! { @item ($($bounds:tt)*) },
            $($tail)*
        }
    };
    (
        @item ($($bounds:tt)*)
        struct {
            attrs: $attrs:tt,
            vis: $vis:tt,
            name: $name:ident,
            generics: $generics:tt,
            where: $where_:tt,
            kind: $kind:ident,
            fields: $fields:tt,
            num_fields: $num_fields:tt,
            $($_struct_tail:tt)*
        }
    ) => {
    };
}

custom_derive! {
    /// The graph's edge type.
    #[derive(DebugBounds, Clone)]
    pub struct Edge<E, Ix = DefaultIx> {
        /// Associated edge data.
        pub weight: E,
        /// Next edge in outgoing and incoming edge lists.
        next: [EdgeIndex<Ix>; 2],
        /// Start and End node index
        node: [NodeIndex<Ix>; 2],
    }
}

Output something like this (tail end of a long macro trace)

parse_generics_shim! { @ parse {
{ constr , params , ltimes , tnames } , (
parse_struct ! {
@ with_generics ( ( DebugBounds ! { @ item (  ) } ) , [  ] , ( pub ) , Edge )
, } ) } , { constr : [ E , Ix , ] , ltimes : [  ] , tnames : [ E , Ix , ] , }
, = DefaultIx > {
# [ doc = r" Associated edge data." ] pub weight : E , # [
doc = r" Next edge in outgoing and incoming edge lists." ] next : [
EdgeIndex < Ix > ; 2 ] , # [ doc = r" Start and End node index" ] node : [
NodeIndex < Ix > ; 2 ] , } }
error: expected ident, found =
   --> src/graph.rs:217:27
    |
217 |     pub struct Edge<E, Ix = DefaultIx> {
    |                           ^

error: Could not compile `petgraph`.

In this case I don't need to parse the default, just that it is valid.

bluss avatar Oct 04 '16 18:10 bluss