-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add diagnostic items for Clippy #87170
Add diagnostic items for Clippy #87170
Conversation
This comment has been minimized.
This comment has been minimized.
The pipeline shows why some diagnostic items use |
I would just add diagnostic items for modules Aside: I am looking into adding a new lookup util so we can write code like |
Such a lookup macro would be awesome, btw. |
Hmm, but doesn't that bring us closer to what we used to have? Seems faster and cleaner to just have diagnostic items for everyone.
Yeah, sure! |
cc @estebank |
22e152c
to
3d5453f
Compare
@@ -1829,6 +1829,7 @@ impl<K, V, S> Debug for RawEntryBuilder<'_, K, V, S> { | |||
/// | |||
/// [`entry`]: HashMap::entry | |||
#[stable(feature = "rust1", since = "1.0.0")] | |||
#[cfg_attr(not(test), rustc_diagnostic_item = "HashmapEntry")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg_attr(not(test), rustc_diagnostic_item = "HashmapEntry")] | |
#[cfg_attr(not(test), rustc_diagnostic_item = "HashMapEntry")] |
3d5453f
to
37626f3
Compare
37626f3
to
d38f2b0
Compare
I recommend that only because some functions are very closely tied to the module they are in. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe someone from @rust-lang/compiler can make sure we're not doing anything wrong here
It would work with associated types, associated methods, inherent methods, module items, ... lookup!(HashMap)
lookup!(HashMap::Entry)
lookup!(HashMap::insert)
lookup!(Iterator::find)
lookup!(cmp::min) |
I definitely like the idea. Note that it probably wouldn't work for Using the parent search method would probably still not fully work for reexports though. |
Right, part of the reason behind having diagnostic items is never having to know the internal organization of the crate. It makes sense to do parent lookups for methods/etc but not as much for free functions |
@bors r=Manishearth,oli-obk |
📌 Commit d38f2b0 has been approved by |
for future reference on method lookups of traits/impls: https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F |
Would it maybe be worth it to implement a function/macro like My understanding is that paths in use statements resolve to the original Has there been any previous discussions about a concept like this? Edit: @oli-obk thanks for posting the link again, should we move the discussion over to Zulip? 🙃 |
I've created a Zulip topic with a short summary here: https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Use.20of.20diagnostic.20items.20.28discussion.20from.20rust.2387170.29/near/246219798 |
The point of diagnostic items was, in part, to not have to do any such lookups: I don't see what problem it solves to switch from diagnostic items to lookups. |
My understanding was that the main point of diagnostic items was to avoid hard coded paths to the exact item. That problem would be solved, and it would make a slightly nicer interface IMO. But that's it. There has also been some feedback on Zulip that using the resolver for this can be problematic and produce ICEs. I'll dig a bit more through the compiler, but it seems like diagnostic items are a currently the best solution. |
…-items, r=Manishearth,oli-obk Add diagnostic items for Clippy This adds a bunch of diagnostic items to `std`/`core`/`alloc` functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync. This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's [`paths.rs`](https://github.com/rust-lang/rust-clippy/blob/ecf85f4bdc319f9d9d853d1fff68a8a25e64c7a8/clippy_utils/src/paths.rs) (after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding a `is_diagnostic_assoc_item(did, sym::Iterator, sym::map)` function or something similar (Suggested by `@camsteffen` [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Diagnostic.20Item.20Naming.20Convention.3F/near/225024603)) There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (`BinaryHeap`) and some snake_case (`hashmap_type`). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome. cc: rust-lang/rust-clippy#5393 r? `@Manishearth`
@bors: r- |
Sorry, that I didn't fix the error earlier, the error message confused me at first. Now everything should hopefully be correct 🙃 |
@bors r=Manishearth,oli-obk |
📌 Commit 67002db has been approved by |
Rollup of 8 pull requests Successful merges: - rust-lang#86763 (Add a regression test for issue-63355) - rust-lang#86814 (Recover from a misplaced inner doc comment) - rust-lang#86843 (Check that const parameters of trait methods have compatible types) - rust-lang#86889 (rustdoc: Cleanup ExternalCrate) - rust-lang#87092 (Remove nondeterminism in multiple-definitions test) - rust-lang#87170 (Add diagnostic items for Clippy) - rust-lang#87183 (fix typo in compile_fail doctest) - rust-lang#87205 (rustc_middle: remove redundant clone) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This adds a bunch of diagnostic items to
std
/core
/alloc
functions, structs and traits used in Clippy. The actual refactorings in Clippy to use these items will be done in a different PR in Clippy after the next sync.This PR doesn't include all paths Clippy uses, I've only gone through the first 85 lines of Clippy's
paths.rs
(after rust-lang/rust-clippy#7466) to get some feedback early on. I've also decided against adding diagnostic items to methods, as it would be nicer and more scalable to access them in a nicer fashion, like adding ais_diagnostic_assoc_item(did, sym::Iterator, sym::map)
function or something similar (Suggested by @camsteffen on Zulip)There seems to be some different naming conventions when it comes to diagnostic items, some use UpperCamelCase (
BinaryHeap
) and some snake_case (hashmap_type
). This PR uses UpperCamelCase for structs and traits and snake_case with the module name as a prefix for functions. Any feedback on is this welcome.cc: rust-lang/rust-clippy#5393
r? @Manishearth