Skip to content

Commit b3aa0e1

Browse files
authored
Rollup merge of rust-lang#87170 - xFrednet:clippy-5393-add-diagnostic-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`
2 parents 0323e6a + 885bd75 commit b3aa0e1

File tree

12 files changed

+22
-0
lines changed

12 files changed

+22
-0
lines changed

alloc/src/borrow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ where
177177
/// }
178178
/// ```
179179
#[stable(feature = "rust1", since = "1.0.0")]
180+
#[cfg_attr(not(test), rustc_diagnostic_item = "Cow")]
180181
pub enum Cow<'a, B: ?Sized + 'a>
181182
where
182183
B: ToOwned,

alloc/src/collections/btree/map/entry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use Entry::*;
1414
///
1515
/// [`entry`]: BTreeMap::entry
1616
#[stable(feature = "rust1", since = "1.0.0")]
17+
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeEntry")]
1718
pub enum Entry<'a, K: 'a, V: 'a> {
1819
/// A vacant entry.
1920
#[stable(feature = "rust1", since = "1.0.0")]

core/src/any.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ use crate::intrinsics;
108108
// unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call,
109109
// but we would likely want to indicate as such in documentation).
110110
#[stable(feature = "rust1", since = "1.0.0")]
111+
#[cfg_attr(not(test), rustc_diagnostic_item = "Any")]
111112
pub trait Any: 'static {
112113
/// Gets the `TypeId` of `self`.
113114
///

core/src/cmp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,7 @@ pub macro PartialOrd($item:item) {
11041104
#[inline]
11051105
#[must_use]
11061106
#[stable(feature = "rust1", since = "1.0.0")]
1107+
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_min")]
11071108
pub fn min<T: Ord>(v1: T, v2: T) -> T {
11081109
v1.min(v2)
11091110
}
@@ -1166,6 +1167,7 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
11661167
#[inline]
11671168
#[must_use]
11681169
#[stable(feature = "rust1", since = "1.0.0")]
1170+
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_max")]
11691171
pub fn max<T: Ord>(v1: T, v2: T) -> T {
11701172
v1.max(v2)
11711173
}

core/src/convert/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ pub const fn identity<T>(x: T) -> T {
152152
/// is_hello(s);
153153
/// ```
154154
#[stable(feature = "rust1", since = "1.0.0")]
155+
#[cfg_attr(not(test), rustc_diagnostic_item = "AsRef")]
155156
pub trait AsRef<T: ?Sized> {
156157
/// Performs the conversion.
157158
#[stable(feature = "rust1", since = "1.0.0")]
@@ -193,6 +194,7 @@ pub trait AsRef<T: ?Sized> {
193194
///
194195
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
195196
#[stable(feature = "rust1", since = "1.0.0")]
197+
#[cfg_attr(not(test), rustc_diagnostic_item = "AsMut")]
196198
pub trait AsMut<T: ?Sized> {
197199
/// Performs the conversion.
198200
#[stable(feature = "rust1", since = "1.0.0")]

core/src/iter/sources/repeat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use crate::iter::{FusedIterator, TrustedLen};
5151
/// ```
5252
#[inline]
5353
#[stable(feature = "rust1", since = "1.0.0")]
54+
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_repeat")]
5455
pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
5556
Repeat { element: elt }
5657
}

core/src/iter/traits/double_ended.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::ops::{ControlFlow, Try};
3636
/// assert_eq!(None, iter.next_back());
3737
/// ```
3838
#[stable(feature = "rust1", since = "1.0.0")]
39+
#[cfg_attr(not(test), rustc_diagnostic_item = "DoubleEndedIterator")]
3940
pub trait DoubleEndedIterator: Iterator {
4041
/// Removes and returns an element from the end of the iterator.
4142
///

core/src/mem/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub use crate::intrinsics::transmute;
140140
#[inline]
141141
#[rustc_const_stable(feature = "const_forget", since = "1.46.0")]
142142
#[stable(feature = "rust1", since = "1.0.0")]
143+
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_forget")]
143144
pub const fn forget<T>(t: T) {
144145
let _ = ManuallyDrop::new(t);
145146
}
@@ -298,6 +299,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) {
298299
#[stable(feature = "rust1", since = "1.0.0")]
299300
#[rustc_promotable]
300301
#[rustc_const_stable(feature = "const_size_of", since = "1.24.0")]
302+
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of")]
301303
pub const fn size_of<T>() -> usize {
302304
intrinsics::size_of::<T>()
303305
}
@@ -324,6 +326,7 @@ pub const fn size_of<T>() -> usize {
324326
#[inline]
325327
#[stable(feature = "rust1", since = "1.0.0")]
326328
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
329+
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of_val")]
327330
pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
328331
// SAFETY: `val` is a reference, so it's a valid raw pointer
329332
unsafe { intrinsics::size_of_val(val) }
@@ -814,6 +817,7 @@ pub fn take<T: Default>(dest: &mut T) -> T {
814817
#[stable(feature = "rust1", since = "1.0.0")]
815818
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
816819
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
820+
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_replace")]
817821
pub const fn replace<T>(dest: &mut T, src: T) -> T {
818822
// SAFETY: We read from `dest` but directly write `src` into it afterwards,
819823
// such that the old value is not duplicated. Nothing is dropped and
@@ -888,6 +892,7 @@ pub const fn replace<T>(dest: &mut T, src: T) -> T {
888892
/// [`RefCell`]: crate::cell::RefCell
889893
#[inline]
890894
#[stable(feature = "rust1", since = "1.0.0")]
895+
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_drop")]
891896
pub fn drop<T>(_x: T) {}
892897

893898
/// Interprets `src` as having type `&U`, and then reads `src` without moving
@@ -1015,6 +1020,7 @@ impl<T> fmt::Debug for Discriminant<T> {
10151020
/// ```
10161021
#[stable(feature = "discriminant_value", since = "1.21.0")]
10171022
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
1023+
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_discriminant")]
10181024
pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
10191025
Discriminant(intrinsics::discriminant_value(v))
10201026
}

core/src/time.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const MICROS_PER_SEC: u64 = 1_000_000;
6161
/// crate to do so.
6262
#[stable(feature = "duration", since = "1.3.0")]
6363
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
64+
#[cfg_attr(not(test), rustc_diagnostic_item = "Duration")]
6465
pub struct Duration {
6566
secs: u64,
6667
nanos: u32, // Always 0 <= nanos < NANOS_PER_SEC

std/src/collections/hash/map.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,6 +1829,7 @@ impl<K, V, S> Debug for RawEntryBuilder<'_, K, V, S> {
18291829
///
18301830
/// [`entry`]: HashMap::entry
18311831
#[stable(feature = "rust1", since = "1.0.0")]
1832+
#[cfg_attr(not(test), rustc_diagnostic_item = "HashMapEntry")]
18321833
pub enum Entry<'a, K: 'a, V: 'a> {
18331834
/// An occupied entry.
18341835
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)