Skip to content

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

@bluss

Description

@bluss

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions