Skip to content

Commit ac118f9

Browse files
authored
Merge pull request #21146 from Veykril/push-kwupvlsnstrx
proc-macro-srv: Fix `<TokenStream as Display>::fmt` impl rendering puncts as u8
2 parents 7f93ba5 + 6bbdb1f commit ac118f9

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/tools/rust-analyzer/crates/proc-macro-srv/src/tests/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn test_derive_error() {
228228
IDENT 1 compile_error
229229
PUNCT 1 ! [joint]
230230
GROUP () 1 1 1
231-
LITER 1 Str #[derive(DeriveError)] struct S {field 58 u32}
231+
LITER 1 Str #[derive(DeriveError)] struct S {field : u32}
232232
PUNCT 1 ; [alone]
233233
"#]],
234234
expect![[r#"
@@ -242,9 +242,9 @@ fn test_derive_error() {
242242
243243
IDENT 42:Root[0000, 0]@0..13#ROOT2024 compile_error
244244
PUNCT 42:Root[0000, 0]@13..14#ROOT2024 ! [joint]
245-
GROUP () 42:Root[0000, 0]@14..15#ROOT2024 42:Root[0000, 0]@63..64#ROOT2024 42:Root[0000, 0]@14..64#ROOT2024
246-
LITER 42:Root[0000, 0]@15..63#ROOT2024 Str #[derive(DeriveError)] struct S {field 58 u32}
247-
PUNCT 42:Root[0000, 0]@64..65#ROOT2024 ; [alone]
245+
GROUP () 42:Root[0000, 0]@14..15#ROOT2024 42:Root[0000, 0]@62..63#ROOT2024 42:Root[0000, 0]@14..63#ROOT2024
246+
LITER 42:Root[0000, 0]@15..62#ROOT2024 Str #[derive(DeriveError)] struct S {field : u32}
247+
PUNCT 42:Root[0000, 0]@63..64#ROOT2024 ; [alone]
248248
"#]],
249249
);
250250
}

src/tools/rust-analyzer/crates/proc-macro-srv/src/token_stream.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn display_token_tree<S>(
475475
}
476476
TokenTree::Punct(Punct { ch, joint, span: _ }) => {
477477
*emit_whitespace = !*joint;
478-
write!(f, "{ch}")?;
478+
write!(f, "{}", *ch as char)?;
479479
}
480480
TokenTree::Ident(Ident { sym, is_raw, span: _ }) => {
481481
if *is_raw {
@@ -745,14 +745,10 @@ mod tests {
745745
use super::*;
746746

747747
#[test]
748-
fn roundtrip() {
749-
let token_stream = TokenStream::from_str("struct T {\"string\"}", ()).unwrap();
750-
assert_eq!(token_stream.to_string(), "struct T {\"string\"}");
751-
}
752-
753-
#[test]
754-
fn ident_ts_no_trailing_whitespace_to_string() {
755-
let token_stream = TokenStream::from_str("this_is_an_ident", ()).unwrap();
756-
assert_eq!(token_stream.to_string(), "this_is_an_ident");
748+
fn ts_to_string() {
749+
let token_stream =
750+
TokenStream::from_str("{} () [] <> ;/., \"gfhdgfuiofghd\" 0f32 r#\"dff\"# 'r#lt", ())
751+
.unwrap();
752+
assert_eq!(token_stream.to_string(), "{}()[]<> ;/., \"gfhdgfuiofghd\"0f32 r#\"dff\"#'r#lt");
757753
}
758754
}

0 commit comments

Comments
 (0)