-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix {:#?} representation of proc_macro::Literal #72233
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,10 +202,16 @@ impl Clone for Literal { | |
} | ||
} | ||
|
||
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls. | ||
impl fmt::Debug for Literal { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str(&self.debug()) | ||
f.debug_struct("Literal") | ||
// format the kind without quotes, as in `kind: Float` | ||
.field("kind", &format_args!("{}", &self.debug_kind())) | ||
Comment on lines
+208
to
+209
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comment. |
||
.field("symbol", &self.symbol()) | ||
// format `Some("...")` on one line even in {:#?} mode | ||
.field("suffix", &format_args!("{:?}", &self.suffix())) | ||
.field("span", &self.span()) | ||
.finish() | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/test/ui/lint/redundant-semicolon/redundant-semi-proc-macro.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/test/ui/proc-macro/debug/auxiliary/macro-dump-debug.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// force-host | ||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
#![crate_name = "macro_dump_debug"] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro] | ||
pub fn dump_debug(tokens: TokenStream) -> TokenStream { | ||
eprintln!("{:?}", tokens); | ||
eprintln!("{:#?}", tokens); | ||
TokenStream::new() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// run-pass | ||
// aux-build:macro-dump-debug.rs | ||
|
||
extern crate macro_dump_debug; | ||
use macro_dump_debug::dump_debug; | ||
|
||
dump_debug! { | ||
ident // ident | ||
r#ident // raw ident | ||
, // alone punct | ||
==> // joint punct | ||
() // empty group | ||
[_] // nonempty group | ||
|
||
// unsuffixed literals | ||
0 | ||
1.0 | ||
"S" | ||
b"B" | ||
r"R" | ||
r##"R"## | ||
br"BR" | ||
br##"BR"## | ||
'C' | ||
b'B' | ||
|
||
// suffixed literals | ||
0q | ||
1.0q | ||
"S"q | ||
b"B"q | ||
r"R"q | ||
r##"R"##q | ||
br"BR"q | ||
br##"BR"##q | ||
'C'q | ||
b'B'q | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
TokenStream [Ident { ident: "ident", span: #0 bytes(130..135) }, Ident { ident: "r#ident", span: #0 bytes(151..158) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(176..177) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(203..205) }, Punct { ch: '=', spacing: Joint, span: #0 bytes(203..205) }, Punct { ch: '>', spacing: Alone, span: #0 bytes(205..206) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #0 bytes(230..232) }, Group { delimiter: Bracket, stream: TokenStream [Ident { ident: "_", span: #0 bytes(258..259) }], span: #0 bytes(257..260) }, Literal { kind: Integer, symbol: "0", suffix: None, span: #0 bytes(315..316) }, Literal { kind: Float, symbol: "1.0", suffix: None, span: #0 bytes(321..324) }, Literal { kind: Str, symbol: "S", suffix: None, span: #0 bytes(329..332) }, Literal { kind: ByteStr, symbol: "B", suffix: None, span: #0 bytes(337..341) }, Literal { kind: StrRaw(0), symbol: "R", suffix: None, span: #0 bytes(346..350) }, Literal { kind: StrRaw(2), symbol: "R", suffix: None, span: #0 bytes(355..363) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: None, span: #0 bytes(368..374) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: None, span: #0 bytes(379..389) }, Literal { kind: Char, symbol: "C", suffix: None, span: #0 bytes(394..397) }, Literal { kind: Byte, symbol: "B", suffix: None, span: #0 bytes(402..406) }, Literal { kind: Integer, symbol: "0", suffix: Some("q"), span: #0 bytes(437..439) }, Literal { kind: Float, symbol: "1.0", suffix: Some("q"), span: #0 bytes(444..448) }, Literal { kind: Str, symbol: "S", suffix: Some("q"), span: #0 bytes(453..457) }, Literal { kind: ByteStr, symbol: "B", suffix: Some("q"), span: #0 bytes(462..467) }, Literal { kind: StrRaw(0), symbol: "R", suffix: Some("q"), span: #0 bytes(472..477) }, Literal { kind: StrRaw(2), symbol: "R", suffix: Some("q"), span: #0 bytes(482..491) }, Literal { kind: ByteStrRaw(0), symbol: "BR", suffix: Some("q"), span: #0 bytes(496..503) }, Literal { kind: ByteStrRaw(2), symbol: "BR", suffix: Some("q"), span: #0 bytes(508..519) }, Literal { kind: Char, symbol: "C", suffix: Some("q"), span: #0 bytes(524..528) }, Literal { kind: Byte, symbol: "B", suffix: Some("q"), span: #0 bytes(533..538) }] | ||
TokenStream [ | ||
Ident { | ||
ident: "ident", | ||
span: #0 bytes(130..135), | ||
}, | ||
Ident { | ||
ident: "r#ident", | ||
span: #0 bytes(151..158), | ||
}, | ||
Punct { | ||
ch: ',', | ||
spacing: Alone, | ||
span: #0 bytes(176..177), | ||
}, | ||
Punct { | ||
ch: '=', | ||
spacing: Joint, | ||
span: #0 bytes(203..205), | ||
}, | ||
Punct { | ||
ch: '=', | ||
spacing: Joint, | ||
span: #0 bytes(203..205), | ||
}, | ||
Punct { | ||
ch: '>', | ||
spacing: Alone, | ||
span: #0 bytes(205..206), | ||
}, | ||
Group { | ||
delimiter: Parenthesis, | ||
stream: TokenStream [], | ||
span: #0 bytes(230..232), | ||
}, | ||
Group { | ||
delimiter: Bracket, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "_", | ||
span: #0 bytes(258..259), | ||
}, | ||
], | ||
span: #0 bytes(257..260), | ||
}, | ||
Literal { | ||
kind: Integer, | ||
symbol: "0", | ||
suffix: None, | ||
span: #0 bytes(315..316), | ||
}, | ||
Literal { | ||
kind: Float, | ||
symbol: "1.0", | ||
suffix: None, | ||
span: #0 bytes(321..324), | ||
}, | ||
Literal { | ||
kind: Str, | ||
symbol: "S", | ||
suffix: None, | ||
span: #0 bytes(329..332), | ||
}, | ||
Literal { | ||
kind: ByteStr, | ||
symbol: "B", | ||
suffix: None, | ||
span: #0 bytes(337..341), | ||
}, | ||
Literal { | ||
kind: StrRaw(0), | ||
symbol: "R", | ||
suffix: None, | ||
span: #0 bytes(346..350), | ||
}, | ||
Literal { | ||
kind: StrRaw(2), | ||
symbol: "R", | ||
suffix: None, | ||
span: #0 bytes(355..363), | ||
}, | ||
Literal { | ||
kind: ByteStrRaw(0), | ||
symbol: "BR", | ||
suffix: None, | ||
span: #0 bytes(368..374), | ||
}, | ||
Literal { | ||
kind: ByteStrRaw(2), | ||
symbol: "BR", | ||
suffix: None, | ||
span: #0 bytes(379..389), | ||
}, | ||
Literal { | ||
kind: Char, | ||
symbol: "C", | ||
suffix: None, | ||
span: #0 bytes(394..397), | ||
}, | ||
Literal { | ||
kind: Byte, | ||
symbol: "B", | ||
suffix: None, | ||
span: #0 bytes(402..406), | ||
}, | ||
Literal { | ||
kind: Integer, | ||
symbol: "0", | ||
suffix: Some("q"), | ||
span: #0 bytes(437..439), | ||
}, | ||
Literal { | ||
kind: Float, | ||
symbol: "1.0", | ||
suffix: Some("q"), | ||
span: #0 bytes(444..448), | ||
}, | ||
Literal { | ||
kind: Str, | ||
symbol: "S", | ||
suffix: Some("q"), | ||
span: #0 bytes(453..457), | ||
}, | ||
Literal { | ||
kind: ByteStr, | ||
symbol: "B", | ||
suffix: Some("q"), | ||
span: #0 bytes(462..467), | ||
}, | ||
Literal { | ||
kind: StrRaw(0), | ||
symbol: "R", | ||
suffix: Some("q"), | ||
span: #0 bytes(472..477), | ||
}, | ||
Literal { | ||
kind: StrRaw(2), | ||
symbol: "R", | ||
suffix: Some("q"), | ||
span: #0 bytes(482..491), | ||
}, | ||
Literal { | ||
kind: ByteStrRaw(0), | ||
symbol: "BR", | ||
suffix: Some("q"), | ||
span: #0 bytes(496..503), | ||
}, | ||
Literal { | ||
kind: ByteStrRaw(2), | ||
symbol: "BR", | ||
suffix: Some("q"), | ||
span: #0 bytes(508..519), | ||
}, | ||
Literal { | ||
kind: Char, | ||
symbol: "C", | ||
suffix: Some("q"), | ||
span: #0 bytes(524..528), | ||
}, | ||
Literal { | ||
kind: Byte, | ||
symbol: "B", | ||
suffix: Some("q"), | ||
span: #0 bytes(533..538), | ||
}, | ||
] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
?
Or is it used to cancel the effect of
{:#?}
, similarly to the suffix? Could you add a comment then?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.
self.debug_kind()
is a String so your suggestion prints it with quotes around, which is not what I want. The {} representation prints without quotes, as inkind: Float
.