Skip to content

Commit 09e47d9

Browse files
committed
fix: allow-one-hash-in-raw-strings option of needless_raw_string_hashes was ignored
Fixes: rust-lang/rust-clippy#11481 changelog: Fix `allow-one-hash-in-raw-strings` option of [`needless_raw_string_hashes`] was ignored
1 parent 9a099e6 commit 09e47d9

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

src/tools/clippy/clippy_lints/src/raw_strings.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl EarlyLintPass for RawStrings {
108108
}
109109
}
110110

111-
let req = {
111+
let mut req = {
112112
let mut following_quote = false;
113113
let mut req = 0;
114114
// `once` so a raw string ending in hashes is still checked
@@ -136,7 +136,9 @@ impl EarlyLintPass for RawStrings {
136136
ControlFlow::Continue(num) | ControlFlow::Break(num) => num,
137137
}
138138
};
139-
139+
if self.allow_one_hash_in_raw_strings {
140+
req = req.max(1);
141+
}
140142
if req < max {
141143
span_lint_and_then(
142144
cx,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
allow-one-hash-in-raw-strings = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![allow(clippy::no_effect, unused)]
2+
#![warn(clippy::needless_raw_string_hashes)]
3+
4+
fn main() {
5+
r#"\aaa"#;
6+
r#"\aaa"#;
7+
r#"Hello "world"!"#;
8+
r####" "### "## "# "####;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![allow(clippy::no_effect, unused)]
2+
#![warn(clippy::needless_raw_string_hashes)]
3+
4+
fn main() {
5+
r#"\aaa"#;
6+
r##"\aaa"##;
7+
r##"Hello "world"!"##;
8+
r######" "### "## "# "######;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error: unnecessary hashes around raw string literal
2+
--> $DIR/needless_raw_string_hashes.rs:6:5
3+
|
4+
LL | r##"\aaa"##;
5+
| ^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::needless_raw_string_hashes)]`
9+
help: remove one hash from both sides of the string literal
10+
|
11+
LL - r##"\aaa"##;
12+
LL + r#"\aaa"#;
13+
|
14+
15+
error: unnecessary hashes around raw string literal
16+
--> $DIR/needless_raw_string_hashes.rs:7:5
17+
|
18+
LL | r##"Hello "world"!"##;
19+
| ^^^^^^^^^^^^^^^^^^^^^
20+
|
21+
help: remove one hash from both sides of the string literal
22+
|
23+
LL - r##"Hello "world"!"##;
24+
LL + r#"Hello "world"!"#;
25+
|
26+
27+
error: unnecessary hashes around raw string literal
28+
--> $DIR/needless_raw_string_hashes.rs:8:5
29+
|
30+
LL | r######" "### "## "# "######;
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
|
33+
help: remove 2 hashes from both sides of the string literal
34+
|
35+
LL - r######" "### "## "# "######;
36+
LL + r####" "### "## "# "####;
37+
|
38+
39+
error: aborting due to 3 previous errors
40+

0 commit comments

Comments
 (0)