Skip to content

Commit 4cd7ad0

Browse files
committed
Merge commit '00e31fa5af1895bf8ff1e2b1e25b041362cdc33e' into clippy_backport
2 parents 708d57e + 00e31fa commit 4cd7ad0

25 files changed

+95
-89
lines changed

src/tools/clippy/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2746,7 +2746,6 @@ Released 2018-09-13
27462746
[`if_let_redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching
27472747
[`if_not_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
27482748
[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
2749-
[`if_then_panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_panic
27502749
[`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none
27512750
[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond
27522751
[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone
@@ -2804,6 +2803,7 @@ Released 2018-09-13
28042803
[`lossy_float_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#lossy_float_literal
28052804
[`macro_use_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#macro_use_imports
28062805
[`main_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#main_recursion
2806+
[`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert
28072807
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
28082808
[`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map
28092809
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map

src/tools/clippy/clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
126126
target_mut,
127127
},
128128
));
129-
}
129+
},
130130
_ => (),
131131
}
132132
},

src/tools/clippy/clippy_lints/src/entry.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,14 @@ fn try_parse_contains(cx: &LateContext<'_>, expr: &'tcx Expr<'_>) -> Option<(Map
245245
ExprKind::MethodCall(
246246
_,
247247
_,
248-
[map, Expr {
249-
kind: ExprKind::AddrOf(_, _, key),
250-
span: key_span,
251-
..
252-
}],
248+
[
249+
map,
250+
Expr {
251+
kind: ExprKind::AddrOf(_, _, key),
252+
span: key_span,
253+
..
254+
},
255+
],
253256
_,
254257
) if key_span.ctxt() == expr.span.ctxt() => {
255258
let id = cx.typeck_results().type_dependent_def_id(expr.hir_id)?;

src/tools/clippy/clippy_lints/src/eta_reduction.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,16 @@ fn check_inputs(cx: &LateContext<'_>, params: &[Param<'_>], call_args: &[Expr<'_
169169
}
170170
match *cx.typeck_results().expr_adjustments(arg) {
171171
[] => true,
172-
[Adjustment {
173-
kind: Adjust::Deref(None),
174-
..
175-
}, Adjustment {
176-
kind: Adjust::Borrow(AutoBorrow::Ref(_, mu2)),
177-
..
178-
}] => {
172+
[
173+
Adjustment {
174+
kind: Adjust::Deref(None),
175+
..
176+
},
177+
Adjustment {
178+
kind: Adjust::Borrow(AutoBorrow::Ref(_, mu2)),
179+
..
180+
},
181+
] => {
179182
// re-borrow with the same mutability is allowed
180183
let ty = cx.typeck_results().expr_ty(arg);
181184
matches!(*ty.kind(), ty::Ref(.., mu1) if mu1 == mu2.into())

src/tools/clippy/clippy_lints/src/int_plus_one.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl IntPlusOne {
8989
},
9090
_ => None,
9191
}
92-
}
92+
},
9393
// case where `x + 1 <= ...` or `1 + x <= ...`
9494
(BinOpKind::Le, &ExprKind::Binary(ref lhskind, ref lhslhs, ref lhsrhs), _)
9595
if lhskind.node == BinOpKind::Add =>
@@ -104,7 +104,7 @@ impl IntPlusOne {
104104
},
105105
_ => None,
106106
}
107-
}
107+
},
108108
// case where `... >= y - 1` or `... >= -1 + y`
109109
(BinOpKind::Le, _, &ExprKind::Binary(ref rhskind, ref rhslhs, ref rhsrhs)) => {
110110
match (rhskind.node, &rhslhs.kind, &rhsrhs.kind) {

src/tools/clippy/clippy_lints/src/lib.register_all.rs

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
7474
LintId::of(get_last_with_len::GET_LAST_WITH_LEN),
7575
LintId::of(identity_op::IDENTITY_OP),
7676
LintId::of(if_let_mutex::IF_LET_MUTEX),
77-
LintId::of(if_then_panic::IF_THEN_PANIC),
7877
LintId::of(indexing_slicing::OUT_OF_BOUNDS_INDEXING),
7978
LintId::of(infinite_iter::INFINITE_ITER),
8079
LintId::of(inherent_to_string::INHERENT_TO_STRING),

src/tools/clippy/clippy_lints/src/lib.register_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ store.register_lints(&[
156156
identity_op::IDENTITY_OP,
157157
if_let_mutex::IF_LET_MUTEX,
158158
if_not_else::IF_NOT_ELSE,
159-
if_then_panic::IF_THEN_PANIC,
160159
if_then_some_else_none::IF_THEN_SOME_ELSE_NONE,
161160
implicit_hasher::IMPLICIT_HASHER,
162161
implicit_return::IMPLICIT_RETURN,
@@ -213,6 +212,7 @@ store.register_lints(&[
213212
loops::WHILE_LET_ON_ITERATOR,
214213
macro_use::MACRO_USE_IMPORTS,
215214
main_recursion::MAIN_RECURSION,
215+
manual_assert::MANUAL_ASSERT,
216216
manual_async_fn::MANUAL_ASYNC_FN,
217217
manual_map::MANUAL_MAP,
218218
manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE,

src/tools/clippy/clippy_lints/src/lib.register_pedantic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
4848
LintId::of(loops::EXPLICIT_INTO_ITER_LOOP),
4949
LintId::of(loops::EXPLICIT_ITER_LOOP),
5050
LintId::of(macro_use::MACRO_USE_IMPORTS),
51+
LintId::of(manual_assert::MANUAL_ASSERT),
5152
LintId::of(manual_ok_or::MANUAL_OK_OR),
5253
LintId::of(match_on_vec_items::MATCH_ON_VEC_ITEMS),
5354
LintId::of(matches::MATCH_BOOL),

src/tools/clippy/clippy_lints/src/lib.register_style.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![
2727
LintId::of(functions::DOUBLE_MUST_USE),
2828
LintId::of(functions::MUST_USE_UNIT),
2929
LintId::of(functions::RESULT_UNIT_ERR),
30-
LintId::of(if_then_panic::IF_THEN_PANIC),
3130
LintId::of(inherent_to_string::INHERENT_TO_STRING),
3231
LintId::of(len_zero::COMPARISON_TO_EMPTY),
3332
LintId::of(len_zero::LEN_WITHOUT_IS_EMPTY),

src/tools/clippy/clippy_lints/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ mod get_last_with_len;
227227
mod identity_op;
228228
mod if_let_mutex;
229229
mod if_not_else;
230-
mod if_then_panic;
231230
mod if_then_some_else_none;
232231
mod implicit_hasher;
233232
mod implicit_return;
@@ -254,6 +253,7 @@ mod literal_representation;
254253
mod loops;
255254
mod macro_use;
256255
mod main_recursion;
256+
mod manual_assert;
257257
mod manual_async_fn;
258258
mod manual_map;
259259
mod manual_non_exhaustive;
@@ -764,7 +764,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
764764
store.register_late_pass(move || Box::new(self_named_constructors::SelfNamedConstructors));
765765
store.register_late_pass(move || Box::new(feature_name::FeatureName));
766766
store.register_late_pass(move || Box::new(iter_not_returning_iterator::IterNotReturningIterator));
767-
store.register_late_pass(move || Box::new(if_then_panic::IfThenPanic));
767+
store.register_late_pass(move || Box::new(manual_assert::ManualAssert));
768768
let enable_raw_pointer_heuristic_for_send = conf.enable_raw_pointer_heuristic_for_send;
769769
store.register_late_pass(move || Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new(enable_raw_pointer_heuristic_for_send)));
770770
}

src/tools/clippy/clippy_lints/src/loops/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ pub(super) fn make_iterator_snippet(cx: &LateContext<'_>, arg: &Expr<'_>, applic
338338
sugg::Sugg::hir_with_applicability(cx, arg_inner, "_", applic_ref).maybe_par(),
339339
meth_name,
340340
)
341-
}
341+
},
342342
_ => format!(
343343
"{}.into_iter()",
344344
sugg::Sugg::hir_with_applicability(cx, arg, "_", applic_ref).maybe_par()

src/tools/clippy/clippy_lints/src/if_then_panic.rs src/tools/clippy/clippy_lints/src/manual_assert.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ declare_clippy_lint! {
2626
/// let sad_people: Vec<&str> = vec![];
2727
/// assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people);
2828
/// ```
29-
pub IF_THEN_PANIC,
30-
style,
29+
pub MANUAL_ASSERT,
30+
pedantic,
3131
"`panic!` and only a `panic!` in `if`-then statement"
3232
}
3333

34-
declare_lint_pass!(IfThenPanic => [IF_THEN_PANIC]);
34+
declare_lint_pass!(ManualAssert => [MANUAL_ASSERT]);
3535

36-
impl LateLintPass<'_> for IfThenPanic {
36+
impl LateLintPass<'_> for ManualAssert {
3737
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
3838
if_chain! {
3939
if let Expr {
@@ -86,7 +86,7 @@ impl LateLintPass<'_> for IfThenPanic {
8686

8787
span_lint_and_sugg(
8888
cx,
89-
IF_THEN_PANIC,
89+
MANUAL_ASSERT,
9090
expr.span,
9191
"only a `panic!` in `if`-then statement",
9292
"try",

src/tools/clippy/clippy_lints/src/methods/clone_on_copy.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol,
8585
if expr.hir_id == self_arg.hir_id && ty != cx.typeck_results().expr_ty_adjusted(expr) =>
8686
{
8787
return;
88-
}
88+
},
8989
ExprKind::MethodCall(_, _, [self_arg, ..], _) if expr.hir_id == self_arg.hir_id => true,
9090
ExprKind::Match(_, _, MatchSource::TryDesugar | MatchSource::AwaitDesugar)
9191
| ExprKind::Field(..)
@@ -100,7 +100,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, method_name: Symbol,
100100
) =>
101101
{
102102
return;
103-
}
103+
},
104104
_ => false,
105105
};
106106

src/tools/clippy/clippy_lints/src/methods/or_fun_call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub(super) fn check<'tcx>(
186186
check_general_case(cx, name, method_span, &args[0], &args[1], expr.span, None);
187187
}
188188
}
189-
}
189+
},
190190
_ => (),
191191
}
192192
}

src/tools/clippy/clippy_lints/src/module_style.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl EarlyLintPass for ModStyle {
106106
}
107107
process_paths_for_mod_files(path, &mut folder_segments, &mut mod_folders);
108108
check_self_named_mod_exists(cx, path, file);
109-
}
109+
},
110110
_ => {},
111111
}
112112
}

src/tools/clippy/clippy_lints/src/needless_borrow.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,18 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
107107
if let ExprKind::AddrOf(BorrowKind::Ref, mutability, inner) = e.kind {
108108
if let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty(inner).kind() {
109109
for adj3 in cx.typeck_results().expr_adjustments(e).windows(3) {
110-
if let [Adjustment {
111-
kind: Adjust::Deref(_), ..
112-
}, Adjustment {
113-
kind: Adjust::Deref(_), ..
114-
}, Adjustment {
115-
kind: Adjust::Borrow(_),
116-
..
117-
}] = *adj3
110+
if let [
111+
Adjustment {
112+
kind: Adjust::Deref(_), ..
113+
},
114+
Adjustment {
115+
kind: Adjust::Deref(_), ..
116+
},
117+
Adjustment {
118+
kind: Adjust::Borrow(_),
119+
..
120+
},
121+
] = *adj3
118122
{
119123
let help_msg_ty = if matches!(mutability, Mutability::Not) {
120124
format!("&{}", ty)

src/tools/clippy/clippy_lints/src/vec_init_then_push.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ fn get_vec_init_kind<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Op
174174
}
175175
});
176176
}
177-
}
177+
},
178178
ExprKind::Path(QPath::Resolved(_, path))
179179
if match_def_path(cx, path.res.opt_def_id()?, &paths::DEFAULT_TRAIT_METHOD)
180180
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(expr), sym::Vec) =>
181181
{
182182
return Some(VecInitKind::New);
183-
}
183+
},
184184
_ => (),
185185
}
186186
}

src/tools/clippy/clippy_utils/src/lib.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -846,10 +846,13 @@ pub fn capture_local_usage(cx: &LateContext<'tcx>, e: &Expr<'_>) -> CaptureKind
846846
let mut capture_expr_ty = e;
847847

848848
for (parent_id, parent) in cx.tcx.hir().parent_iter(e.hir_id) {
849-
if let [Adjustment {
850-
kind: Adjust::Deref(_) | Adjust::Borrow(AutoBorrow::Ref(..)),
851-
target,
852-
}, ref adjust @ ..] = *cx
849+
if let [
850+
Adjustment {
851+
kind: Adjust::Deref(_) | Adjust::Borrow(AutoBorrow::Ref(..)),
852+
target,
853+
},
854+
ref adjust @ ..,
855+
] = *cx
853856
.typeck_results()
854857
.adjustments()
855858
.get(child_id)
@@ -1234,9 +1237,7 @@ pub fn get_enclosing_loop_or_closure(tcx: TyCtxt<'tcx>, expr: &Expr<'_>) -> Opti
12341237
for (_, node) in tcx.hir().parent_iter(expr.hir_id) {
12351238
match node {
12361239
Node::Expr(
1237-
e
1238-
@
1239-
Expr {
1240+
e @ Expr {
12401241
kind: ExprKind::Loop(..) | ExprKind::Closure(..),
12411242
..
12421243
},
@@ -1698,10 +1699,12 @@ pub fn is_async_fn(kind: FnKind<'_>) -> bool {
16981699
pub fn get_async_fn_body(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Option<&'tcx Expr<'tcx>> {
16991700
if let ExprKind::Call(
17001701
_,
1701-
&[Expr {
1702-
kind: ExprKind::Closure(_, _, body, _, _),
1703-
..
1704-
}],
1702+
&[
1703+
Expr {
1704+
kind: ExprKind::Closure(_, _, body, _, _),
1705+
..
1706+
},
1707+
],
17051708
) = body.value.kind
17061709
{
17071710
if let ExprKind::Block(

src/tools/clippy/tests/ui/fallible_impl_from.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![deny(clippy::fallible_impl_from)]
2-
#![allow(clippy::if_then_panic)]
32

43
// docs example
54
struct Foo(i32);

src/tools/clippy/tests/ui/fallible_impl_from.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: consider implementing `TryFrom` instead
2-
--> $DIR/fallible_impl_from.rs:6:1
2+
--> $DIR/fallible_impl_from.rs:5:1
33
|
44
LL | / impl From<String> for Foo {
55
LL | | fn from(s: String) -> Self {
@@ -15,13 +15,13 @@ LL | #![deny(clippy::fallible_impl_from)]
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
1717
note: potential failure(s)
18-
--> $DIR/fallible_impl_from.rs:8:13
18+
--> $DIR/fallible_impl_from.rs:7:13
1919
|
2020
LL | Foo(s.parse().unwrap())
2121
| ^^^^^^^^^^^^^^^^^^
2222

2323
error: consider implementing `TryFrom` instead
24-
--> $DIR/fallible_impl_from.rs:27:1
24+
--> $DIR/fallible_impl_from.rs:26:1
2525
|
2626
LL | / impl From<usize> for Invalid {
2727
LL | | fn from(i: usize) -> Invalid {
@@ -34,14 +34,14 @@ LL | | }
3434
|
3535
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
3636
note: potential failure(s)
37-
--> $DIR/fallible_impl_from.rs:30:13
37+
--> $DIR/fallible_impl_from.rs:29:13
3838
|
3939
LL | panic!();
4040
| ^^^^^^^^
4141
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
4242

4343
error: consider implementing `TryFrom` instead
44-
--> $DIR/fallible_impl_from.rs:36:1
44+
--> $DIR/fallible_impl_from.rs:35:1
4545
|
4646
LL | / impl From<Option<String>> for Invalid {
4747
LL | | fn from(s: Option<String>) -> Invalid {
@@ -54,7 +54,7 @@ LL | | }
5454
|
5555
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
5656
note: potential failure(s)
57-
--> $DIR/fallible_impl_from.rs:38:17
57+
--> $DIR/fallible_impl_from.rs:37:17
5858
|
5959
LL | let s = s.unwrap();
6060
| ^^^^^^^^^^
@@ -68,7 +68,7 @@ LL | panic!("{:?}", s);
6868
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
6969

7070
error: consider implementing `TryFrom` instead
71-
--> $DIR/fallible_impl_from.rs:54:1
71+
--> $DIR/fallible_impl_from.rs:53:1
7272
|
7373
LL | / impl<'a> From<&'a mut <Box<u32> as ProjStrTrait>::ProjString> for Invalid {
7474
LL | | fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
@@ -81,7 +81,7 @@ LL | | }
8181
|
8282
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
8383
note: potential failure(s)
84-
--> $DIR/fallible_impl_from.rs:56:12
84+
--> $DIR/fallible_impl_from.rs:55:12
8585
|
8686
LL | if s.parse::<u32>().ok().unwrap() != 42 {
8787
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/tools/clippy/tests/ui/if_then_panic.fixed src/tools/clippy/tests/ui/manual_assert.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::if_then_panic)]
2+
#![warn(clippy::manual_assert)]
33

44
fn main() {
55
let a = vec![1, 2, 3];

0 commit comments

Comments
 (0)