rust-lang / rust-lang/rust-clippy
`let_unit_value` targeting entire function
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Lint name: let_unit_value
This is one of the functions being targeted:
#[cfg_attr(feature = "tracing", tracing::instrument(level = "trace"))]
pub fn bytes(&self, bytes: &[u8]) {
if self.wants(EventTypeFlags::SHARD_PAYLOAD) {
self.send(Event::ShardPayload(Payload {
bytes: bytes.to_vec(),
}))
}
}
I expected to see this happen: the lint to not be triggered
Instead, this happened:
clippy output
Posting clippy checks here instead.
error: this let-binding has unit value
--> gateway/src/shard/emitter.rs:94:39
|
94 | pub fn bytes(&self, bytes: &[u8]) {
| _______________________________________^
95 | | if self.wants(EventTypeFlags::SHARD_PAYLOAD) {
96 | | self.send(Event::ShardPayload(Payload {
97 | | bytes: bytes.to_vec(),
98 | | }))
99 | | }
100 | | }
| |_____^
|
note: the lint level is defined here
--> gateway/src/lib.rs:122:5
|
122 | clippy::pedantic,
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::let_unit_value)]` implied by `#[deny(clippy::pedantic)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
help: omit the `let` binding
|
94 | pub fn bytes(&self, bytes: &[u8]) {
95 | if self.wants(EventTypeFlags::SHARD_PAYLOAD) {
96 | self.send(Event::ShardPayload(Payload {
97 | bytes: bytes.to_vec(),
98 | }))
99 | }
...
error: this let-binding has unit value
--> gateway/src/shard/emitter.rs:104:39
|
104 | pub fn event(&self, event: Event) {
| _______________________________________^
105 | | let event_type = EventTypeFlags::from(event.kind());
106 | |
107 | | if self.wants(event_type) {
108 | | self.send(event);
109 | | }
110 | | }
| |_____^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
help: omit the `let` binding
|
104 | pub fn event(&self, event: Event) {
105 | let event_type = EventTypeFlags::from(event.kind());
106 |
107 | if self.wants(event_type) {
108 | self.send(event);
109 | }
...
error: this let-binding has unit value
--> gateway/src/shard/processor/compression/inflater.rs:50:73
|
50 | pub fn msg(&mut self) -> Result<Option<&mut [u8]>, DecompressError> {
| _________________________________________________________________________^
51 | | let length = self.compressed.len();
52 | |
53 | | // Check if a partial payload was received. If it was, we can just
... |
120 | | Ok(Some(&mut self.buffer))
121 | | }
| |_____^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
help: omit the `let` binding
|
50 | pub fn msg(&mut self) -> Result<Option<&mut [u8]>, DecompressError> {
51 | let length = self.compressed.len();
52 |
53 | // Check if a partial payload was received. If it was, we can just
54 | // return that no decompressed message is available.
55 | if length < 4 || self.compressed[(length - 4)..] != ZLIB_SUFFIX {
...
error: this let-binding has unit value
--> gateway/src/shard/processor/compression/inflater.rs:128:29
|
128 | pub fn clear(&mut self) {
| _____________________________^
129 | | self.shrink();
130 | |
131 | | self.compressed.clear();
132 | | self.internal_buffer.clear();
133 | | self.buffer.clear();
134 | | }
| |_____^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
help: omit the `let` binding
|
128 | pub fn clear(&mut self) {
129 | self.shrink();
130 |
131 | self.compressed.clear();
132 | self.internal_buffer.clear();
133 | self.buffer.clear();
...
##[error]Exiting due to clippy errors
Post job cleanup.
This only happens in our CI run, in one crate, on functions that are behind a feature flag. I don't know yet if it's due to run caching (it happens on separate cache keys, on separate repos, so maybe not) or a strangeness in clippy.
Link to an action run: https://github.com/twilight-rs/twilight/pull/1176/checks?check_run_id=3782693317
Meta
Rust versIon: Happens on both stable-x86_64-unknown-linux-gnu unchanged - rustc 1.55.0 (c8dfcfe04 2021-09-06) and the preinstalled "Rust 1.55, Clippy 1.55" that the actions environment gives us
https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#rust-tools
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
Reproduce the reported diagnostics using gateway/src/shard/emitter.rs and gateway/src/shard/processor/compression/inflater.rs, with the feature-gated code and clippy::pedantic enabled in gateway/src/lib.rs. Compare stable Rust 1.55 and the CI run linked in the issue; done means these functions no longer receive erroneous let_unit_value diagnostics while the lint still reports genuine cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100