Skip to content

Commit 2a13e83

Browse files
committed
Update all the code to pass the updated use_self lint.
One struct required a temporary `#[allow(dead_code)]` annotation due to a bug in the Rust compiler: rust-lang/rust#63151.
1 parent 41110b0 commit 2a13e83

File tree

10 files changed

+80
-79
lines changed

10 files changed

+80
-79
lines changed

clippy_dev/src/fmt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ pub enum CliError {
1515

1616
impl From<io::Error> for CliError {
1717
fn from(error: io::Error) -> Self {
18-
CliError::IoError(error)
18+
Self::IoError(error)
1919
}
2020
}
2121

2222
impl From<walkdir::Error> for CliError {
2323
fn from(error: walkdir::Error) -> Self {
24-
CliError::WalkDirError(error)
24+
Self::WalkDirError(error)
2525
}
2626
}
2727

clippy_lints/src/checked_conversions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,12 @@ impl ConversionType {
160160
/// Creates a conversion type if the type is allowed & conversion is valid
161161
fn try_new(from: &str, to: &str) -> Option<Self> {
162162
if UINTS.contains(&from) {
163-
Some(ConversionType::FromUnsigned)
163+
Some(Self::FromUnsigned)
164164
} else if SINTS.contains(&from) {
165165
if UINTS.contains(&to) {
166-
Some(ConversionType::SignedToUnsigned)
166+
Some(Self::SignedToUnsigned)
167167
} else if SINTS.contains(&to) {
168-
Some(ConversionType::SignedToSigned)
168+
Some(Self::SignedToSigned)
169169
} else {
170170
None
171171
}

clippy_lints/src/consts.rs

+28-28
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ pub enum Constant {
4848
impl PartialEq for Constant {
4949
fn eq(&self, other: &Self) -> bool {
5050
match (self, other) {
51-
(&Constant::Str(ref ls), &Constant::Str(ref rs)) => ls == rs,
52-
(&Constant::Binary(ref l), &Constant::Binary(ref r)) => l == r,
53-
(&Constant::Char(l), &Constant::Char(r)) => l == r,
54-
(&Constant::Int(l), &Constant::Int(r)) => l == r,
55-
(&Constant::F64(l), &Constant::F64(r)) => {
51+
(&Self::Str(ref ls), &Self::Str(ref rs)) => ls == rs,
52+
(&Self::Binary(ref l), &Self::Binary(ref r)) => l == r,
53+
(&Self::Char(l), &Self::Char(r)) => l == r,
54+
(&Self::Int(l), &Self::Int(r)) => l == r,
55+
(&Self::F64(l), &Self::F64(r)) => {
5656
// We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
5757
// `Fw32 == Fw64`, so don’t compare them.
5858
// `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
5959
l.to_bits() == r.to_bits()
6060
},
61-
(&Constant::F32(l), &Constant::F32(r)) => {
61+
(&Self::F32(l), &Self::F32(r)) => {
6262
// We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
6363
// `Fw32 == Fw64`, so don’t compare them.
6464
// `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
6565
f64::from(l).to_bits() == f64::from(r).to_bits()
6666
},
67-
(&Constant::Bool(l), &Constant::Bool(r)) => l == r,
68-
(&Constant::Vec(ref l), &Constant::Vec(ref r)) | (&Constant::Tuple(ref l), &Constant::Tuple(ref r)) => {
67+
(&Self::Bool(l), &Self::Bool(r)) => l == r,
68+
(&Self::Vec(ref l), &Self::Vec(ref r)) | (&Self::Tuple(ref l), &Self::Tuple(ref r)) => {
6969
l == r
7070
},
71-
(&Constant::Repeat(ref lv, ref ls), &Constant::Repeat(ref rv, ref rs)) => ls == rs && lv == rv,
71+
(&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => ls == rs && lv == rv,
7272
// TODO: are there inter-type equalities?
7373
_ => false,
7474
}
@@ -82,38 +82,38 @@ impl Hash for Constant {
8282
{
8383
std::mem::discriminant(self).hash(state);
8484
match *self {
85-
Constant::Str(ref s) => {
85+
Self::Str(ref s) => {
8686
s.hash(state);
8787
},
88-
Constant::Binary(ref b) => {
88+
Self::Binary(ref b) => {
8989
b.hash(state);
9090
},
91-
Constant::Char(c) => {
91+
Self::Char(c) => {
9292
c.hash(state);
9393
},
94-
Constant::Int(i) => {
94+
Self::Int(i) => {
9595
i.hash(state);
9696
},
97-
Constant::F32(f) => {
97+
Self::F32(f) => {
9898
f64::from(f).to_bits().hash(state);
9999
},
100-
Constant::F64(f) => {
100+
Self::F64(f) => {
101101
f.to_bits().hash(state);
102102
},
103-
Constant::Bool(b) => {
103+
Self::Bool(b) => {
104104
b.hash(state);
105105
},
106-
Constant::Vec(ref v) | Constant::Tuple(ref v) => {
106+
Self::Vec(ref v) | Self::Tuple(ref v) => {
107107
v.hash(state);
108108
},
109-
Constant::Repeat(ref c, l) => {
109+
Self::Repeat(ref c, l) => {
110110
c.hash(state);
111111
l.hash(state);
112112
},
113-
Constant::RawPtr(u) => {
113+
Self::RawPtr(u) => {
114114
u.hash(state);
115115
},
116-
Constant::Err(ref s) => {
116+
Self::Err(ref s) => {
117117
s.hash(state);
118118
},
119119
}
@@ -123,25 +123,25 @@ impl Hash for Constant {
123123
impl Constant {
124124
pub fn partial_cmp(tcx: TyCtxt<'_>, cmp_type: Ty<'_>, left: &Self, right: &Self) -> Option<Ordering> {
125125
match (left, right) {
126-
(&Constant::Str(ref ls), &Constant::Str(ref rs)) => Some(ls.cmp(rs)),
127-
(&Constant::Char(ref l), &Constant::Char(ref r)) => Some(l.cmp(r)),
128-
(&Constant::Int(l), &Constant::Int(r)) => {
126+
(&Self::Str(ref ls), &Self::Str(ref rs)) => Some(ls.cmp(rs)),
127+
(&Self::Char(ref l), &Self::Char(ref r)) => Some(l.cmp(r)),
128+
(&Self::Int(l), &Self::Int(r)) => {
129129
if let ty::Int(int_ty) = cmp_type.sty {
130130
Some(sext(tcx, l, int_ty).cmp(&sext(tcx, r, int_ty)))
131131
} else {
132132
Some(l.cmp(&r))
133133
}
134134
},
135-
(&Constant::F64(l), &Constant::F64(r)) => l.partial_cmp(&r),
136-
(&Constant::F32(l), &Constant::F32(r)) => l.partial_cmp(&r),
137-
(&Constant::Bool(ref l), &Constant::Bool(ref r)) => Some(l.cmp(r)),
138-
(&Constant::Tuple(ref l), &Constant::Tuple(ref r)) | (&Constant::Vec(ref l), &Constant::Vec(ref r)) => l
135+
(&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r),
136+
(&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r),
137+
(&Self::Bool(ref l), &Self::Bool(ref r)) => Some(l.cmp(r)),
138+
(&Self::Tuple(ref l), &Self::Tuple(ref r)) | (&Self::Vec(ref l), &Self::Vec(ref r)) => l
139139
.iter()
140140
.zip(r.iter())
141141
.map(|(li, ri)| Self::partial_cmp(tcx, cmp_type, li, ri))
142142
.find(|r| r.map_or(true, |o| o != Ordering::Equal))
143143
.unwrap_or_else(|| Some(l.len().cmp(&r.len()))),
144-
(&Constant::Repeat(ref lv, ref ls), &Constant::Repeat(ref rv, ref rs)) => {
144+
(&Self::Repeat(ref lv, ref ls), &Self::Repeat(ref rv, ref rs)) => {
145145
match Self::partial_cmp(tcx, cmp_type, lv, rv) {
146146
Some(Equal) => Some(ls.cmp(rs)),
147147
x => x,

clippy_lints/src/excessive_precision.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,20 @@ impl FloatFormat {
143143
fn new(s: &str) -> Self {
144144
s.chars()
145145
.find_map(|x| match x {
146-
'e' => Some(FloatFormat::LowerExp),
147-
'E' => Some(FloatFormat::UpperExp),
146+
'e' => Some(Self::LowerExp),
147+
'E' => Some(Self::UpperExp),
148148
_ => None,
149149
})
150-
.unwrap_or(FloatFormat::Normal)
150+
.unwrap_or(Self::Normal)
151151
}
152152
fn format<T>(&self, f: T) -> String
153153
where
154154
T: fmt::UpperExp + fmt::LowerExp + fmt::Display,
155155
{
156156
match self {
157-
FloatFormat::LowerExp => format!("{:e}", f),
158-
FloatFormat::UpperExp => format!("{:E}", f),
159-
FloatFormat::Normal => format!("{}", f),
157+
Self::LowerExp => format!("{:e}", f),
158+
Self::UpperExp => format!("{:E}", f),
159+
Self::Normal => format!("{}", f),
160160
}
161161
}
162162
}

clippy_lints/src/literal_representation.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ impl Radix {
115115
/// Returns a reasonable digit group size for this radix.
116116
crate fn suggest_grouping(&self) -> usize {
117117
match *self {
118-
Radix::Binary | Radix::Hexadecimal => 4,
119-
Radix::Octal | Radix::Decimal => 3,
118+
Self::Binary | Self::Hexadecimal => 4,
119+
Self::Octal | Self::Decimal => 3,
120120
}
121121
}
122122
}
@@ -285,7 +285,7 @@ enum WarningType {
285285
impl WarningType {
286286
crate fn display(&self, grouping_hint: &str, cx: &EarlyContext<'_>, span: syntax_pos::Span) {
287287
match self {
288-
WarningType::MistypedLiteralSuffix => span_lint_and_sugg(
288+
Self::MistypedLiteralSuffix => span_lint_and_sugg(
289289
cx,
290290
MISTYPED_LITERAL_SUFFIXES,
291291
span,
@@ -294,7 +294,7 @@ impl WarningType {
294294
grouping_hint.to_string(),
295295
Applicability::MaybeIncorrect,
296296
),
297-
WarningType::UnreadableLiteral => span_lint_and_sugg(
297+
Self::UnreadableLiteral => span_lint_and_sugg(
298298
cx,
299299
UNREADABLE_LITERAL,
300300
span,
@@ -303,7 +303,7 @@ impl WarningType {
303303
grouping_hint.to_owned(),
304304
Applicability::MachineApplicable,
305305
),
306-
WarningType::LargeDigitGroups => span_lint_and_sugg(
306+
Self::LargeDigitGroups => span_lint_and_sugg(
307307
cx,
308308
LARGE_DIGIT_GROUPS,
309309
span,
@@ -312,7 +312,7 @@ impl WarningType {
312312
grouping_hint.to_owned(),
313313
Applicability::MachineApplicable,
314314
),
315-
WarningType::InconsistentDigitGrouping => span_lint_and_sugg(
315+
Self::InconsistentDigitGrouping => span_lint_and_sugg(
316316
cx,
317317
INCONSISTENT_DIGIT_GROUPING,
318318
span,
@@ -321,7 +321,7 @@ impl WarningType {
321321
grouping_hint.to_owned(),
322322
Applicability::MachineApplicable,
323323
),
324-
WarningType::DecimalRepresentation => span_lint_and_sugg(
324+
Self::DecimalRepresentation => span_lint_and_sugg(
325325
cx,
326326
DECIMAL_LITERAL_REPRESENTATION,
327327
span,

clippy_lints/src/methods/mod.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -2505,14 +2505,14 @@ impl SelfKind {
25052505
let is_actually_self = |ty| is_self_ty(ty) || SpanlessEq::new(cx).eq_ty(ty, self_ty);
25062506
if is_self(arg) {
25072507
match self {
2508-
SelfKind::Value => is_actually_self(ty),
2509-
SelfKind::Ref | SelfKind::RefMut => {
2508+
Self::Value => is_actually_self(ty),
2509+
Self::Ref | Self::RefMut => {
25102510
if allow_value_for_ref && is_actually_self(ty) {
25112511
return true;
25122512
}
25132513
match ty.node {
25142514
hir::TyKind::Rptr(_, ref mt_ty) => {
2515-
let mutability_match = if self == SelfKind::Ref {
2515+
let mutability_match = if self == Self::Ref {
25162516
mt_ty.mutbl == hir::MutImmutable
25172517
} else {
25182518
mt_ty.mutbl == hir::MutMutable
@@ -2526,20 +2526,20 @@ impl SelfKind {
25262526
}
25272527
} else {
25282528
match self {
2529-
SelfKind::Value => false,
2530-
SelfKind::Ref => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASREF_TRAIT),
2531-
SelfKind::RefMut => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASMUT_TRAIT),
2532-
SelfKind::No => true,
2529+
Self::Value => false,
2530+
Self::Ref => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASREF_TRAIT),
2531+
Self::RefMut => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASMUT_TRAIT),
2532+
Self::No => true,
25332533
}
25342534
}
25352535
}
25362536

25372537
fn description(self) -> &'static str {
25382538
match self {
2539-
SelfKind::Value => "self by value",
2540-
SelfKind::Ref => "self by reference",
2541-
SelfKind::RefMut => "self by mutable reference",
2542-
SelfKind::No => "no self",
2539+
Self::Value => "self by value",
2540+
Self::Ref => "self by reference",
2541+
Self::RefMut => "self by mutable reference",
2542+
Self::No => "no self",
25432543
}
25442544
}
25452545
}
@@ -2609,17 +2609,17 @@ fn single_segment_ty(ty: &hir::Ty) -> Option<&hir::PathSegment> {
26092609
impl Convention {
26102610
fn check(&self, other: &str) -> bool {
26112611
match *self {
2612-
Convention::Eq(this) => this == other,
2613-
Convention::StartsWith(this) => other.starts_with(this) && this != other,
2612+
Self::Eq(this) => this == other,
2613+
Self::StartsWith(this) => other.starts_with(this) && this != other,
26142614
}
26152615
}
26162616
}
26172617

26182618
impl fmt::Display for Convention {
26192619
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
26202620
match *self {
2621-
Convention::Eq(this) => this.fmt(f),
2622-
Convention::StartsWith(this) => this.fmt(f).and_then(|_| '*'.fmt(f)),
2621+
Self::Eq(this) => this.fmt(f),
2622+
Self::StartsWith(this) => this.fmt(f).and_then(|_| '*'.fmt(f)),
26232623
}
26242624
}
26252625
}
@@ -2636,11 +2636,11 @@ impl OutType {
26362636
fn matches(self, cx: &LateContext<'_, '_>, ty: &hir::FunctionRetTy) -> bool {
26372637
let is_unit = |ty: &hir::Ty| SpanlessEq::new(cx).eq_ty_kind(&ty.node, &hir::TyKind::Tup(vec![].into()));
26382638
match (self, ty) {
2639-
(OutType::Unit, &hir::DefaultReturn(_)) => true,
2640-
(OutType::Unit, &hir::Return(ref ty)) if is_unit(ty) => true,
2641-
(OutType::Bool, &hir::Return(ref ty)) if is_bool(ty) => true,
2642-
(OutType::Any, &hir::Return(ref ty)) if !is_unit(ty) => true,
2643-
(OutType::Ref, &hir::Return(ref ty)) => matches!(ty.node, hir::TyKind::Rptr(_, _)),
2639+
(Self::Unit, &hir::DefaultReturn(_)) => true,
2640+
(Self::Unit, &hir::Return(ref ty)) if is_unit(ty) => true,
2641+
(Self::Bool, &hir::Return(ref ty)) if is_bool(ty) => true,
2642+
(Self::Any, &hir::Return(ref ty)) if !is_unit(ty) => true,
2643+
(Self::Ref, &hir::Return(ref ty)) => matches!(ty.node, hir::TyKind::Rptr(_, _)),
26442644
_ => false,
26452645
}
26462646
}

clippy_lints/src/non_copy_const.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ declare_clippy_lint! {
8484
"referencing const with interior mutability"
8585
}
8686

87+
#[allow(dead_code)]
8788
#[derive(Copy, Clone)]
8889
enum Source {
8990
Item { item: Span },
@@ -94,12 +95,12 @@ enum Source {
9495
impl Source {
9596
fn lint(&self) -> (&'static Lint, &'static str, Span) {
9697
match self {
97-
Source::Item { item } | Source::Assoc { item, .. } => (
98+
Self::Item { item } | Self::Assoc { item, .. } => (
9899
DECLARE_INTERIOR_MUTABLE_CONST,
99100
"a const item should never be interior mutable",
100101
*item,
101102
),
102-
Source::Expr { expr } => (
103+
Self::Expr { expr } => (
103104
BORROW_INTERIOR_MUTABLE_CONST,
104105
"a const item with interior mutability should not be borrowed",
105106
*expr,

clippy_lints/src/ptr_offset_with_cast.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,17 @@ enum Method {
133133
impl Method {
134134
fn suggestion(self) -> &'static str {
135135
match self {
136-
Method::Offset => "add",
137-
Method::WrappingOffset => "wrapping_add",
136+
Self::Offset => "add",
137+
Self::WrappingOffset => "wrapping_add",
138138
}
139139
}
140140
}
141141

142142
impl fmt::Display for Method {
143143
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
144144
match self {
145-
Method::Offset => write!(f, "offset"),
146-
Method::WrappingOffset => write!(f, "wrapping_offset"),
145+
Self::Offset => write!(f, "offset"),
146+
Self::WrappingOffset => write!(f, "wrapping_offset"),
147147
}
148148
}
149149
}

clippy_lints/src/types.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1725,10 +1725,10 @@ impl PartialEq for FullInt {
17251725
impl PartialOrd for FullInt {
17261726
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
17271727
Some(match (self, other) {
1728-
(&FullInt::S(s), &FullInt::S(o)) => s.cmp(&o),
1729-
(&FullInt::U(s), &FullInt::U(o)) => s.cmp(&o),
1730-
(&FullInt::S(s), &FullInt::U(o)) => Self::cmp_s_u(s, o),
1731-
(&FullInt::U(s), &FullInt::S(o)) => Self::cmp_s_u(o, s).reverse(),
1728+
(&Self::S(s), &Self::S(o)) => s.cmp(&o),
1729+
(&Self::U(s), &Self::U(o)) => s.cmp(&o),
1730+
(&Self::S(s), &Self::U(o)) => Self::cmp_s_u(s, o),
1731+
(&Self::U(s), &Self::S(o)) => Self::cmp_s_u(o, s).reverse(),
17321732
})
17331733
}
17341734
}

0 commit comments

Comments
 (0)