Skip to content

Commit e1a78ae

Browse files
committed
update tests and fix lints in clippy
1 parent 6396a7a commit e1a78ae

8 files changed

+38
-33
lines changed

clippy_lints/src/invalid_ref.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,5 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef {
5151
span_help_and_lint(cx, INVALID_REF, expr.span, msg, HELP);
5252
}
5353
}
54-
return;
5554
}
5655
}

clippy_lints/src/methods/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,16 +1648,15 @@ fn lint_unnecessary_fold(cx: &LateContext<'_, '_>, expr: &hir::Expr, fold_args:
16481648
);
16491649

16501650
// Check if the first argument to .fold is a suitable literal
1651-
match fold_args[1].node {
1652-
hir::ExprKind::Lit(ref lit) => match lit.node {
1651+
if let hir::ExprKind::Lit(ref lit) = fold_args[1].node {
1652+
match lit.node {
16531653
ast::LitKind::Bool(false) => check_fold_with_op(cx, fold_args, hir::BinOpKind::Or, "any", true),
16541654
ast::LitKind::Bool(true) => check_fold_with_op(cx, fold_args, hir::BinOpKind::And, "all", true),
16551655
ast::LitKind::Int(0, _) => check_fold_with_op(cx, fold_args, hir::BinOpKind::Add, "sum", false),
16561656
ast::LitKind::Int(1, _) => check_fold_with_op(cx, fold_args, hir::BinOpKind::Mul, "product", false),
1657-
_ => return,
1658-
},
1659-
_ => return,
1660-
};
1657+
_ => (),
1658+
}
1659+
}
16611660
}
16621661

16631662
fn lint_iter_nth<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &hir::Expr, iter_args: &'tcx [hir::Expr], is_mut: bool) {

clippy_lints/src/non_expressive_names.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
169169
.any(|id| id.name == ident.name)
170170
{
171171
return;
172-
} else if let Some(scope) = &mut self.0.single_char_names.last_mut() {
172+
}
173+
174+
if let Some(scope) = &mut self.0.single_char_names.last_mut() {
173175
scope.push(ident);
174176
}
175177
}

clippy_lints/src/redundant_pattern_matching.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ fn find_sugg_for_if_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr,
9595
);
9696
},
9797
);
98-
} else {
99-
return;
10098
}
10199
}
102100

@@ -161,8 +159,6 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o
161159
},
162160
);
163161
}
164-
} else {
165-
return;
166162
}
167163
}
168164

tests/compile-test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ fn run_ui_toml() {
141141

142142
let res = run_ui_toml_tests(&config, tests);
143143
match res {
144-
Ok(true) => {},
144+
Ok(true) => {}
145145
Ok(false) => panic!("Some tests failed"),
146146
Err(e) => {
147147
println!("I/O failure during tests: {:?}", e);
148-
},
148+
}
149149
}
150150
}
151151

tests/missing-test-files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn explore_directory(dir: &Path) -> Vec<String> {
4646
if file_stem != current_file {
4747
missing_files.push(path.to_str().unwrap().to_string());
4848
}
49-
},
49+
}
5050
_ => continue,
5151
};
5252
}

tests/ui/needless_return.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#![warn(clippy::needless_return)]
22

33
macro_rules! the_answer {
4-
() => (42)
4+
() => {
5+
42
6+
};
57
}
68

79
fn test_end_of_fn() -> bool {
@@ -56,6 +58,13 @@ fn test_void_if_fun(b: bool) {
5658
}
5759
}
5860

61+
fn test_void_match(x: u32) {
62+
match x {
63+
0 => (),
64+
_ => return,
65+
}
66+
}
67+
5968
fn main() {
6069
let _ = test_end_of_fn();
6170
let _ = test_no_semicolon();

tests/ui/needless_return.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
11
error: unneeded return statement
2-
--> $DIR/needless_return.rs:12:5
2+
--> $DIR/needless_return.rs:14:5
33
|
44
LL | return true;
55
| ^^^^^^^^^^^^ help: remove `return` as shown: `true`
66
|
77
= note: `-D clippy::needless-return` implied by `-D warnings`
88

99
error: unneeded return statement
10-
--> $DIR/needless_return.rs:16:5
10+
--> $DIR/needless_return.rs:18:5
1111
|
1212
LL | return true;
1313
| ^^^^^^^^^^^^ help: remove `return` as shown: `true`
1414

1515
error: unneeded return statement
16-
--> $DIR/needless_return.rs:21:9
16+
--> $DIR/needless_return.rs:23:9
1717
|
1818
LL | return true;
1919
| ^^^^^^^^^^^^ help: remove `return` as shown: `true`
2020

2121
error: unneeded return statement
22-
--> $DIR/needless_return.rs:23:9
22+
--> $DIR/needless_return.rs:25:9
2323
|
2424
LL | return false;
2525
| ^^^^^^^^^^^^^ help: remove `return` as shown: `false`
2626

2727
error: unneeded return statement
28-
--> $DIR/needless_return.rs:29:17
28+
--> $DIR/needless_return.rs:31:17
2929
|
3030
LL | true => return false,
3131
| ^^^^^^^^^^^^ help: remove `return` as shown: `false`
3232

3333
error: unneeded return statement
34-
--> $DIR/needless_return.rs:31:13
34+
--> $DIR/needless_return.rs:33:13
3535
|
3636
LL | return true;
3737
| ^^^^^^^^^^^^ help: remove `return` as shown: `true`
3838

3939
error: unneeded return statement
40-
--> $DIR/needless_return.rs:38:9
40+
--> $DIR/needless_return.rs:40:9
4141
|
4242
LL | return true;
4343
| ^^^^^^^^^^^^ help: remove `return` as shown: `true`
4444

4545
error: unneeded return statement
46-
--> $DIR/needless_return.rs:40:16
46+
--> $DIR/needless_return.rs:42:16
4747
|
4848
LL | let _ = || return true;
4949
| ^^^^^^^^^^^ help: remove `return` as shown: `true`
5050

5151
error: unneeded return statement
52-
--> $DIR/needless_return.rs:44:5
53-
|
54-
LL | return the_answer!();
55-
| ^^^^^^^^^^^^^^^^^^^^^
56-
57-
error: unneeded return statement
58-
--> $DIR/needless_return.rs:48:5
52+
--> $DIR/needless_return.rs:50:5
5953
|
6054
LL | return;
6155
| ^^^^^^^ help: remove `return`
6256

6357
error: unneeded return statement
64-
--> $DIR/needless_return.rs:53:9
58+
--> $DIR/needless_return.rs:55:9
6559
|
6660
LL | return;
6761
| ^^^^^^^ help: remove `return`
6862

6963
error: unneeded return statement
70-
--> $DIR/needless_return.rs:55:9
64+
--> $DIR/needless_return.rs:57:9
7165
|
7266
LL | return;
7367
| ^^^^^^^ help: remove `return`
7468

69+
error: unneeded return statement
70+
--> $DIR/needless_return.rs:64:14
71+
|
72+
LL | _ => return,
73+
| ^^^^^^ help: replace `return` with the unit type `()`: `()`
74+
7575
error: aborting due to 12 previous errors
7676

0 commit comments

Comments
 (0)