Auto merge of #119552 - krtab:dead_code_priv_mod_pub_field, r=cjgillot,saethlin

Replace visibility test with reachability test in dead code detection

Fixes https://github.com/rust-lang/rust/issues/119545

Also included is a fix for an error now flagged by the lint
This commit is contained in:
bors 2024-03-23 00:37:05 +00:00
commit e5ece90f64
5 changed files with 63 additions and 2 deletions

View File

@ -108,7 +108,7 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
} }
} }
let req = { let mut req = {
let mut following_quote = false; let mut following_quote = false;
let mut req = 0; let mut req = 0;
// `once` so a raw string ending in hashes is still checked // `once` so a raw string ending in hashes is still checked
@ -136,7 +136,9 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
ControlFlow::Continue(num) | ControlFlow::Break(num) => num, ControlFlow::Continue(num) | ControlFlow::Break(num) => num,
} }
}; };
if self.allow_one_hash_in_raw_strings {
req = req.max(1);
}
if req < max { if req < max {
span_lint_and_then( span_lint_and_then(
cx, cx,

View File

@ -0,0 +1 @@
allow-one-hash-in-raw-strings = true

View File

@ -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####" "### "## "# "####;
}

View File

@ -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######" "### "## "# "######;
}

View File

@ -0,0 +1,40 @@
error: unnecessary hashes around raw string literal
--> tests/ui-toml/needless_raw_string_hashes_one_allowed/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
--> tests/ui-toml/needless_raw_string_hashes_one_allowed/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
--> tests/ui-toml/needless_raw_string_hashes_one_allowed/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