Skip to content

Commit 6256892

Browse files
Merge #3402
3402: clippy: fix pedantic warnings and run clippy::pedantic lints on the codebase r=oli-obk a=matthiaskrgr Turn on pedantic lints in dogfood and base tests. needless_bool: fix clippy::items-after-statements redundant_pattern_matching: fix clippy::similar-names mods.rs: fix clippy::explicit-iter-loop returns.rs: allow clippy::cast-possible-wrap Fixes #3172 Co-authored-by: Matthias Krüger <[email protected]>
2 parents 7c86a9c + df7cff3 commit 6256892

File tree

7 files changed

+18
-16
lines changed

7 files changed

+18
-16
lines changed

ci/base-tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ cd rustc_tools_util && cargo test && cd ..
2727

2828
CLIPPY="`pwd`/target/debug/cargo-clippy clippy"
2929
# run clippy on its own codebase...
30-
${CLIPPY} --all-targets --all-features -- -D clippy::all -D clippy::internal
30+
${CLIPPY} --all-targets --all-features -- -D clippy::all -D clippy::internal -Dclippy::pedantic
3131
# ... and some test directories
3232
for dir in clippy_workspace_tests clippy_workspace_tests/src clippy_workspace_tests/subcrate clippy_workspace_tests/subcrate/src clippy_dev rustc_tools_util
3333
do
3434
cd ${dir}
35-
${CLIPPY} -- -D clippy::all
35+
${CLIPPY} -- -D clippy::all -D clippy::pedantic
3636
cd -
3737
done
3838

clippy_dev/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// except according to those terms.
99

1010

11-
1211
#![allow(clippy::default_hash_types)]
1312

1413
use itertools::Itertools;

clippy_lints/src/methods/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
931931
if let TyKind::Opaque(def_id, _) = ret_ty.sty {
932932

933933
// one of the associated types must be Self
934-
for predicate in cx.tcx.predicates_of(def_id).predicates.iter() {
934+
for predicate in &cx.tcx.predicates_of(def_id).predicates {
935935
match predicate {
936936
(Predicate::Projection(poly_projection_predicate), _) => {
937937
let binder = poly_projection_predicate.ty();

clippy_lints/src/needless_bool.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ impl LintPass for BoolComparison {
133133

134134
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
135135
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
136+
use self::Expression::*;
137+
136138
if in_macro(e.span) {
137139
return;
138140
}
139-
use self::Expression::*;
141+
140142
if let ExprKind::Binary(Spanned { node: BinOpKind::Eq, .. }, ref left_side, ref right_side) = e.node {
141143
match (fetch_bool_expr(left_side), fetch_bool_expr(right_side)) {
142144
(Bool(true), Other) => {

clippy_lints/src/redundant_pattern_matching.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ fn find_sugg_for_if_let<'a, 'tcx>(
8383
) {
8484
if arms[0].pats.len() == 1 {
8585
let good_method = match arms[0].pats[0].node {
86-
PatKind::TupleStruct(ref path, ref pats, _) if pats.len() == 1 => {
87-
if let PatKind::Wild = pats[0].node {
86+
PatKind::TupleStruct(ref path, ref patterns, _) if patterns.len() == 1 => {
87+
if let PatKind::Wild = patterns[0].node {
8888
if match_qpath(path, &paths::RESULT_OK) {
8989
"is_ok()"
9090
} else if match_qpath(path, &paths::RESULT_ERR) {
@@ -135,10 +135,10 @@ fn find_sugg_for_match<'a, 'tcx>(
135135

136136
let found_good_method = match node_pair {
137137
(
138-
PatKind::TupleStruct(ref path_left, ref pats_left, _),
139-
PatKind::TupleStruct(ref path_right, ref pats_right, _)
140-
) if pats_left.len() == 1 && pats_right.len() == 1 => {
141-
if let (PatKind::Wild, PatKind::Wild) = (&pats_left[0].node, &pats_right[0].node) {
138+
PatKind::TupleStruct(ref path_left, ref patterns_left, _),
139+
PatKind::TupleStruct(ref path_right, ref patterns_right, _)
140+
) if patterns_left.len() == 1 && patterns_right.len() == 1 => {
141+
if let (PatKind::Wild, PatKind::Wild) = (&patterns_left[0].node, &patterns_right[0].node) {
142142
find_good_method_for_match(
143143
arms,
144144
path_left,
@@ -153,13 +153,13 @@ fn find_sugg_for_match<'a, 'tcx>(
153153
}
154154
},
155155
(
156-
PatKind::TupleStruct(ref path_left, ref pats, _),
156+
PatKind::TupleStruct(ref path_left, ref patterns, _),
157157
PatKind::Path(ref path_right)
158158
) | (
159159
PatKind::Path(ref path_left),
160-
PatKind::TupleStruct(ref path_right, ref pats, _)
161-
) if pats.len() == 1 => {
162-
if let PatKind::Wild = pats[0].node {
160+
PatKind::TupleStruct(ref path_right, ref patterns, _)
161+
) if patterns.len() == 1 => {
162+
if let PatKind::Wild = patterns[0].node {
163163
find_good_method_for_match(
164164
arms,
165165
path_left,

clippy_lints/src/returns.rs

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ impl EarlyLintPass for ReturnPass {
200200
cx.sess().source_map()
201201
.span_to_snippet(span.with_hi(ty.span.hi())) {
202202
if let Some(rpos) = fn_source.rfind("->") {
203+
#[allow(clippy::cast_possible_truncation)]
203204
(ty.span.with_lo(BytePos(span.lo().0 + rpos as u32)),
204205
Applicability::MachineApplicable)
205206
} else {

tests/dogfood.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn dogfood() {
2323
.arg("--all-features")
2424
.arg("--manifest-path")
2525
.arg(root_dir.join("Cargo.toml"))
26-
.args(&["--", "-W clippy::internal"])
26+
.args(&["--", "-W clippy::internal -W clippy::pedantic"])
2727
.env("CLIPPY_DOGFOOD", "true")
2828
.output()
2929
.unwrap();

0 commit comments

Comments
 (0)