about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2021-01-02 14:31:21 -0500
committerJason Newcomb <jsnewcomb@pm.me>2021-01-02 14:31:21 -0500
commitd37ee6ffa0642a0812cbda4592be6650aa4eda08 (patch)
treece552b136bc566a0f320e6dd555017226e0a234d
parent9427e0356beab35222ba3cbdf394b4c9198880ba (diff)
downloadrust-d37ee6ffa0642a0812cbda4592be6650aa4eda08.tar.gz
rust-d37ee6ffa0642a0812cbda4592be6650aa4eda08.zip
Fix lint errors
-rw-r--r--clippy_lints/src/vec_init_then_push.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs
index 0aadb453444..e2cbcc9108c 100644
--- a/clippy_lints/src/vec_init_then_push.rs
+++ b/clippy_lints/src/vec_init_then_push.rs
@@ -7,6 +7,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
 use rustc_middle::lint::in_external_macro;
 use rustc_session::{declare_tool_lint, impl_lint_pass};
 use rustc_span::{symbol::sym, Span, Symbol};
+use std::convert::TryInto;
 
 declare_clippy_lint! {
     /// **What it does:** Checks for calls to `push` immediately after creating a new `Vec`.
@@ -92,7 +93,7 @@ impl LateLintPass<'_> for VecInitThenPush {
                         init: init_kind,
                         name: ident.name,
                         lhs_is_local: true,
-                        lhs_span: local.ty.map(|t| local.pat.span.to(t.span)).unwrap_or(local.pat.span),
+                        lhs_span: local.ty.map_or(local.pat.span, |t| local.pat.span.to(t.span)),
                         err_span: local.span,
                         found: 0,
                     });
@@ -165,7 +166,7 @@ fn get_vec_init_kind<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Op
                             if let ExprKind::Lit(lit) = &arg.kind;
                             if let LitKind::Int(num, _) = lit.node;
                             then {
-                                Some(VecInitKind::WithCapacity(num as u64))
+                                Some(VecInitKind::WithCapacity(num.try_into().ok()?))
                             } else {
                                 None
                             }