-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
proc_macro: Improve Debug representations #49748
Conversation
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
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
cc @dtolnay |
src/libproc_macro/lib.rs
Outdated
#[unstable(feature = "proc_macro", issue = "38356")] | ||
impl fmt::Debug for Span { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{:?} bytes({}...{})", |
There was a problem hiding this comment.
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.
Here is sample debug output for the tokens 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+ |
📌 Commit 52766b5 has been approved by |
…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
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:
@@ -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>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nice!
This commit improves the
fmt::Debug
output ofproc_macro
data structures byprimarily focusing on the representation exposed by
proc_macro
rather than thecompiler's own internal representation. This cuts down quite a bit on assorted
wrapper types and ensure a relatively clean output.
Closes #49720