Closed sassman closed 2 years ago
clippy has a check for this, although in nursery ATM, see https://rust-lang.github.io/rust-clippy/master/index.html#use_self
Personally, I'm all for using Self
, so :+1:
I don't think this is a good idea given that it reduces the clarity, I think that's the reason why it is still in nursery.
I don't think this is a good idea given that it reduces the clarity, I think that's the reason why it is still in nursery.
Could you please elaborate what exactly would reduce the clarity?
I'm having a hard time to imagine what clarity you might refer to.
See https://github.com/rust-unofficial/patterns/issues/145, there's a reason it's still not closed up till now because different people have different opinion.
Can we revert this pull request given that the lint is still in nursery and no clear benefits that using Self
is better over the explicit type?
Hey pickfire, I think that using Self
here is fine, since it's just an example code.
That issue is more for the page dedicated to that idiom, I think.
Also there is the benefit that when you copy-paste that piece of code you don't have to change the struct name, because Self
will work for you.
I hope you don't mind that much :)
Also there is the benefit that when you copy-paste that piece of code you don't have to change the struct name, because Self will work for you.
If your file only have a single impl
and is short then yeah, no issue. Imagine if your files is 1000 lines and tons of impl
for a single enum or struct, then you can easily get lost on the context, having the return there can give more context. Built docs have the same issue.
This PR just fixes a minor but IMO important detail: whenever returning with
new
ordefault
usingSelf
is preferable