-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
Clippy does not respect MSRV when suggesting to remove an &
when comparing a CString
and a &CStr
on Rust 1.76.0.
Lint Name
clippy::op_ref
Reproducer
I tried this code:
fn intern_get_roundtrip(cstring: CString) -> bool {
let mut table = SymbolTable::new();
let sym = table.intern(cstring.clone()).unwrap();
let retrieved_c_string = table.get(sym).unwrap();
&*cstring == retrieved_c_string
}
I saw this happen:
warning: needlessly taken reference of left operand
--> src/cstr.rs:1027:13
|
1027 | &*cstring == retrieved_c_string
| ---------^^^^^^^^^^^^^^^^^^^^^^
| |
| help: use the left value directly: `*cstring`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
note: the lint level is defined here
--> src/lib.rs:1:9
|
1 | #![warn(clippy::all)]
| ^^^^^^^^^^^
= note: `#[warn(clippy::op_ref)]` implied by `#[warn(clippy::all)]`
I expected to see this happen: the lint should not fire because the crate has rust-version = "1.76.0"
declared in Cargo.toml
.
Applying this diff:
diff --git a/src/cstr.rs b/src/cstr.rs
index 75d702b..e2d3fa3 100644
--- a/src/cstr.rs
+++ b/src/cstr.rs
@@ -1024,7 +1024,7 @@ mod tests {
let mut table = SymbolTable::new();
let sym = table.intern(cstring.clone()).unwrap();
let retrieved_c_string = table.get(sym).unwrap();
- &*cstring == retrieved_c_string
+ *cstring == retrieved_c_string
}
fn table_contains_sym(cstring: CString) -> bool {
yields this error
Compiling intaglio v1.10.0 (/home/runner/work/intaglio/intaglio)
error[E0308]: mismatched types
--> src/cstr.rs:1027:25
|
1027 | *cstring == retrieved_c_string
| -------- ^^^^^^^^^^^^^^^^^^ expected `CStr`, found `&CStr`
| |
| expected because this is `CStr`
|
help: consider dereferencing the borrow
|
1027 | *cstring == *retrieved_c_string
| +
For more information about this error, try `rustc --explain E0308`.
error: could not compile `intaglio` (lib test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
when building with Rust 1.76.0, which does not have the required trait impls.
Failing GitHub Actions run is here: https://github.com/artichoke/intaglio/actions/runs/18436896685/job/52531604213?pr=324
Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied