# Diagnostic Items
While writing lints it's common to check for specific types, traits and
functions. This raises the question on how to check for these. Types can be
checked by their complete type path. However, this requires hard coding paths
and can lead to misclassifications in some edge cases. To counteract this,
rustc has introduced diagnostic items that are used to identify types via
[`Symbol`]s.
## Finding diagnostic items
Diagnostic items are added to items inside `rustc`/`std`/`core`/`alloc` with the
`rustc_diagnostic_item` attribute. The item for a specific type can be found by
opening the source code in the documentation and looking for this attribute.
Note that it's often added with the `cfg_attr` attribute to avoid compilation
errors during tests. A definition often looks like this:
```rs
// This is the diagnostic item for this type vvvvvvv
#[cfg_attr(not(test), rustc_diagnostic_item = "Penguin")]
struct Penguin;
```
Diagnostic items are usually only added to traits,
types,
and standalone functions.
If the goal is to check for an associated type or method,
please use the diagnostic item of the item and reference
[*Using Diagnostic Items*](#using-diagnostic-items).
## Adding diagnostic items
A new diagnostic item can be added with these two steps:
1. Find the target item inside the Rust repo. Now add the diagnostic item as a
string via the `rustc_diagnostic_item` attribute. This can sometimes cause
compilation errors while running tests. These errors can be avoided by using
the `cfg_attr` attribute with the `not(test)` condition (it's fine adding
then for all `rustc_diagnostic_item` attributes as a preventive manner). At
the end, it should look like this:
```rs
// This will be the new diagnostic item vvv
#[cfg_attr(not(test), rustc_diagnostic_item = "Cat")]
struct Cat;
```
For the naming conventions of diagnostic items, please refer to
[*Naming Conventions*](#naming-conventions).
2. <!-- date-check: Feb 2023 -->
Diagnostic items in code are accessed via symbols in
[`rustc_span::symbol::sym`].
To add your newly-created diagnostic item,
simply open the module file,
and add the name (In this case `Cat`) at the correct point in the list.
Now you can create a pull request with your changes. :tada:
> NOTE:
> When using diagnostic items in other projects like Clippy,
> it might take some time until the repos get synchronized.
## Naming conventions
Diagnostic items don't have a naming convention yet.
Following are some guidelines that should be used in future,
but might differ from existing names:
* Types, traits, and enums are named using UpperCamelCase
(Examples: `Iterator` and `HashMap`)
* For type names that are used multiple times,
like `Writer`,
it's good to choose a more precise name,