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

proc_macro: Improve Debug representations #49748

Merged
merged 2 commits into from
Apr 7, 2018

Conversation

alexcrichton
Copy link
Member

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 #49720

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
@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2018
@alexcrichton
Copy link
Member Author

r? @petrochenkov

cc @dtolnay

@rust-highfive rust-highfive assigned petrochenkov and unassigned aturon Apr 6, 2018
#[unstable(feature = "proc_macro", issue = "38356")]
impl fmt::Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?} bytes({}...{})",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the lo/hi interval is half-open so {}..{} would be more accurate. Like in #49720 the + token is bytes(82..83).

A span covering a single byte, such as for an operator `+` token, should
print as e.g. `80..81` rather than `80...81`. The lo end of the range is
inclusive and the hi end is exclusive.
@dtolnay
Copy link
Member

dtolnay commented Apr 7, 2018

Here is sample debug output for the tokens [a + 1]. This is a huge improvement from what it looked like before this PR. Thanks!

TokenStream [
    Group {
        delimiter: Bracket,
        stream: TokenStream [
            Term {
                sym: a,
                span: #0 bytes(80..81)
            },
            Op {
                op: '+',
                spacing: Alone,
                span: #0 bytes(82..83)
            },
            Literal {
                lit: Integer(
                    1
                ),
                suffix: None,
                span: #0 bytes(84..85)
            }
        ],
        span: #0 bytes(79..86)
    }
]

@bors r+

@bors
Copy link
Contributor

bors commented Apr 7, 2018

📌 Commit 52766b5 has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 7, 2018
kennytm added a commit to kennytm/rust that referenced this pull request 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
bors added a commit that referenced this pull request Apr 7, 2018
Rollup of 9 pull requests

Successful merges:

 - #49510 (Fix anchor position on fields)
 - #49652 (Fix anchors issue when everything is collapsed)
 - #49702 (std: Inline some Termination-related methods)
 - #49728 (add emit_debug_gdb_scripts target option and ..)
 - #49731 (add THUMB targets to rustup manifest)
 - #49742 (Using X headings instead of 0.X #49739)
 - #49748 (proc_macro: Improve Debug representations)
 - #49750 (bootstrap: Remove the fast path)
 - #49503 (Inject the `compiler_builtins` crate whenever the `core` crate is injected)

Failed merges:
@bors bors merged commit 52766b5 into rust-lang:master Apr 7, 2018
@@ -717,7 +742,8 @@ impl fmt::Display for Term {
#[derive(Clone, Debug)]
#[unstable(feature = "proc_macro", issue = "38356")]
pub struct Literal {
token: token::Token,
lit: token::Lit,
suffix: Option<ast::Name>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice!

@alexcrichton alexcrichton deleted the proc-macro-debug branch April 20, 2018 06:03
@dtolnay dtolnay assigned dtolnay and unassigned petrochenkov Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Debug representation of proc_macro::TokenStream
7 participants