Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,6 @@ where
match chr {
'"' => {
if sharps == 0 {
char_kind = FullCodeCharKind::Normal;

@jieyouxu jieyouxu Jul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question (not necessary for you, but one I had when looking at this diff): do we know or can we guess why we have to override char_kind in this arm? I'm a bit concerned that while this diff is seemingly tiny and fixes #6161, that it regresses another pattern that isn't occurring to me just yet.

View changes since the review

@jieyouxu jieyouxu Jul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this goes back to 6748042, #2983, which fixes #2642

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The override comes from 6748042, which first special cased r"...". Before that commit it was lexed through LitString, where the closing quote is already InString. The Normal override looks copied from the RawStringSuffix arm, where the last # is Normal.

CharClassesStatus::Normal
} else if is_raw_string_suffix(&mut self.base, sharps) {
CharClassesStatus::RawStringSuffix(sharps)
Expand Down Expand Up @@ -1862,6 +1861,20 @@ mod test {
assert_eq!(None, iter.next());
}

#[test]
fn char_classes_hashless_raw_string() {
let mut iter = CharClasses::new("r\"a\nb\",".chars());

assert_eq!((FullCodeCharKind::InString, 'r'), iter.next().unwrap());
assert_eq!((FullCodeCharKind::InString, '"'), iter.next().unwrap());
assert_eq!((FullCodeCharKind::InString, 'a'), iter.next().unwrap());
assert_eq!((FullCodeCharKind::InString, '\n'), iter.next().unwrap());
assert_eq!((FullCodeCharKind::InString, 'b'), iter.next().unwrap());
assert_eq!((FullCodeCharKind::InString, '"'), iter.next().unwrap());
assert_eq!((FullCodeCharKind::Normal, ','), iter.next().unwrap());
assert_eq!(None, iter.next());
}

#[test]
fn comment_code_slices() {
let input = "code(); /* test */ 1 + 1";
Expand Down
8 changes: 8 additions & 0 deletions tests/source/issue-6161.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn f() {
my_macro! {
m =>
"a": r"bb
ccc
",
};
}
8 changes: 8 additions & 0 deletions tests/target/issue-6161.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn f() {
my_macro! {
m =>
"a": r"bb
ccc
",
};

@jieyouxu jieyouxu Jul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion (not really for author): okay, so this I am not 100% sure about. Can we actually format raw strings, or strings in general, in user macros? Do we want to?

This raw string here AFAIK are indeed equivalent so...

View changes since the review

}
Loading