Unnamed repository; edit this file 'description' to name the repository.
fix: Fix TokenStream::to_string implementation dropping quotation marks
Lukas Wirth 2024-08-29
parent d6666b1 · commit abed6e2
-rw-r--r--crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs9
-rw-r--r--crates/tt/src/lib.rs2
2 files changed, 8 insertions, 3 deletions
diff --git a/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs b/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs
index bfc3ea5d03..d508c19dd7 100644
--- a/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs
+++ b/crates/proc-macro-srv/src/server_impl/rust_analyzer_span.rs
@@ -507,12 +507,17 @@ mod tests {
close: span,
kind: tt::DelimiterKind::Brace,
},
- token_trees: Box::new([]),
+ token_trees: Box::new([tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
+ kind: tt::LitKind::Str,
+ symbol: Symbol::intern("string"),
+ suffix: None,
+ span,
+ }))]),
}),
],
};
- assert_eq!(s.to_string(), "struct T {}");
+ assert_eq!(s.to_string(), "struct T {\"string\"}");
}
#[test]
diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs
index 7b72f9ff10..8d915d0a51 100644
--- a/crates/tt/src/lib.rs
+++ b/crates/tt/src/lib.rs
@@ -603,7 +603,7 @@ pub fn pretty<S>(tkns: &[TokenTree<S>]) -> String {
TokenTree::Leaf(Leaf::Ident(ident)) => {
format!("{}{}", ident.is_raw.as_str(), ident.sym)
}
- TokenTree::Leaf(Leaf::Literal(literal)) => literal.symbol.as_str().to_owned(),
+ TokenTree::Leaf(Leaf::Literal(literal)) => format!("{literal}"),
TokenTree::Leaf(Leaf::Punct(punct)) => format!("{}", punct.char),
TokenTree::Subtree(subtree) => {
let content = pretty(&subtree.token_trees);