-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clippy::return_self_not_must_use
is overreaching
#8339
Comments
@Manishearth can you move this to the clippy repo? Thanks! |
Oops, sorry for putting it into the wrong place! |
@matthiaskrgr no longer on core, I don't have admin powers anymore |
I strongly disagree: So, “pedantic” would be that this lint needs to be removed :-) (I’m a big fan of using English words as defined in the dictionary, please excuse my humour). Perhaps we have different perspectives on what a “linter” is. To me, a linter is a useful tool only if it shows me places in my code that are very likely incorrect or where there is a compelling reason to use a different code pattern due to how the language and compiler are designed. If a tool forces me to spend many hours on bringing my projects in line with someone else’s coding taste after every update of my Rust toolchain, then it loses its utility — which is a shame since I’d really like to keep that first part. Having a good linter is of huge benefit to a programming community, and I wouldn’t want to see Rust gradually losing clippy by it losing its way. To make my proposal more explicit:
|
We don't have different perspective on what a linter is, clippy surpassed this compelling reason argument for me a long time ago. I merely tripped over this lint in other project which does use it and felt like it was excessive and had ramifications for users who don't even use clippy. But if it is in however keep up the good fight. |
Personally, having builders tagged as On the other hand, adding #[must_use]
#[derive(Clone)]
pub struct DiagnosticBuilder<'a>(Box<DiagnosticBuilderInner<'a>>); It's questionable if this would be desirable in all cases, though. In one of my projects, I've made the (questionable?) decision to give a non-builder struct builder methods: use glam::{Quat, Vec3};
#[derive(Clone, Copy)]
pub struct Transform {
position: Vec3,
rotation: Quat,
scale: Vec3,
}
impl Transform {
pub const fn new() -> Self {
Self {
position: Vec3::ZERO,
rotation: Quat::IDENTITY,
scale: Vec3::ONE,
}
}
pub const fn with_position(mut self, position: Vec3) -> Self {
self.position = position;
self
}
}
Given all of this, I'm partial to demoting |
There's a bit more discussion about this on #8197. I'll summarize my view here as well: I think the lint makes sense if |
Using 1.59.0-beta.3, the following illustrates the point:
I can see how a method that takes
&self
and producesSelf
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.The text was updated successfully, but these errors were encountered: