Skip to content

Commit

Permalink
Add more diagnostic items for clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Sep 27, 2023
1 parent 92009f2 commit d33f254
Show file tree
Hide file tree
Showing 76 changed files with 290 additions and 267 deletions.
7 changes: 6 additions & 1 deletion compiler/rustc_lint/src/noop_method_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {

let orig_ty = expr_ty.peel_refs();

if receiver_ty == expr_ty {
if receiver_ty == expr_ty
&& matches!(
name,
sym::noop_method_borrow | sym::noop_method_clone | sym::noop_method_deref
)
{
cx.emit_spanned_lint(
NOOP_METHOD_CALL,
span,
Expand Down
50 changes: 50 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ symbols! {
Alignment,
Any,
Arc,
ArcWeak,
Argument,
ArgumentMethods,
Arguments,
ArrayIntoIter,
AsMut,
AsRef,
AssertParamIsClone,
Expand Down Expand Up @@ -164,13 +166,15 @@ symbols! {
Capture,
Center,
Clone,
Command,
ConstParamTy,
Context,
Continue,
Copy,
Count,
Cow,
Debug,
DebugStruct,
Decodable,
Decoder,
DecorateLint,
Expand All @@ -194,6 +198,8 @@ symbols! {
From,
FromIterator,
FromResidual,
FsOpenOptions,
FsPermissions,
Future,
FutureOutput,
FxHashMap,
Expand All @@ -207,16 +213,22 @@ symbols! {
Implied,
IndexOutput,
Input,
Instant,
Into,
IntoDiagnostic,
IntoFuture,
IntoIterator,
IoLines,
IoRead,
IoSeek,
IoWrite,
IpAddr,
IrTyKind,
Is,
ItemContext,
IterEmpty,
IterOnce,
IterPeekable,
Iterator,
IteratorItem,
Layout,
Expand All @@ -227,6 +239,7 @@ symbols! {
Mutex,
MutexGuard,
N,
NonNull,
NonZeroI128,
NonZeroI16,
NonZeroI32,
Expand Down Expand Up @@ -259,15 +272,19 @@ symbols! {
ProcMacro,
ProceduralMasqueradeDummyType,
Range,
RangeBounds,
RangeFrom,
RangeFull,
RangeInclusive,
RangeTo,
RangeToInclusive,
Rc,
RcWeak,
Ready,
Receiver,
RefCell,
RefCellRef,
RefCellRefMut,
Relaxed,
Release,
Result,
Expand All @@ -284,6 +301,7 @@ symbols! {
Send,
SeqCst,
SliceIndex,
SliceIter,
Some,
String,
StructuralEq,
Expand Down Expand Up @@ -493,6 +511,7 @@ symbols! {
clone,
clone_closures,
clone_from,
clone_method,
closure,
closure_lifetime_binder,
closure_to_fn_coercion,
Expand Down Expand Up @@ -561,6 +580,7 @@ symbols! {
constant,
constructor,
context,
convert_identity,
copy,
copy_closures,
copy_nonoverlapping,
Expand All @@ -583,6 +603,7 @@ symbols! {
crate_name,
crate_type,
crate_visibility_modifier,
create_dir,
crt_dash_static: "crt-static",
csky_target_feature,
cstring_type,
Expand Down Expand Up @@ -617,6 +638,7 @@ symbols! {
decode,
default_alloc_error_handler,
default_lib_allocator,
default_method,
default_method_body_is_const,
default_type_parameter_fallback,
default_type_params,
Expand All @@ -628,6 +650,7 @@ symbols! {
deref,
deref_method,
deref_mut,
deref_mut_method,
deref_target,
derive,
derive_const,
Expand Down Expand Up @@ -777,9 +800,11 @@ symbols! {
from_desugaring,
from_fn,
from_iter,
from_iterator_method,
from_output,
from_residual,
from_size_align_unchecked,
from_str_method,
from_usize,
from_yeet,
fsub_fast,
Expand Down Expand Up @@ -962,6 +987,7 @@ symbols! {
mem_replace,
mem_size_of,
mem_size_of_val,
mem_swap,
mem_uninitialized,
mem_variant_count,
mem_zeroed,
Expand Down Expand Up @@ -1091,6 +1117,7 @@ symbols! {
options,
or,
or_patterns,
ord_cmp_method,
other,
out,
overflow_checks,
Expand Down Expand Up @@ -1172,13 +1199,18 @@ symbols! {
proc_macro_mod,
proc_macro_non_items,
proc_macro_path_invoc,
process_exit,
profiler_builtins,
profiler_runtime,
ptr,
ptr_cast,
ptr_cast_const,
ptr_cast_mut,
ptr_const_is_null,
ptr_copy,
ptr_copy_nonoverlapping,
ptr_drop_in_place,
ptr_eq,
ptr_from_ref,
ptr_guaranteed_cmp,
ptr_is_null,
Expand All @@ -1187,8 +1219,19 @@ symbols! {
ptr_null_mut,
ptr_offset_from,
ptr_offset_from_unsigned,
ptr_read,
ptr_read_unaligned,
ptr_read_volatile,
ptr_replace,
ptr_slice_from_raw_parts,
ptr_slice_from_raw_parts_mut,
ptr_swap,
ptr_swap_nonoverlapping,
ptr_unaligned_volatile_load,
ptr_unaligned_volatile_store,
ptr_unique,
ptr_write,
ptr_write_bytes,
ptr_write_unaligned,
ptr_write_volatile,
pub_macro_rules,
Expand Down Expand Up @@ -1477,6 +1520,8 @@ symbols! {
sized,
skip,
slice,
slice_from_raw_parts,
slice_from_raw_parts_mut,
slice_len_fn,
slice_patterns,
slicing_syntax,
Expand All @@ -1502,6 +1547,8 @@ symbols! {
std_panic,
std_panic_2015_macro,
std_panic_macro,
stderr,
stdout,
stmt,
stmt_expr_attributes,
stop_after_dataflow,
Expand Down Expand Up @@ -1564,7 +1611,9 @@ symbols! {
thumb2,
thumb_mode: "thumb-mode",
tmm_reg,
to_owned_method,
to_string,
to_string_method,
to_vec,
todo_macro,
tool_attributes,
Expand All @@ -1587,6 +1636,7 @@ symbols! {
try_blocks,
try_capture,
try_from,
try_from_method,
try_into,
try_trait_v2,
tt,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub trait ToOwned {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "cloning is often expensive and is not expected to have side effects"]
#[rustc_diagnostic_item = "to_owned_method"]
fn to_owned(&self) -> Self::Owned;

/// Uses borrowed data to replace owned data, usually by cloning.
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
///
/// [`upgrade`]: Weak::upgrade
#[stable(feature = "rc_weak", since = "1.4.0")]
#[rustc_diagnostic_item = "RcWeak"]
pub struct Weak<
T: ?Sized,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,7 @@ pub trait ToString {
/// ```
#[rustc_conversion_suggestion]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "to_string_method"]
fn to_string(&self) -> String;
}

Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
///
/// [`upgrade`]: Weak::upgrade
#[stable(feature = "arc_weak", since = "1.4.0")]
#[rustc_diagnostic_item = "ArcWeak"]
pub struct Weak<
T: ?Sized,
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/array/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
/// A by-value [array] iterator.
#[stable(feature = "array_value_iter", since = "1.51.0")]
#[rustc_insignificant_dtor]
#[rustc_diagnostic_item = "ArrayIntoIter"]
pub struct IntoIter<T, const N: usize> {
/// This is the array we are iterating over.
///
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,7 @@ impl Clone for BorrowRef<'_> {
/// See the [module-level documentation](self) for more.
#[stable(feature = "rust1", since = "1.0.0")]
#[must_not_suspend = "holding a Ref across suspend points can cause BorrowErrors"]
#[rustc_diagnostic_item = "RefCellRef"]
pub struct Ref<'b, T: ?Sized + 'b> {
// NB: we use a pointer instead of `&'b T` to avoid `noalias` violations, because a
// `Ref` argument doesn't hold immutability for its whole scope, only until it drops.
Expand Down Expand Up @@ -1804,6 +1805,7 @@ impl<'b> BorrowRefMut<'b> {
/// See the [module-level documentation](self) for more.
#[stable(feature = "rust1", since = "1.0.0")]
#[must_not_suspend = "holding a RefMut across suspend points can cause BorrowErrors"]
#[rustc_diagnostic_item = "RefCellRefMut"]
pub struct RefMut<'b, T: ?Sized + 'b> {
// NB: we use a pointer instead of `&'b mut T` to avoid `noalias` violations, because a
// `RefMut` argument doesn't hold exclusivity for its whole scope, only until it drops.
Expand Down
1 change: 1 addition & 0 deletions library/core/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub trait Clone: Sized {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "cloning is often expensive and is not expected to have side effects"]
#[rustc_diagnostic_item = "clone_method"]
fn clone(&self) -> Self;

/// Performs copy-assignment from `source`.
Expand Down
1 change: 1 addition & 0 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "ord_cmp_method"]
fn cmp(&self, other: &Self) -> Ordering;

/// Compares and returns the maximum of two values.
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub use num::FloatToInt;
#[stable(feature = "convert_id", since = "1.33.0")]
#[rustc_const_stable(feature = "const_identity", since = "1.33.0")]
#[inline(always)]
#[rustc_diagnostic_item = "convert_identity"]
pub const fn identity<T>(x: T) -> T {
x
}
Expand Down Expand Up @@ -642,6 +643,7 @@ pub trait TryFrom<T>: Sized {

/// Performs the conversion.
#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_diagnostic_item = "try_from_method"]
fn try_from(value: T) -> Result<Self, Self::Error>;
}

Expand Down
1 change: 1 addition & 0 deletions library/core/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub trait Default: Sized {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "default_method"]
fn default() -> Self;
}

Expand Down
1 change: 1 addition & 0 deletions library/core/src/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl fmt::Write for PadAdapter<'_, '_> {
#[must_use = "must eventually call `finish()` on Debug builders"]
#[allow(missing_debug_implementations)]
#[stable(feature = "debug_builders", since = "1.2.0")]
#[rustc_diagnostic_item = "DebugStruct"]
pub struct DebugStruct<'a, 'b: 'a> {
fmt: &'a mut fmt::Formatter<'b>,
result: fmt::Result,
Expand Down
1 change: 1 addition & 0 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ impl<W: Write + ?Sized> Write for &mut W {
/// documentation of the methods defined on `Formatter` below.
#[allow(missing_debug_implementations)]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_diagnostic_item = "Formatter"]
pub struct Formatter<'a> {
flags: u32,
fill: char,
Expand Down
Loading

0 comments on commit d33f254

Please sign in to comment.