Skip to content

False Positive: needless_raw_string_hashes #11402

Closed as not planned
Closed as not planned
@FintanH

Description

@FintanH

Summary

On our radicle-surf project, the lint job failed due to this clippy warning. This is the job and the offending code is:

#[test]
fn test_both_missing_eof_newline() {
    let buf = r#"
diff --git a/.env b/.env
index f89e4c0..7c56eb7 100644
--- a/.env
+++ b/.env
@@ -1 +1 @@
-hello=123
\ No newline at end of file
+hello=1234
\ No newline at end of file
"#;
    let diff = git2::Diff::from_buffer(buf.as_bytes()).unwrap();
    let diff = Diff::try_from(diff).unwrap();
    assert_eq!(
        diff.modified().next().unwrap().diff.eof(),
        Some(EofNewLine::BothMissing)
    );
}

What's strange is there is a very similar test below that does not set off the clippy warning:

#[test]
fn test_none_missing_eof_newline() {
    let buf = r#"
diff --git a/.env b/.env
index f89e4c0..7c56eb7 100644
--- a/.env
+++ b/.env
@@ -1 +1 @@
-hello=123
+hello=1234
"#;
    let diff = git2::Diff::from_buffer(buf.as_bytes()).unwrap();
    let diff = Diff::try_from(diff).unwrap();
    assert_eq!(
        diff.modified().next().unwrap().diff.eof(),
        Some(EofNewLine::NoneMissing)
    );
}

Lint Name

needless_raw_string_hashes

Reproducer

I tried this code:

#[test]
fn test_both_missing_eof_newline() {
    let buf = r#"
diff --git a/.env b/.env
index f89e4c0..7c56eb7 100644
--- a/.env
+++ b/.env
@@ -1 +1 @@
-hello=123
\ No newline at end of file
+hello=1234
\ No newline at end of file
"#;
    let diff = git2::Diff::from_buffer(buf.as_bytes()).unwrap();
    let diff = Diff::try_from(diff).unwrap();
    assert_eq!(
        diff.modified().next().unwrap().diff.eof(),
        Some(EofNewLine::BothMissing)
    );
}

I saw this happen:

error: unnecessary hashes around raw string literal
   --> radicle-surf/t/src/diff.rs:363:15
    |
363 |       let buf = r#"
    |  _______________^
364 | | diff --git a/.env b/.env
365 | | index f89e4c0..7c56eb7 100644
366 | | --- a/.env
...   |
372 | | \ No newline at end of file
373 | | "#;
    | |__^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
    = note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings`
help: try
    |
363 ~     let buf = r"
364 + diff --git a/.env b/.env
365 + index f89e4c0..7c56eb7 100644
366 + --- a/.env
367 + +++ b/.env
368 + @@ -1 +1 @@
369 + -hello=123
370 + \ No newline at end of file
371 + +hello=1234
372 + \ No newline at end of file
373 ~ ";
    |

error: could not compile `radicle-surf-test` (lib test) due to previous error

I expected for the lint job to pass. It can be reproduced in the git repository by running scripts/ci/lint.

Version

rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: x86_64-unknown-linux-gnu
release: 1.72.0
LLVM version: 16.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions