Skip to content

Commit 3610d6c

Browse files
authored
Rollup merge of rust-lang#87267 - dtolnay:negspace, r=Aaron1011
Remove space after negative sign in Literal to_string Negative proc macro literal tokens used to be printed with a space between the minus sign and the magnitude. That's because `impl ToString for Literal` used to convert the Literal into a TokenStream, which splits the minus sign into a separate Punct token. ```rust Literal::isize_unsuffixed(-10).to_string() // "- 10" ``` This PR updates the ToString impl to directly use `rustc_ast::token::Lit`'s ToString, which matches the way Rust negative numbers are idiomatically written without a space. ```rust Literal::isize_unsuffixed(-10).to_string() // "-10" ```
2 parents 7d03e37 + 5f2dd07 commit 3610d6c

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

proc_macro/src/bridge/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ macro_rules! with_api {
109109
fn drop($self: $S::Literal);
110110
fn clone($self: &$S::Literal) -> $S::Literal;
111111
fn from_str(s: &str) -> Result<$S::Literal, ()>;
112+
fn to_string($self: &$S::Literal) -> String;
112113
fn debug_kind($self: &$S::Literal) -> String;
113114
fn symbol($self: &$S::Literal) -> String;
114115
fn suffix($self: &$S::Literal) -> Option<String>;

proc_macro/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ impl FromStr for Literal {
11951195
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
11961196
impl ToString for Literal {
11971197
fn to_string(&self) -> String {
1198-
TokenStream::from(TokenTree::from(self.clone())).to_string()
1198+
self.0.to_string()
11991199
}
12001200
}
12011201

0 commit comments

Comments
 (0)