Skip to content
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

Make String a diagnostic item #110949

Closed
bluthej opened this issue Apr 28, 2023 · 3 comments
Closed

Make String a diagnostic item #110949

bluthej opened this issue Apr 28, 2023 · 3 comments

Comments

@bluthej
Copy link
Contributor

bluthej commented Apr 28, 2023

Proposal

It would be nice if String was a diagnostic item.

Background

I implemented the clear_with_drain Clippy lint for Vecs first, and then proposed to extend that to 5 other container types including Strings. However, in the process I realized that all my container types were diagnostic items except for Strings.

This led me to find a false negative in collection_is_never_read, which was also trying to check for Strings using is_type_diagnostic_item. The current workaround is to use the lang item for String, which means that this type gets a special treatment. I find this a little unfortunate and would like to be able to handle all these container types in the same way 🙂

@llogiq suggested to add a String diagnostic item here so I thought I would open the issue!

Ironically, the String type was the one mentioned as an example in @Manishearth's original proposal #39131, and it was again suggested in this comment. But apparently nobody needed this diagnostic item that bad!

Pros and cons

When working on Clippy lints, one expects the ability to check for such a prominent type using is_type_diagnostic_item, which can lead to false negatives (like I mentioned, even though this was also due to insufficient testing).

The only downside that I can think of is that there would be two different ways to check for the String type, so one can wonder which one one is supposed to use.

@jyn514
Copy link
Member

jyn514 commented Apr 28, 2023

I think this should be fixed in clippy's helper library. There's no reason for an item to be both a lang item and a diagnostic item.

@Manishearth
Copy link
Member

I believe when I first proposed diagnostic items String wasn't a lang item and that has since changed.

Yes, for lang items we should just use the lang item.

@bluthej
Copy link
Contributor Author

bluthej commented Apr 28, 2023

Oh I see. Thx for the feedback, I'll close this issue and see if we can find a better workaround on the Clippy side.

@bluthej bluthej closed this as not planned Won't fix, can't repro, duplicate, stale Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants