Skip to content

Commit 07faa2e

Browse files
authored
Rollup merge of #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 81d0b70 + 67002db commit 07faa2e

File tree

13 files changed

+44
-0
lines changed

13 files changed

+44
-0
lines changed

compiler/rustc_span/src/symbol.rs

+22
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@ symbols! {
122122
// nice to have.
123123
Symbols {
124124
Alignment,
125+
Any,
125126
Arc,
126127
Argument,
127128
ArgumentV1,
128129
Arguments,
130+
AsMut,
131+
AsRef,
132+
BTreeEntry,
129133
BTreeMap,
130134
BTreeSet,
131135
BinaryHeap,
@@ -139,19 +143,25 @@ symbols! {
139143
Continue,
140144
Copy,
141145
Count,
146+
Cow,
142147
Debug,
143148
DebugStruct,
144149
DebugTuple,
145150
Decodable,
146151
Decoder,
147152
Default,
148153
Deref,
154+
DirBuilder,
155+
DoubleEndedIterator,
156+
Duration,
149157
Encodable,
150158
Encoder,
151159
Eq,
152160
Equal,
153161
Err,
154162
Error,
163+
File,
164+
FileType,
155165
FormatSpec,
156166
Formatter,
157167
From,
@@ -162,11 +172,14 @@ symbols! {
162172
GlobalAlloc,
163173
Hash,
164174
HashMap,
175+
HashMapEntry,
165176
HashSet,
166177
Hasher,
167178
Implied,
168179
Input,
169180
IntoIterator,
181+
IoRead,
182+
IoWrite,
170183
Is,
171184
ItemContext,
172185
Iterator,
@@ -369,6 +382,8 @@ symbols! {
369382
closure,
370383
closure_to_fn_coercion,
371384
cmp,
385+
cmp_max,
386+
cmp_min,
372387
cmpxchg16b_target_feature,
373388
cmse_nonsecure_entry,
374389
coerce_unsized,
@@ -674,6 +689,7 @@ symbols! {
674689
item,
675690
item_like_imports,
676691
iter,
692+
iter_repeat,
677693
keyword,
678694
kind,
679695
kreg,
@@ -740,6 +756,12 @@ symbols! {
740756
maybe_uninit,
741757
maybe_uninit_uninit,
742758
maybe_uninit_zeroed,
759+
mem_discriminant,
760+
mem_drop,
761+
mem_forget,
762+
mem_replace,
763+
mem_size_of,
764+
mem_size_of_val,
743765
mem_uninitialized,
744766
mem_zeroed,
745767
member_constraints,

library/alloc/src/borrow.rs

+1
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,

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

+1
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")]

library/core/src/any.rs

+1
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
///

library/core/src/cmp.rs

+2
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
}

library/core/src/convert/mod.rs

+2
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")]

library/core/src/iter/sources/repeat.rs

+1
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
}

library/core/src/iter/traits/double_ended.rs

+1
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
///

library/core/src/mem/mod.rs

+6
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
}

library/core/src/time.rs

+1
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

library/std/src/collections/hash/map.rs

+1
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")]

library/std/src/fs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ use crate::time::SystemTime;
8888
/// [`BufReader<R>`]: io::BufReader
8989
/// [`sync_all`]: File::sync_all
9090
#[stable(feature = "rust1", since = "1.0.0")]
91+
#[cfg_attr(not(test), rustc_diagnostic_item = "File")]
9192
pub struct File {
9293
inner: fs_imp::File,
9394
}
@@ -183,12 +184,14 @@ pub struct Permissions(fs_imp::FilePermissions);
183184
/// It is returned by [`Metadata::file_type`] method.
184185
#[stable(feature = "file_type", since = "1.1.0")]
185186
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
187+
#[cfg_attr(not(test), rustc_diagnostic_item = "FileType")]
186188
pub struct FileType(fs_imp::FileType);
187189

188190
/// A builder used to create directories in various manners.
189191
///
190192
/// This builder also supports platform-specific options.
191193
#[stable(feature = "dir_builder", since = "1.6.0")]
194+
#[cfg_attr(not(test), rustc_diagnostic_item = "DirBuilder")]
192195
#[derive(Debug)]
193196
pub struct DirBuilder {
194197
inner: fs_imp::DirBuilder,

library/std/src/io/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ pub(crate) fn default_read_exact<R: Read + ?Sized>(this: &mut R, mut buf: &mut [
514514
/// [`File`]: crate::fs::File
515515
#[stable(feature = "rust1", since = "1.0.0")]
516516
#[doc(notable_trait)]
517+
#[cfg_attr(not(test), rustc_diagnostic_item = "IoRead")]
517518
pub trait Read {
518519
/// Pull some bytes from this source into the specified buffer, returning
519520
/// how many bytes were read.
@@ -1361,6 +1362,7 @@ impl Initializer {
13611362
/// [`write_all`]: Write::write_all
13621363
#[stable(feature = "rust1", since = "1.0.0")]
13631364
#[doc(notable_trait)]
1365+
#[cfg_attr(not(test), rustc_diagnostic_item = "IoWrite")]
13641366
pub trait Write {
13651367
/// Write a buffer into this writer, returning how many bytes were written.
13661368
///

0 commit comments

Comments
 (0)