mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
fix(mbe): desugar doc correctly for mbe
Fixes #16110.
The way rust desugars doc comments when expanding macros
is rendering it as raw strings delimited with hashes.
Rust-analyzer wasn't aware of this, so the desugared doc
comments wouldn't match correctly when on the LHS of macro
declarations.
This PR fixes this by porting the code used by rustc: 4cfdbd328b/compiler/rustc_ast/src/tokenstream.rs (L6837)
This commit is contained in:
parent
f6635211ce
commit
117a28a065
2 changed files with 22 additions and 7 deletions
|
@ -406,9 +406,20 @@ fn doc_comment_text(comment: &ast::Comment) -> SmolStr {
|
|||
text = &text[0..text.len() - 2];
|
||||
}
|
||||
|
||||
// Quote the string
|
||||
let mut num_of_hashes = 0;
|
||||
let mut count = 0;
|
||||
for ch in text.chars() {
|
||||
count = match ch {
|
||||
'"' => 1,
|
||||
'#' if count > 0 => count + 1,
|
||||
_ => 0,
|
||||
};
|
||||
num_of_hashes = num_of_hashes.max(count);
|
||||
}
|
||||
|
||||
// Quote raw string with delimiters
|
||||
// Note that `tt::Literal` expect an escaped string
|
||||
let text = format!("\"{}\"", text.escape_debug());
|
||||
let text = format!("r{delim}\"{text}\"{delim}", delim = "#".repeat(num_of_hashes));
|
||||
text.into()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue