rust-lang / rust-lang/rust-clippy

`clippy::return_self_not_must_use` is overreaching

Open
#8,339 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement S-needs-discussion
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Using 1.59.0-beta.3, the following illustrates the point:

warning: missing `#[must_use]` attribute on a method returning `Self`
  --> libp2p-streaming-response/src/v2/behaviour.rs:32:5
   |
32 | /     pub fn with_request_timeout(self, request_timeout: Duration) -> Self {
33 | |         Self {
34 | |             request_timeout,
35 | |             ..self
36 | |         }
37 | |     }
   | |_____^
   |
   = note: `#[warn(clippy::return_self_not_must_use)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#return_self_not_must_use

I can see how a method that takes &self and produces Self may be misused (although I don’t think that is compelling enough to warrant a default lint), but the above method is not susceptible to programmer mistakes, thanks to Rust’s affine type system. If you deem this worthy of a fix, I may try my hand at it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the warning from clippy::return_self_not_must_use with Rust 1.59.0-beta.3 using the example in libp2p-streaming-response/src/v2/behaviour.rs. Compare the lint's treatment of methods consuming self with methods taking &self; completion requires an agreed scope for the lint's behavior and corresponding Clippy coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.