Skip to content

Commit 9de9cf1

Browse files
committed
Add comments to TokenCursor::desugar.
It took me some time to work out what this code was doing.
1 parent 40e4827 commit 9de9cf1

File tree

1 file changed

+5
-1
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+5
-1
lines changed

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@ impl TokenCursor {
302302

303303
fn desugar(&mut self, attr_style: AttrStyle, data: Symbol, span: Span) -> (Token, Spacing) {
304304
// Searches for the occurrences of `"#*` and returns the minimum number of `#`s
305-
// required to wrap the text.
305+
// required to wrap the text. E.g.
306+
// - `abc d` is wrapped as `r"abc d"` (num_of_hashes = 0)
307+
// - `abc "d"` is wrapped as `r#"abc "d""#` (num_of_hashes = 1)
308+
// - `abc "##d##"` is wrapped as `r###"abc "d""###` (num_of_hashes = 3)
306309
let mut num_of_hashes = 0;
307310
let mut count = 0;
308311
for ch in data.as_str().chars() {
@@ -314,6 +317,7 @@ impl TokenCursor {
314317
num_of_hashes = cmp::max(num_of_hashes, count);
315318
}
316319

320+
// `/// foo` becomes `doc = r"foo".
317321
let delim_span = DelimSpan::from_single(span);
318322
let body = TokenTree::Delimited(
319323
delim_span,

0 commit comments

Comments
 (0)