-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
Before: TokenStream [ Ident { ident: "name", span: #0 bytes(37..41), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(42..43), }, Literal { lit: Lit { kind: Str, symbol: "SNPP", suffix: None }, span: Span { lo: BytePos(44), hi: BytePos(50), ctxt: #0 } }, Punct { ch: ',', spacing: Alone, span: #0 bytes(50..51), }, Ident { ident: "owner", span: #0 bytes(56..61), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(62..63), }, Literal { lit: Lit { kind: Str, symbol: "Canary M Burns", suffix: None }, span: Span { lo: BytePos(64), hi: BytePos(80), ctxt: #0 } }, ] After: TokenStream [ Ident { ident: "name", span: #0 bytes(37..41), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(42..43), }, Literal { kind: Str, symbol: "SNPP", suffix: None, span: #0 bytes(44..50), }, Punct { ch: ',', spacing: Alone, span: #0 bytes(50..51), }, Ident { ident: "owner", span: #0 bytes(56..61), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(62..63), }, Literal { kind: Str, symbol: "Canary M Burns", suffix: None, span: #0 bytes(64..80), }, ]
(rust_highfive has picked a reviewer for you, use r? to override) |
impl fmt::Debug for Literal { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.write_str(&self.debug()) | ||
f.debug_struct("Literal") | ||
.field("kind", &format_args!("{}", &self.debug_kind())) |
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.
.field("kind", &format_args!("{}", &self.debug_kind())) | |
.field("kind", &self.debug_kind()) |
?
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 in kind: Float
.
r=me with #72233 (comment) clarified. |
// format the kind without quotes, as in `kind: Float` | ||
.field("kind", &format_args!("{}", &self.debug_kind())) |
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.
Added comment.
@bors r=petrochenkov |
📌 Commit bea2c59 has been approved by |
Fix {:#?} representation of proc_macro::Literal Before: ```rust TokenStream [ Ident { ident: "name", span: #0 bytes(37..41), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(42..43), }, Literal { lit: Lit { kind: Str, symbol: "SNPP", suffix: None }, span: Span { lo: BytePos(44), hi: BytePos(50), ctxt: #0 } }, Punct { ch: ',', spacing: Alone, span: #0 bytes(50..51), }, Ident { ident: "owner", span: #0 bytes(56..61), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(62..63), }, Literal { lit: Lit { kind: Str, symbol: "Canary M Burns", suffix: None }, span: Span { lo: BytePos(64), hi: BytePos(80), ctxt: #0 } }, ] ``` After: ```rust TokenStream [ Ident { ident: "name", span: #0 bytes(37..41), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(42..43), }, Literal { kind: Str, symbol: "SNPP", suffix: None, span: #0 bytes(44..50), }, Punct { ch: ',', spacing: Alone, span: #0 bytes(50..51), }, Ident { ident: "owner", span: #0 bytes(56..61), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(62..63), }, Literal { kind: Str, symbol: "Canary M Burns", suffix: None, span: #0 bytes(64..80), }, ] ```
Fix {:#?} representation of proc_macro::Literal Before: ```rust TokenStream [ Ident { ident: "name", span: #0 bytes(37..41), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(42..43), }, Literal { lit: Lit { kind: Str, symbol: "SNPP", suffix: None }, span: Span { lo: BytePos(44), hi: BytePos(50), ctxt: #0 } }, Punct { ch: ',', spacing: Alone, span: #0 bytes(50..51), }, Ident { ident: "owner", span: #0 bytes(56..61), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(62..63), }, Literal { lit: Lit { kind: Str, symbol: "Canary M Burns", suffix: None }, span: Span { lo: BytePos(64), hi: BytePos(80), ctxt: #0 } }, ] ``` After: ```rust TokenStream [ Ident { ident: "name", span: #0 bytes(37..41), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(42..43), }, Literal { kind: Str, symbol: "SNPP", suffix: None, span: #0 bytes(44..50), }, Punct { ch: ',', spacing: Alone, span: #0 bytes(50..51), }, Ident { ident: "owner", span: #0 bytes(56..61), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(62..63), }, Literal { kind: Str, symbol: "Canary M Burns", suffix: None, span: #0 bytes(64..80), }, ] ```
Fix {:#?} representation of proc_macro::Literal Before: ```rust TokenStream [ Ident { ident: "name", span: #0 bytes(37..41), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(42..43), }, Literal { lit: Lit { kind: Str, symbol: "SNPP", suffix: None }, span: Span { lo: BytePos(44), hi: BytePos(50), ctxt: #0 } }, Punct { ch: ',', spacing: Alone, span: #0 bytes(50..51), }, Ident { ident: "owner", span: #0 bytes(56..61), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(62..63), }, Literal { lit: Lit { kind: Str, symbol: "Canary M Burns", suffix: None }, span: Span { lo: BytePos(64), hi: BytePos(80), ctxt: #0 } }, ] ``` After: ```rust TokenStream [ Ident { ident: "name", span: #0 bytes(37..41), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(42..43), }, Literal { kind: Str, symbol: "SNPP", suffix: None, span: #0 bytes(44..50), }, Punct { ch: ',', spacing: Alone, span: #0 bytes(50..51), }, Ident { ident: "owner", span: #0 bytes(56..61), }, Punct { ch: '=', spacing: Alone, span: #0 bytes(62..63), }, Literal { kind: Str, symbol: "Canary M Burns", suffix: None, span: #0 bytes(64..80), }, ] ```
Rollup of 4 pull requests Successful merges: - rust-lang#72233 (Fix {:#?} representation of proc_macro::Literal) - rust-lang#72277 (emphasize that ManuallyDrop is safe-to-access and unsafe-to-drop) - rust-lang#72281 (Fix whitespace in `?Sized` structured suggestion) - rust-lang#72282 (Fix issue number typo in note) Failed merges: r? @ghost
4676: proc_macro: fix current nightly/future stable ABI incompatibility r=matklad a=robojumper With rust-lang/rust#72233, the proc_macro ABI has changed, leading to the `test_derive_serialize_proc_macro` test believing (on nightly) that `serde` wants to pass the struct name as a byte string literal instead of a string literal. This fixes the test on nightly, but obviously breaks it on stable. As a result, this should be merged when Rust stable `1.45` releases on 2020-07-16. The PR is a draft as to not accidentally merge this too early. People working on nightly can simply apply the commit if they want a fully passing test suite. Co-authored-by: robojumper <[email protected]>
4676: proc_macro: fix current nightly/future stable ABI incompatibility r=matklad a=robojumper With rust-lang/rust#72233, the proc_macro ABI has changed, leading to the `test_derive_serialize_proc_macro` test believing that `serde` wants to pass the struct name as a byte string literal instead of a string literal. Fixes #4866. Co-authored-by: robojumper <[email protected]>
Before:
After: