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
19 changes: 10 additions & 9 deletions clippy_lints/src/raw_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,20 @@ impl RawStrings {
// `once` so a raw string ending in hashes is still checked
let num = str.as_bytes().iter().chain(once(&0)).try_fold(0u8, |acc, &b| {
match b {
b'"' if !following_quote => (following_quote, req) = (true, 1),
b'#' => req += u8::from(following_quote),
_ => {
if following_quote {
following_quote = false;

if req == max {
return ControlFlow::Break(req);
}
b'"' if !following_quote => (following_quote, req) = (true, 1),
_ if following_quote => {
let ended = req;
// a quote also starts a new run, e.g. `""#` requires two hashes
(following_quote, req) = (b == b'"', 1);

return ControlFlow::Continue(acc.max(req));
if ended == max {
return ControlFlow::Break(ended);
}

return ControlFlow::Continue(acc.max(ended));
},
_ => {},
}

ControlFlow::Continue(acc)
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/needless_raw_string_hashes.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ fn issue_13503() {
// Test arguments as well
println!("{}", r"foobar".len());
}

fn issue_11737() {
r##"task test(execute: "") {r#""#}"##;
r##"a quote pair followed by a hash: ""#"##;
Comment thread
shulaoda marked this conversation as resolved.
r##"a gap between the quotes: r#"_"#"##;
r##"a gap between the quotes: "_"#"##;
}
7 changes: 7 additions & 0 deletions tests/ui/needless_raw_string_hashes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ fn issue_13503() {
// Test arguments as well
println!("{}", r"foobar".len());
}

fn issue_11737() {
r##"task test(execute: "") {r#""#}"##;
r##"a quote pair followed by a hash: ""#"##;
r##"a gap between the quotes: r#"_"#"##;
r##"a gap between the quotes: "_"#"##;
}