-
Notifications
You must be signed in to change notification settings - Fork 1.6k
add to_string_trait_impl lint #12122
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
Conversation
r? @llogiq (rustbot has picked a reviewer for you, use r? to override) |
There are some unrelated tests that get errors because of the lint. This can be worked around by adding suitable I do wonder though if this should really be a style lint. If there's any type that one may want to convert to a string, but not for displaying, linting that would constitute a false positive without a way to distinguish from a true one. |
If I have a type that already implements to_string as well as Display but both in different ways (on purpose), will this lint? Seems like this would be a false positive then. |
@matthiaskrgr that wouldn't be possible since |
struct A {}
impl std::fmt::Display for A {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
writeln!(f, "AAAAAH")?;
Ok(())
}
}
impl A {
fn to_string(&self) -> String {
String::from("oh no")
}
}
fn main() {
let a = A {};
assert_eq!(a.to_string(), format!("{}", a));
} |
ah, i'll push a fix soon
i could be missing some context, but the docs sound like there isn't much room for nuance (maybe that's an issue with the docs). is there a good reason one would want to separate conversion logic from displaying logic in this case? users can still |
@matthiaskrgr ah, sorry, i misunderstood what you meant. no this will not lint that since it only checks for |
@llogiq there are a bunch of errors that aren't from this lint. maybe something broke in master? e.g.
edit: weird... master passes all tests... how did this |
2b21c9e
to
1243ba3
Compare
@llogiq i added allows for the tests triggered by this new lint, but still not sure why seemingly unrelated lints are triggering now @matthiaskrgr added a test to show a direct |
You added |
1243ba3
to
a15afc6
Compare
got it. thanks @y21 fixed |
ah, actually, looks like there are other areas. will fix those soon. |
a15afc6
to
247842d
Compare
hmm, now failures are for the doc comment examples, even though they have |
will |
I think to see the error that happens in CI you need to run |
@TennyZhuang not sure if there's a formal rule for this, but personally i prefer the current name since |
247842d
to
7d8a141
Compare
all ci checks are passing now @llogiq |
I can’t find a convention rule for clippy, but generally according to rust naming convention, it’s preferred to add an underscore when an UpperCamelCase naming have to be used in a snake_case context. BTW I can find both styles in clippy.
and
|
hmm, true. on one hand that is for rust code, not clippy names (as you said), but on the other hand it might make sense to try to adhere to that. what do we think of |
Note that this is only true without The Is this an acceptable false positive, considering that specialization is an incomplete nightly feature? 🤔 |
i'll let others weigh in since i have only a surface level understanding of the mechanics from reading about specialization |
actually, thinking about it some more, i don't think my assumption about std's |
7d8a141
to
141adce
Compare
141adce
to
9127907
Compare
@TennyZhuang updated name to |
Again, I'm a bit worried that this may cause needless noise at some projects, so I'm going to run a lintcheck first. Otherwise this should be fine. |
@llogiq any results from the check? |
Sorry, I was quite busy, I'll see if I can run it this evening. |
☔ The latest upstream changes (presumably #12160) made this pull request unmergeable. Please resolve the merge conflicts. |
@llogiq I'll fix these conflicts once the lintcheck is done |
Sorry it took me so long, but the lintcheck came back negative, which is good. So r=me after a rebase. |
No worries! Thanks. I'll rebase soon. |
d0d3f0f
to
9127907
Compare
9127907
to
6d76d14
Compare
all set @llogiq |
Thank you! @bors r+ |
add to_string_trait_impl lint closes #12076 changelog: [`to_string_trait_impl`]: add lint for direct `ToString` implementations
💔 Test failed - checks-action_test |
Another MacOS Runner failure... 🙃 @bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
[`to_string_trait_impl`]: avoid linting if the impl is a specialization Fixes #12263 Oh well... #12122 (comment) 🙃 changelog: [`to_string_trait_impl`]: avoid linting if the impl is a specialization
closes #12076
changelog: [
to_string_trait_impl
]: add lint for directToString
implementations