Skip to content

Commit

Permalink
fix: allow-one-hash-in-raw-strings option of needless_raw_string_hash…
Browse files Browse the repository at this point in the history
…es was ignored

Fixes: rust-lang/rust-clippy#11481

changelog: Fix `allow-one-hash-in-raw-strings` option of [`needless_raw_string_hashes`] was ignored
  • Loading branch information
krtab committed Jan 5, 2024
1 parent 03e0a01 commit fb75654
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tools/clippy/clippy_lints/src/raw_strings.rs
Expand Up @@ -108,7 +108,7 @@ impl EarlyLintPass for RawStrings {
}
}

let req = {
let mut req = {
let mut following_quote = false;
let mut req = 0;
// `once` so a raw string ending in hashes is still checked
Expand Down Expand Up @@ -136,7 +136,9 @@ impl EarlyLintPass for RawStrings {
ControlFlow::Continue(num) | ControlFlow::Break(num) => num,
}
};

if self.allow_one_hash_in_raw_strings {
req = req.max(1);
}
if req < max {
span_lint_and_then(
cx,
Expand Down
@@ -0,0 +1 @@
allow-one-hash-in-raw-strings = true
@@ -0,0 +1,9 @@
#![allow(clippy::no_effect, unused)]
#![warn(clippy::needless_raw_string_hashes)]

fn main() {
r#"\aaa"#;
r#"\aaa"#;
r#"Hello "world"!"#;
r####" "### "## "# "####;
}
@@ -0,0 +1,9 @@
#![allow(clippy::no_effect, unused)]
#![warn(clippy::needless_raw_string_hashes)]

fn main() {
r#"\aaa"#;
r##"\aaa"##;
r##"Hello "world"!"##;
r######" "### "## "# "######;
}
@@ -0,0 +1,40 @@
error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:6:5
|
LL | r##"\aaa"##;
| ^^^^^^^^^^^
|
= note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::needless_raw_string_hashes)]`
help: remove one hash from both sides of the string literal
|
LL - r##"\aaa"##;
LL + r#"\aaa"#;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:7:5
|
LL | r##"Hello "world"!"##;
| ^^^^^^^^^^^^^^^^^^^^^
|
help: remove one hash from both sides of the string literal
|
LL - r##"Hello "world"!"##;
LL + r#"Hello "world"!"#;
|

error: unnecessary hashes around raw string literal
--> $DIR/needless_raw_string_hashes.rs:8:5
|
LL | r######" "### "## "# "######;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: remove 2 hashes from both sides of the string literal
|
LL - r######" "### "## "# "######;
LL + r####" "### "## "# "####;
|

error: aborting due to 3 previous errors

0 comments on commit fb75654

Please sign in to comment.