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`](ecf85f4bdc/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`
This commit is contained in:
commit
07faa2e32c
13 changed files with 44 additions and 0 deletions
|
@ -122,10 +122,14 @@ symbols! {
|
||||||
// nice to have.
|
// nice to have.
|
||||||
Symbols {
|
Symbols {
|
||||||
Alignment,
|
Alignment,
|
||||||
|
Any,
|
||||||
Arc,
|
Arc,
|
||||||
Argument,
|
Argument,
|
||||||
ArgumentV1,
|
ArgumentV1,
|
||||||
Arguments,
|
Arguments,
|
||||||
|
AsMut,
|
||||||
|
AsRef,
|
||||||
|
BTreeEntry,
|
||||||
BTreeMap,
|
BTreeMap,
|
||||||
BTreeSet,
|
BTreeSet,
|
||||||
BinaryHeap,
|
BinaryHeap,
|
||||||
|
@ -139,6 +143,7 @@ symbols! {
|
||||||
Continue,
|
Continue,
|
||||||
Copy,
|
Copy,
|
||||||
Count,
|
Count,
|
||||||
|
Cow,
|
||||||
Debug,
|
Debug,
|
||||||
DebugStruct,
|
DebugStruct,
|
||||||
DebugTuple,
|
DebugTuple,
|
||||||
|
@ -146,12 +151,17 @@ symbols! {
|
||||||
Decoder,
|
Decoder,
|
||||||
Default,
|
Default,
|
||||||
Deref,
|
Deref,
|
||||||
|
DirBuilder,
|
||||||
|
DoubleEndedIterator,
|
||||||
|
Duration,
|
||||||
Encodable,
|
Encodable,
|
||||||
Encoder,
|
Encoder,
|
||||||
Eq,
|
Eq,
|
||||||
Equal,
|
Equal,
|
||||||
Err,
|
Err,
|
||||||
Error,
|
Error,
|
||||||
|
File,
|
||||||
|
FileType,
|
||||||
FormatSpec,
|
FormatSpec,
|
||||||
Formatter,
|
Formatter,
|
||||||
From,
|
From,
|
||||||
|
@ -162,11 +172,14 @@ symbols! {
|
||||||
GlobalAlloc,
|
GlobalAlloc,
|
||||||
Hash,
|
Hash,
|
||||||
HashMap,
|
HashMap,
|
||||||
|
HashMapEntry,
|
||||||
HashSet,
|
HashSet,
|
||||||
Hasher,
|
Hasher,
|
||||||
Implied,
|
Implied,
|
||||||
Input,
|
Input,
|
||||||
IntoIterator,
|
IntoIterator,
|
||||||
|
IoRead,
|
||||||
|
IoWrite,
|
||||||
Is,
|
Is,
|
||||||
ItemContext,
|
ItemContext,
|
||||||
Iterator,
|
Iterator,
|
||||||
|
@ -369,6 +382,8 @@ symbols! {
|
||||||
closure,
|
closure,
|
||||||
closure_to_fn_coercion,
|
closure_to_fn_coercion,
|
||||||
cmp,
|
cmp,
|
||||||
|
cmp_max,
|
||||||
|
cmp_min,
|
||||||
cmpxchg16b_target_feature,
|
cmpxchg16b_target_feature,
|
||||||
cmse_nonsecure_entry,
|
cmse_nonsecure_entry,
|
||||||
coerce_unsized,
|
coerce_unsized,
|
||||||
|
@ -674,6 +689,7 @@ symbols! {
|
||||||
item,
|
item,
|
||||||
item_like_imports,
|
item_like_imports,
|
||||||
iter,
|
iter,
|
||||||
|
iter_repeat,
|
||||||
keyword,
|
keyword,
|
||||||
kind,
|
kind,
|
||||||
kreg,
|
kreg,
|
||||||
|
@ -740,6 +756,12 @@ symbols! {
|
||||||
maybe_uninit,
|
maybe_uninit,
|
||||||
maybe_uninit_uninit,
|
maybe_uninit_uninit,
|
||||||
maybe_uninit_zeroed,
|
maybe_uninit_zeroed,
|
||||||
|
mem_discriminant,
|
||||||
|
mem_drop,
|
||||||
|
mem_forget,
|
||||||
|
mem_replace,
|
||||||
|
mem_size_of,
|
||||||
|
mem_size_of_val,
|
||||||
mem_uninitialized,
|
mem_uninitialized,
|
||||||
mem_zeroed,
|
mem_zeroed,
|
||||||
member_constraints,
|
member_constraints,
|
||||||
|
|
|
@ -177,6 +177,7 @@ where
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Cow")]
|
||||||
pub enum Cow<'a, B: ?Sized + 'a>
|
pub enum Cow<'a, B: ?Sized + 'a>
|
||||||
where
|
where
|
||||||
B: ToOwned,
|
B: ToOwned,
|
||||||
|
|
|
@ -14,6 +14,7 @@ use Entry::*;
|
||||||
///
|
///
|
||||||
/// [`entry`]: BTreeMap::entry
|
/// [`entry`]: BTreeMap::entry
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "BTreeEntry")]
|
||||||
pub enum Entry<'a, K: 'a, V: 'a> {
|
pub enum Entry<'a, K: 'a, V: 'a> {
|
||||||
/// A vacant entry.
|
/// A vacant entry.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
|
@ -108,6 +108,7 @@ use crate::intrinsics;
|
||||||
// unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call,
|
// unsafe traits and unsafe methods (i.e., `type_id` would still be safe to call,
|
||||||
// but we would likely want to indicate as such in documentation).
|
// but we would likely want to indicate as such in documentation).
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Any")]
|
||||||
pub trait Any: 'static {
|
pub trait Any: 'static {
|
||||||
/// Gets the `TypeId` of `self`.
|
/// Gets the `TypeId` of `self`.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1104,6 +1104,7 @@ pub macro PartialOrd($item:item) {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_min")]
|
||||||
pub fn min<T: Ord>(v1: T, v2: T) -> T {
|
pub fn min<T: Ord>(v1: T, v2: T) -> T {
|
||||||
v1.min(v2)
|
v1.min(v2)
|
||||||
}
|
}
|
||||||
|
@ -1166,6 +1167,7 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "cmp_max")]
|
||||||
pub fn max<T: Ord>(v1: T, v2: T) -> T {
|
pub fn max<T: Ord>(v1: T, v2: T) -> T {
|
||||||
v1.max(v2)
|
v1.max(v2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,6 +152,7 @@ pub const fn identity<T>(x: T) -> T {
|
||||||
/// is_hello(s);
|
/// is_hello(s);
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "AsRef")]
|
||||||
pub trait AsRef<T: ?Sized> {
|
pub trait AsRef<T: ?Sized> {
|
||||||
/// Performs the conversion.
|
/// Performs the conversion.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
@ -193,6 +194,7 @@ pub trait AsRef<T: ?Sized> {
|
||||||
///
|
///
|
||||||
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
|
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "AsMut")]
|
||||||
pub trait AsMut<T: ?Sized> {
|
pub trait AsMut<T: ?Sized> {
|
||||||
/// Performs the conversion.
|
/// Performs the conversion.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
|
@ -51,6 +51,7 @@ use crate::iter::{FusedIterator, TrustedLen};
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "iter_repeat")]
|
||||||
pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
|
pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
|
||||||
Repeat { element: elt }
|
Repeat { element: elt }
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ use crate::ops::{ControlFlow, Try};
|
||||||
/// assert_eq!(None, iter.next_back());
|
/// assert_eq!(None, iter.next_back());
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "DoubleEndedIterator")]
|
||||||
pub trait DoubleEndedIterator: Iterator {
|
pub trait DoubleEndedIterator: Iterator {
|
||||||
/// Removes and returns an element from the end of the iterator.
|
/// Removes and returns an element from the end of the iterator.
|
||||||
///
|
///
|
||||||
|
|
|
@ -140,6 +140,7 @@ pub use crate::intrinsics::transmute;
|
||||||
#[inline]
|
#[inline]
|
||||||
#[rustc_const_stable(feature = "const_forget", since = "1.46.0")]
|
#[rustc_const_stable(feature = "const_forget", since = "1.46.0")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_forget")]
|
||||||
pub const fn forget<T>(t: T) {
|
pub const fn forget<T>(t: T) {
|
||||||
let _ = ManuallyDrop::new(t);
|
let _ = ManuallyDrop::new(t);
|
||||||
}
|
}
|
||||||
|
@ -298,6 +299,7 @@ pub fn forget_unsized<T: ?Sized>(t: T) {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_promotable]
|
#[rustc_promotable]
|
||||||
#[rustc_const_stable(feature = "const_size_of", since = "1.24.0")]
|
#[rustc_const_stable(feature = "const_size_of", since = "1.24.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of")]
|
||||||
pub const fn size_of<T>() -> usize {
|
pub const fn size_of<T>() -> usize {
|
||||||
intrinsics::size_of::<T>()
|
intrinsics::size_of::<T>()
|
||||||
}
|
}
|
||||||
|
@ -324,6 +326,7 @@ pub const fn size_of<T>() -> usize {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
|
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of_val")]
|
||||||
pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
|
pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
|
||||||
// SAFETY: `val` is a reference, so it's a valid raw pointer
|
// SAFETY: `val` is a reference, so it's a valid raw pointer
|
||||||
unsafe { intrinsics::size_of_val(val) }
|
unsafe { intrinsics::size_of_val(val) }
|
||||||
|
@ -814,6 +817,7 @@ pub fn take<T: Default>(dest: &mut T) -> T {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
|
#[must_use = "if you don't need the old value, you can just assign the new value directly"]
|
||||||
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
|
#[rustc_const_unstable(feature = "const_replace", issue = "83164")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_replace")]
|
||||||
pub const fn replace<T>(dest: &mut T, src: T) -> T {
|
pub const fn replace<T>(dest: &mut T, src: T) -> T {
|
||||||
// SAFETY: We read from `dest` but directly write `src` into it afterwards,
|
// SAFETY: We read from `dest` but directly write `src` into it afterwards,
|
||||||
// such that the old value is not duplicated. Nothing is dropped and
|
// 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 {
|
||||||
/// [`RefCell`]: crate::cell::RefCell
|
/// [`RefCell`]: crate::cell::RefCell
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_drop")]
|
||||||
pub fn drop<T>(_x: T) {}
|
pub fn drop<T>(_x: T) {}
|
||||||
|
|
||||||
/// Interprets `src` as having type `&U`, and then reads `src` without moving
|
/// Interprets `src` as having type `&U`, and then reads `src` without moving
|
||||||
|
@ -1015,6 +1020,7 @@ impl<T> fmt::Debug for Discriminant<T> {
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "discriminant_value", since = "1.21.0")]
|
#[stable(feature = "discriminant_value", since = "1.21.0")]
|
||||||
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
|
#[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_discriminant")]
|
||||||
pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
|
pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
|
||||||
Discriminant(intrinsics::discriminant_value(v))
|
Discriminant(intrinsics::discriminant_value(v))
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ const MICROS_PER_SEC: u64 = 1_000_000;
|
||||||
/// crate to do so.
|
/// crate to do so.
|
||||||
#[stable(feature = "duration", since = "1.3.0")]
|
#[stable(feature = "duration", since = "1.3.0")]
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Duration")]
|
||||||
pub struct Duration {
|
pub struct Duration {
|
||||||
secs: u64,
|
secs: u64,
|
||||||
nanos: u32, // Always 0 <= nanos < NANOS_PER_SEC
|
nanos: u32, // Always 0 <= nanos < NANOS_PER_SEC
|
||||||
|
|
|
@ -1829,6 +1829,7 @@ impl<K, V, S> Debug for RawEntryBuilder<'_, K, V, S> {
|
||||||
///
|
///
|
||||||
/// [`entry`]: HashMap::entry
|
/// [`entry`]: HashMap::entry
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "HashMapEntry")]
|
||||||
pub enum Entry<'a, K: 'a, V: 'a> {
|
pub enum Entry<'a, K: 'a, V: 'a> {
|
||||||
/// An occupied entry.
|
/// An occupied entry.
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
|
@ -88,6 +88,7 @@ use crate::time::SystemTime;
|
||||||
/// [`BufReader<R>`]: io::BufReader
|
/// [`BufReader<R>`]: io::BufReader
|
||||||
/// [`sync_all`]: File::sync_all
|
/// [`sync_all`]: File::sync_all
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "File")]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
inner: fs_imp::File,
|
inner: fs_imp::File,
|
||||||
}
|
}
|
||||||
|
@ -183,12 +184,14 @@ pub struct Permissions(fs_imp::FilePermissions);
|
||||||
/// It is returned by [`Metadata::file_type`] method.
|
/// It is returned by [`Metadata::file_type`] method.
|
||||||
#[stable(feature = "file_type", since = "1.1.0")]
|
#[stable(feature = "file_type", since = "1.1.0")]
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "FileType")]
|
||||||
pub struct FileType(fs_imp::FileType);
|
pub struct FileType(fs_imp::FileType);
|
||||||
|
|
||||||
/// A builder used to create directories in various manners.
|
/// A builder used to create directories in various manners.
|
||||||
///
|
///
|
||||||
/// This builder also supports platform-specific options.
|
/// This builder also supports platform-specific options.
|
||||||
#[stable(feature = "dir_builder", since = "1.6.0")]
|
#[stable(feature = "dir_builder", since = "1.6.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "DirBuilder")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DirBuilder {
|
pub struct DirBuilder {
|
||||||
inner: fs_imp::DirBuilder,
|
inner: fs_imp::DirBuilder,
|
||||||
|
|
|
@ -514,6 +514,7 @@ pub(crate) fn default_read_exact<R: Read + ?Sized>(this: &mut R, mut buf: &mut [
|
||||||
/// [`File`]: crate::fs::File
|
/// [`File`]: crate::fs::File
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[doc(notable_trait)]
|
#[doc(notable_trait)]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "IoRead")]
|
||||||
pub trait Read {
|
pub trait Read {
|
||||||
/// Pull some bytes from this source into the specified buffer, returning
|
/// Pull some bytes from this source into the specified buffer, returning
|
||||||
/// how many bytes were read.
|
/// how many bytes were read.
|
||||||
|
@ -1361,6 +1362,7 @@ impl Initializer {
|
||||||
/// [`write_all`]: Write::write_all
|
/// [`write_all`]: Write::write_all
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[doc(notable_trait)]
|
#[doc(notable_trait)]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "IoWrite")]
|
||||||
pub trait Write {
|
pub trait Write {
|
||||||
/// Write a buffer into this writer, returning how many bytes were written.
|
/// Write a buffer into this writer, returning how many bytes were written.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue