Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Debug representation of proc_macro::TokenStream #49720

Closed
dtolnay opened this issue Apr 6, 2018 · 0 comments · Fixed by #49748
Closed

Improve Debug representation of proc_macro::TokenStream #49720

dtolnay opened this issue Apr 6, 2018 · 0 comments · Fixed by #49748
Assignees
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412)

Comments

@dtolnay
Copy link
Member

dtolnay commented Apr 6, 2018

Currently the Debug representation of the TokenStream corresponding to tokens [a + 1] is as follows. This is just delegating to the derived Debug impls of the underlying syntax::tokenstream::TokenStream.

Show current Debug representation of [a + 1]...
TokenStream {
    kind: Stream(
        [
            TokenStream {
                kind: Tree(
                    Delimited(
                        Span {
                            lo: BytePos(
                                79
                            ),
                            hi: BytePos(
                                86
                            ),
                            ctxt: #0
                        },
                        Delimited {
                            delim: Bracket,
                            tts: ThinTokenStream(
                                Some(
                                    [
                                        TokenStream {
                                            kind: Tree(
                                                Token(
                                                    Span {
                                                        lo: BytePos(
                                                            80
                                                        ),
                                                        hi: BytePos(
                                                            81
                                                        ),
                                                        ctxt: #0
                                                    },
                                                    Ident(
                                                        a#0,
                                                        false
                                                    )
                                                )
                                            )
                                        },
                                        TokenStream {
                                            kind: Tree(
                                                Token(
                                                    Span {
                                                        lo: BytePos(
                                                            82
                                                        ),
                                                        hi: BytePos(
                                                            83
                                                        ),
                                                        ctxt: #0
                                                    },
                                                    BinOp(
                                                        Plus
                                                    )
                                                )
                                            )
                                        },
                                        TokenStream {
                                            kind: Tree(
                                                Token(
                                                    Span {
                                                        lo: BytePos(
                                                            84
                                                        ),
                                                        hi: BytePos(
                                                            85
                                                        ),
                                                        ctxt: #0
                                                    },
                                                    Literal(
                                                        Integer(
                                                            1
                                                        ),
                                                        None
                                                    )
                                                )
                                            )
                                        }
                                    ]
                                )
                            )
                        }
                    )
                )
            }
        ]
    )
}

It would be far more helpful to have the Debug for proc_macro::TokenStream line up better with the TokenStream public API. Something like:

TokenStream [
    Group {
        delimiter: Bracket,
        stream: TokenStream [
            Term {
                name: "a",
                span: #0 bytes(80..81)
            },
            Op {
                op: '+',
                spacing: Alone,
                span: #0 bytes(82..83)
            },
            Literal {
                value: `1`,
                span: #0 bytes(84..85)
            }
        },
        span: #0 bytes(79..86)
    }
]
@dtolnay dtolnay added the A-macros-2.0 Area: Declarative macros 2.0 (#39412) label Apr 6, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 6, 2018
This commit improves the `fmt::Debug` output of `proc_macro` data structures by
primarily focusing on the representation exposed by `proc_macro` rather than the
compiler's own internal representation. This cuts down quite a bit on assorted
wrapper types and ensure a relatively clean output.

Closes rust-lang#49720
kennytm added a commit to kennytm/rust that referenced this issue Apr 7, 2018
…olnay

proc_macro: Improve Debug representations

This commit improves the `fmt::Debug` output of `proc_macro` data structures by
primarily focusing on the representation exposed by `proc_macro` rather than the
compiler's own internal representation. This cuts down quite a bit on assorted
wrapper types and ensure a relatively clean output.

Closes rust-lang#49720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants