Skip to content

Commit 93bb229

Browse files
committed
Update clippy
1 parent 4d62619 commit 93bb229

29 files changed

+230
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,7 @@ Released 2018-09-13
12031203
[`suspicious_unary_op_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_unary_op_formatting
12041204
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
12051205
[`temporary_cstring_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_cstring_as_ptr
1206+
[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some
12061207
[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
12071208
[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
12081209
[`too_many_lines`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 332 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 333 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_lints/src/functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span,
548548
Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)),
549549
Array(ty, _) | Slice(ty) => is_mutable_ty(cx, ty, span, tys),
550550
RawPtr(ty::TypeAndMut { ty, mutbl }) | Ref(_, ty, mutbl) => {
551-
mutbl == hir::Mutability::MutMutable || is_mutable_ty(cx, ty, span, tys)
551+
mutbl == hir::Mutability::Mutable || is_mutable_ty(cx, ty, span, tys)
552552
},
553553
// calling something constitutes a side effect, so return true on all callables
554554
// also never calls need not be used, so return true for them, too
@@ -653,7 +653,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> {
653653
tys.clear();
654654
}
655655
},
656-
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(hir::Mutability::MutMutable, ref target) => {
656+
Assign(ref target, _) | AssignOp(_, ref target, _) | AddrOf(hir::Mutability::Mutable, ref target) => {
657657
self.mutates_static |= is_mutated_static(self.cx, target)
658658
},
659659
_ => {},

clippy_lints/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub mod strings;
274274
pub mod suspicious_trait_impl;
275275
pub mod swap;
276276
pub mod temporary_assignment;
277+
pub mod to_digit_is_some;
277278
pub mod trait_bounds;
278279
pub mod transmute;
279280
pub mod transmuting_null;
@@ -715,6 +716,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
715716
&swap::ALMOST_SWAPPED,
716717
&swap::MANUAL_SWAP,
717718
&temporary_assignment::TEMPORARY_ASSIGNMENT,
719+
&to_digit_is_some::TO_DIGIT_IS_SOME,
718720
&trait_bounds::TYPE_REPETITION_IN_BOUNDS,
719721
&transmute::CROSSPOINTER_TRANSMUTE,
720722
&transmute::TRANSMUTE_BYTES_TO_STR,
@@ -946,6 +948,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
946948
store.register_late_pass(|| box unused_self::UnusedSelf);
947949
store.register_late_pass(|| box mutable_debug_assertion::DebugAssertWithMutCall);
948950
store.register_late_pass(|| box exit::Exit);
951+
store.register_late_pass(|| box to_digit_is_some::ToDigitIsSome);
949952

950953
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
951954
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
@@ -1240,6 +1243,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
12401243
LintId::of(&swap::ALMOST_SWAPPED),
12411244
LintId::of(&swap::MANUAL_SWAP),
12421245
LintId::of(&temporary_assignment::TEMPORARY_ASSIGNMENT),
1246+
LintId::of(&to_digit_is_some::TO_DIGIT_IS_SOME),
12431247
LintId::of(&transmute::CROSSPOINTER_TRANSMUTE),
12441248
LintId::of(&transmute::TRANSMUTE_BYTES_TO_STR),
12451249
LintId::of(&transmute::TRANSMUTE_INT_TO_BOOL),
@@ -1365,6 +1369,7 @@ pub fn register_plugins(store: &mut lint::LintStore, sess: &Session, conf: &Conf
13651369
LintId::of(&returns::NEEDLESS_RETURN),
13661370
LintId::of(&returns::UNUSED_UNIT),
13671371
LintId::of(&strings::STRING_LIT_AS_BYTES),
1372+
LintId::of(&to_digit_is_some::TO_DIGIT_IS_SOME),
13681373
LintId::of(&try_err::TRY_ERR),
13691374
LintId::of(&types::FN_TO_NUMERIC_CAST),
13701375
LintId::of(&types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION),

clippy_lints/src/literal_representation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl LiteralDigitGrouping {
364364
if_chain! {
365365
if let Some(src) = snippet_opt(cx, lit.span);
366366
if let Some(firstch) = src.chars().next();
367-
if char::to_digit(firstch, 10).is_some();
367+
if char::is_digit(firstch, 10);
368368
then {
369369
let digit_info = DigitInfo::new(&src, false);
370370
let _ = Self::do_lint(digit_info.digits, digit_info.suffix, in_macro).map_err(|warning_type| {
@@ -378,7 +378,7 @@ impl LiteralDigitGrouping {
378378
if_chain! {
379379
if let Some(src) = snippet_opt(cx, lit.span);
380380
if let Some(firstch) = src.chars().next();
381-
if char::to_digit(firstch, 10).is_some();
381+
if char::is_digit(firstch, 10);
382382
then {
383383
let digit_info = DigitInfo::new(&src, true);
384384
// Separate digits into integral and fractional parts.
@@ -512,7 +512,7 @@ impl DecimalLiteralRepresentation {
512512
if let LitKind::Int(val, _) = lit.kind;
513513
if let Some(src) = snippet_opt(cx, lit.span);
514514
if let Some(firstch) = src.chars().next();
515-
if char::to_digit(firstch, 10).is_some();
515+
if char::is_digit(firstch, 10);
516516
let digit_info = DigitInfo::new(&src, false);
517517
if digit_info.radix == Radix::Decimal;
518518
if val >= u128::from(self.threshold);

clippy_lints/src/loops.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,8 +1506,8 @@ fn make_iterator_snippet(cx: &LateContext<'_, '_>, arg: &Expr, applic_ref: &mut
15061506
match &arg.kind {
15071507
ExprKind::AddrOf(mutability, arg_inner) if has_iter_method(cx, cx.tables.expr_ty(&arg_inner)).is_some() => {
15081508
let meth_name = match mutability {
1509-
MutMutable => "iter_mut",
1510-
MutImmutable => "iter",
1509+
Mutability::Mutable => "iter_mut",
1510+
Mutability::Immutable => "iter",
15111511
};
15121512
format!(
15131513
"{}.{}()",
@@ -1539,14 +1539,14 @@ fn check_for_loop_over_map_kv<'a, 'tcx>(
15391539
let (new_pat_span, kind, ty, mutbl) = match cx.tables.expr_ty(arg).kind {
15401540
ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) {
15411541
(key, _) if pat_is_wild(key, body) => (pat[1].span, "value", ty, mutbl),
1542-
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, MutImmutable),
1542+
(_, value) if pat_is_wild(value, body) => (pat[0].span, "key", ty, Mutability::Immutable),
15431543
_ => return,
15441544
},
15451545
_ => return,
15461546
};
15471547
let mutbl = match mutbl {
1548-
MutImmutable => "",
1549-
MutMutable => "_mut",
1548+
Mutability::Immutable => "",
1549+
Mutability::Mutable => "_mut",
15501550
};
15511551
let arg = match arg.kind {
15521552
ExprKind::AddrOf(_, ref expr) => &**expr,
@@ -1874,7 +1874,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18741874
self.visit_expr(rhs);
18751875
},
18761876
ExprKind::AddrOf(mutbl, ref expr) => {
1877-
if mutbl == MutMutable {
1877+
if mutbl == Mutability::Mutable {
18781878
self.prefer_mutable = true;
18791879
}
18801880
self.visit_expr(expr);
@@ -1885,7 +1885,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18851885
let ty = self.cx.tables.expr_ty_adjusted(expr);
18861886
self.prefer_mutable = false;
18871887
if let ty::Ref(_, _, mutbl) = ty.kind {
1888-
if mutbl == MutMutable {
1888+
if mutbl == Mutability::Mutable {
18891889
self.prefer_mutable = true;
18901890
}
18911891
}
@@ -1897,7 +1897,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18971897
for (ty, expr) in self.cx.tcx.fn_sig(def_id).inputs().skip_binder().iter().zip(args) {
18981898
self.prefer_mutable = false;
18991899
if let ty::Ref(_, _, mutbl) = ty.kind {
1900-
if mutbl == MutMutable {
1900+
if mutbl == Mutability::Mutable {
19011901
self.prefer_mutable = true;
19021902
}
19031903
}
@@ -1993,7 +1993,13 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr) -> bool {
19931993
fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'_, 'tcx>) -> bool {
19941994
// IntoIterator is currently only implemented for array sizes <= 32 in rustc
19951995
match ty.kind {
1996-
ty::Array(_, n) => (0..=32).contains(&n.eval_usize(cx.tcx, cx.param_env)),
1996+
ty::Array(_, n) => {
1997+
if let Some(val) = n.try_eval_usize(cx.tcx, cx.param_env) {
1998+
(0..=32).contains(&val)
1999+
} else {
2000+
false
2001+
}
2002+
},
19972003
_ => false,
19982004
}
19992005
}
@@ -2084,7 +2090,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
20842090
}
20852091
},
20862092
ExprKind::Assign(ref lhs, _) if lhs.hir_id == expr.hir_id => *state = VarState::DontWarn,
2087-
ExprKind::AddrOf(mutability, _) if mutability == MutMutable => *state = VarState::DontWarn,
2093+
ExprKind::AddrOf(mutability, _) if mutability == Mutability::Mutable => *state = VarState::DontWarn,
20882094
_ => (),
20892095
}
20902096
}
@@ -2166,7 +2172,9 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21662172
VarState::DontWarn
21672173
}
21682174
},
2169-
ExprKind::AddrOf(mutability, _) if mutability == MutMutable => self.state = VarState::DontWarn,
2175+
ExprKind::AddrOf(mutability, _) if mutability == Mutability::Mutable => {
2176+
self.state = VarState::DontWarn
2177+
},
21702178
_ => (),
21712179
}
21722180
}

clippy_lints/src/matches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn is_panic_block(block: &Block) -> bool {
570570
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
571571
if has_only_ref_pats(arms) {
572572
let mut suggs = Vec::new();
573-
let (title, msg) = if let ExprKind::AddrOf(Mutability::MutImmutable, ref inner) = ex.kind {
573+
let (title, msg) = if let ExprKind::AddrOf(Mutability::Immutable, ref inner) = ex.kind {
574574
let span = ex.span.source_callsite();
575575
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
576576
(

clippy_lints/src/mem_replace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::utils::{
22
match_def_path, match_qpath, paths, snippet_with_applicability, span_help_and_lint, span_lint_and_sugg,
33
};
44
use if_chain::if_chain;
5-
use rustc::hir::{Expr, ExprKind, MutMutable, QPath};
5+
use rustc::hir::{Expr, ExprKind, Mutability, QPath};
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
77
use rustc::{declare_lint_pass, declare_tool_lint};
88
use rustc_errors::Applicability;
@@ -90,7 +90,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MemReplace {
9090
// argument's type. All that's left is to get
9191
// replacee's path.
9292
let replaced_path = match func_args[0].kind {
93-
ExprKind::AddrOf(MutMutable, ref replaced) => {
93+
ExprKind::AddrOf(Mutability::Mutable, ref replaced) => {
9494
if let ExprKind::Path(QPath::Resolved(None, ref replaced_path)) = replaced.kind {
9595
replaced_path
9696
} else {

clippy_lints/src/methods/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,8 +2764,8 @@ fn ty_has_iter_method(cx: &LateContext<'_, '_>, self_ref_ty: Ty<'_>) -> Option<(
27642764
_ => unreachable!(),
27652765
};
27662766
let method_name = match mutbl {
2767-
hir::MutImmutable => "iter",
2768-
hir::MutMutable => "iter_mut",
2767+
hir::Mutability::Immutable => "iter",
2768+
hir::Mutability::Mutable => "iter_mut",
27692769
};
27702770
(ty_name, method_name)
27712771
})
@@ -2955,8 +2955,8 @@ impl SelfKind {
29552955
}
29562956

29572957
let trait_path = match mutability {
2958-
hir::Mutability::MutImmutable => &paths::ASREF_TRAIT,
2959-
hir::Mutability::MutMutable => &paths::ASMUT_TRAIT,
2958+
hir::Mutability::Immutable => &paths::ASREF_TRAIT,
2959+
hir::Mutability::Mutable => &paths::ASMUT_TRAIT,
29602960
};
29612961

29622962
let trait_def_id = match get_trait_def_id(cx, trait_path) {
@@ -2969,9 +2969,9 @@ impl SelfKind {
29692969
match self {
29702970
Self::Value => matches_value(parent_ty, ty),
29712971
Self::Ref => {
2972-
matches_ref(cx, hir::Mutability::MutImmutable, parent_ty, ty) || ty == parent_ty && is_copy(cx, ty)
2972+
matches_ref(cx, hir::Mutability::Immutable, parent_ty, ty) || ty == parent_ty && is_copy(cx, ty)
29732973
},
2974-
Self::RefMut => matches_ref(cx, hir::Mutability::MutMutable, parent_ty, ty),
2974+
Self::RefMut => matches_ref(cx, hir::Mutability::Mutable, parent_ty, ty),
29752975
Self::No => ty != parent_ty,
29762976
}
29772977
}

clippy_lints/src/misc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,8 @@ fn check_cast(cx: &LateContext<'_, '_>, span: Span, e: &Expr, ty: &Ty) {
627627
if !in_constant(cx, e.hir_id);
628628
then {
629629
let (msg, sugg_fn) = match mut_ty.mutbl {
630-
Mutability::MutMutable => ("`0 as *mut _` detected", "std::ptr::null_mut"),
631-
Mutability::MutImmutable => ("`0 as *const _` detected", "std::ptr::null"),
630+
Mutability::Mutable => ("`0 as *mut _` detected", "std::ptr::null_mut"),
631+
Mutability::Immutable => ("`0 as *const _` detected", "std::ptr::null"),
632632
};
633633

634634
let (sugg, appl) = if let TyKind::Infer = mut_ty.ty.kind {

0 commit comments

Comments
 (0)