Skip to content

Commit 2e47438

Browse files
committed
change category and refactor
1 parent 7db8c79 commit 2e47438

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

clippy_lints/src/raw_strings.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ declare_clippy_lint! {
1313
/// Checks for raw string literals where a string literal can be used instead.
1414
///
1515
/// ### Why is this bad?
16-
/// It's just unnecessary.
16+
/// It's just unnecessary, but there are many cases where using a raw string literal is more
17+
/// idiomatic than a string literal, so it's opt-in.
1718
///
1819
/// ### Example
1920
/// ```rust
@@ -25,7 +26,7 @@ declare_clippy_lint! {
2526
/// ```
2627
#[clippy::version = "1.72.0"]
2728
pub NEEDLESS_RAW_STRING,
28-
complexity,
29+
restriction,
2930
"suggests using a string literal when a raw string literal is unnecessary"
3031
}
3132
declare_clippy_lint! {
@@ -46,7 +47,7 @@ declare_clippy_lint! {
4647
/// ```
4748
#[clippy::version = "1.72.0"]
4849
pub NEEDLESS_RAW_STRING_HASHES,
49-
complexity,
50+
style,
5051
"suggests reducing the number of hashes around a raw string literal"
5152
}
5253
impl_lint_pass!(RawStrings => [NEEDLESS_RAW_STRING, NEEDLESS_RAW_STRING_HASHES]);
@@ -86,10 +87,21 @@ impl EarlyLintPass for RawStrings {
8687
}
8788

8889
#[expect(clippy::cast_possible_truncation)]
89-
let req = lit.symbol.as_str().as_bytes()
90+
let req = lit
91+
.symbol
92+
.as_str()
93+
.as_bytes()
9094
.split(|&b| b == b'"')
9195
.skip(1)
92-
.map(|bs| 1 + bs.iter().take_while(|&&b| b == b'#').count() as u8)
96+
.map_while(|bs| {
97+
let max = num;
98+
let num = bs.iter().take_while(|&&b| b == b'#').count() as u8;
99+
if num != max {
100+
return Some(num + 1);
101+
}
102+
103+
None
104+
})
93105
.max()
94106
.unwrap_or(0);
95107

tests/ui/needless_raw_string_hashes.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@run-rustfix
2-
#![allow(clippy::needless_raw_string, clippy::no_effect, unused)]
2+
#![allow(clippy::no_effect, unused)]
33
#![warn(clippy::needless_raw_string_hashes)]
44
#![feature(c_str_literals)]
55

tests/ui/needless_raw_string_hashes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@run-rustfix
2-
#![allow(clippy::needless_raw_string, clippy::no_effect, unused)]
2+
#![allow(clippy::no_effect, unused)]
33
#![warn(clippy::needless_raw_string_hashes)]
44
#![feature(c_str_literals)]
55

0 commit comments

Comments
 (0)