Skip to content

Commit 6dcc8d5

Browse files
committed
Auto merge of #5141 - xiongmao86:issue5095, r=flip1995
Fixes issue 5095 fixes #5095. - [x] Followed [lint naming conventions][lint_naming] - [x] Added passing UI tests (including committed `.stderr` file) - [x] `cargo test` passes locally - [x] Executed `cargo dev update_lints` - [x] Added lint documentation - [x] Run `cargo dev fmt` [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints changelog: (internal) warn about collapsible `span_lint_and_then` calls.
2 parents 2efc2d6 + 7aeb3a4 commit 6dcc8d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+758
-199
lines changed

clippy_lints/src/as_conversions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ impl EarlyLintPass for AsConversions {
5050
AS_CONVERSIONS,
5151
expr.span,
5252
"using a potentially dangerous silent `as` conversion",
53+
None,
5354
"consider using a safe wrapper for this conversion",
5455
);
5556
}

clippy_lints/src/assertions_on_constants.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4141
} else {
4242
"`assert!(true)` will be optimized out by the compiler"
4343
},
44+
None,
4445
"remove it",
4546
);
4647
};
@@ -50,6 +51,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
5051
ASSERTIONS_ON_CONSTANTS,
5152
e.span,
5253
"`assert!(false)` should probably be replaced",
54+
None,
5355
"use `panic!()` or `unreachable!()`",
5456
);
5557
};
@@ -59,6 +61,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
5961
ASSERTIONS_ON_CONSTANTS,
6062
e.span,
6163
&format!("`assert!(false, {})` should probably be replaced", panic_message),
64+
None,
6265
&format!("use `panic!({})` or `unreachable!({})`", panic_message, panic_message),
6366
)
6467
};

clippy_lints/src/atomic_ordering.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
8585
INVALID_ATOMIC_ORDERING,
8686
ordering_arg.span,
8787
"atomic loads cannot have `Release` and `AcqRel` ordering",
88+
None,
8889
"consider using ordering modes `Acquire`, `SeqCst` or `Relaxed`"
8990
);
9091
} else if method == "store" &&
@@ -94,6 +95,7 @@ fn check_atomic_load_store(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
9495
INVALID_ATOMIC_ORDERING,
9596
ordering_arg.span,
9697
"atomic stores cannot have `Acquire` and `AcqRel` ordering",
98+
None,
9799
"consider using ordering modes `Release`, `SeqCst` or `Relaxed`"
98100
);
99101
}
@@ -118,6 +120,7 @@ fn check_memory_fence(cx: &LateContext<'_, '_>, expr: &Expr<'_>) {
118120
INVALID_ATOMIC_ORDERING,
119121
args[0].span,
120122
"memory fences cannot have `Relaxed` ordering",
123+
None,
121124
"consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`"
122125
);
123126
}

clippy_lints/src/cognitive_complexity.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl CognitiveComplexity {
105105
rust_cc,
106106
self.limit.limit()
107107
),
108+
None,
108109
"you could split it up into multiple smaller functions",
109110
);
110111
}

clippy_lints/src/comparison_chain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ComparisonChain {
104104
COMPARISON_CHAIN,
105105
expr.span,
106106
"`if` chain can be rewritten with `match`",
107+
None,
107108
"Consider rewriting the `if` chain to use `cmp` and `match`.",
108109
)
109110
}

clippy_lints/src/copies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn lint_same_then_else(cx: &LateContext<'_, '_>, blocks: &[&Block<'_>]) {
183183
IF_SAME_THEN_ELSE,
184184
j.span,
185185
"this `if` has identical blocks",
186-
i.span,
186+
Some(i.span),
187187
"same as this",
188188
);
189189
}
@@ -206,7 +206,7 @@ fn lint_same_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
206206
IFS_SAME_COND,
207207
j.span,
208208
"this `if` has the same condition as a previous `if`",
209-
i.span,
209+
Some(i.span),
210210
"same as this",
211211
);
212212
}
@@ -234,7 +234,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_, '_>, conds: &[&Expr<'_>]) {
234234
SAME_FUNCTIONS_IN_IF_CONDITION,
235235
j.span,
236236
"this `if` has the same function call as a previous `if`",
237-
i.span,
237+
Some(i.span),
238238
"same as this",
239239
);
240240
}

clippy_lints/src/copy_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
4646
COPY_ITERATOR,
4747
item.span,
4848
"you are implementing `Iterator` on a `Copy` type",
49-
item.span,
49+
None,
5050
"consider implementing `IntoIterator` instead",
5151
);
5252
}

clippy_lints/src/dbg_macro.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ impl EarlyLintPass for DbgMacro {
4848
DBG_MACRO,
4949
mac.span(),
5050
"`dbg!` macro is intended as a debugging tool",
51+
None,
5152
"ensure to avoid having uses of it in version control",
5253
);
5354
}

clippy_lints/src/derive.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::paths;
2-
use crate::utils::{is_automatically_derived, is_copy, match_path, span_lint_and_then};
2+
use crate::utils::{is_automatically_derived, is_copy, match_path, span_lint_and_note, span_lint_and_then};
33
use if_chain::if_chain;
44
use rustc_hir::{Item, ItemKind, TraitRef};
55
use rustc_lint::{LateContext, LateLintPass};
@@ -163,14 +163,13 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item<'_>, trait
163163
_ => (),
164164
}
165165

166-
span_lint_and_then(
166+
span_lint_and_note(
167167
cx,
168168
EXPL_IMPL_CLONE_ON_COPY,
169169
item.span,
170170
"you are implementing `Clone` explicitly on a `Copy` type",
171-
|diag| {
172-
diag.span_note(item.span, "consider deriving `Clone` or removing `Copy`");
173-
},
171+
Some(item.span),
172+
"consider deriving `Clone` or removing `Copy`",
174173
);
175174
}
176175
}

clippy_lints/src/drop_forget_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
135135
lint,
136136
expr.span,
137137
&msg,
138-
arg.span,
138+
Some(arg.span),
139139
&format!("argument has type `{}`", arg_ty));
140140
} else if is_copy(cx, arg_ty) {
141141
if match_def_path(cx, def_id, &paths::DROP) {
@@ -151,7 +151,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DropForgetRef {
151151
lint,
152152
expr.span,
153153
&msg,
154-
arg.span,
154+
Some(arg.span),
155155
&format!("argument has type {}", arg_ty));
156156
}
157157
}

0 commit comments

Comments
 (0)