rust-lang / rust-lang/rust-clippy
collection_is_never_read misfires on #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The following line causes the collection_is_never_read lint to highlight serde::Deserialize
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Lint Name
collection_is_never_read
Reproducer
I tried this code:
pub enum Payload {
/// An initialization packet should be the first one sent to a node.
/// It is used to configure the node's parameters.
Initialization {
/// The type of the node being initialized.
#[cfg_attr(feature = "serde", serde(flatten))]
node_sort: NodeSort
},
/// The poll request packet is sent to a node to cause a receive data packet to be sent.
PollRequest,
/// A receive data packet is sent by a node (in response to a poll request packet)
/// and is used to send the node's input states to the controller.
ReceiveData {
/// The data which was read from the inputs.
data: Data
},
/// A transmit data packet is sent to a node to cause it's output states to be changed.
TransmitData {
/// The data to be written to the outputs.
data: Data
},
#[cfg(feature = "experimenter")]
#[cfg_attr(any(docrs, toolchain = "nightly"), doc(cfg(feature = "experimenter")))]
#[cfg_attr(not(toolchain = "nightly"), doc = "**Available on crate feature experimenter only.**\n\n")]
/// An unknown message type.
Unknown {
/// The packet's message type.
message_type: u8,
/// The packet's body.
body: Data
}
}
I saw this happen:
warning: collection is never read
--> cmri/src/packet/payload.rs:7:56
|
7 | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
| ^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collection_is_never_read
= note: this warning originates in the derive macro `serde::Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
I expected to see this happen:
No output since removing serde::Deserialize causes tests to start failing since it is needed.
Version
rustc 1.78.0-nightly (98aa3624b 2024-02-08)
binary: rustc
commit-hash: 98aa3624be70462d6a25ed5544333e3df62f4c66
commit-date: 2024-02-08
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the collection_is_never_read lint and the provided cfg_attr/serde reproducer; compare the emitted span with the expected no-output behavior while retaining serde::Deserialize. Done means the reproducer no longer highlights serde::Deserialize and the existing serde-dependent tests still pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100