Skip to content

Commit d37ee6f

Browse files
committed
Fix lint errors
1 parent 9427e03 commit d37ee6f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

clippy_lints/src/vec_init_then_push.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
77
use rustc_middle::lint::in_external_macro;
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
99
use rustc_span::{symbol::sym, Span, Symbol};
10+
use std::convert::TryInto;
1011

1112
declare_clippy_lint! {
1213
/// **What it does:** Checks for calls to `push` immediately after creating a new `Vec`.
@@ -92,7 +93,7 @@ impl LateLintPass<'_> for VecInitThenPush {
9293
init: init_kind,
9394
name: ident.name,
9495
lhs_is_local: true,
95-
lhs_span: local.ty.map(|t| local.pat.span.to(t.span)).unwrap_or(local.pat.span),
96+
lhs_span: local.ty.map_or(local.pat.span, |t| local.pat.span.to(t.span)),
9697
err_span: local.span,
9798
found: 0,
9899
});
@@ -165,7 +166,7 @@ fn get_vec_init_kind<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Op
165166
if let ExprKind::Lit(lit) = &arg.kind;
166167
if let LitKind::Int(num, _) = lit.node;
167168
then {
168-
Some(VecInitKind::WithCapacity(num as u64))
169+
Some(VecInitKind::WithCapacity(num.try_into().ok()?))
169170
} else {
170171
None
171172
}

0 commit comments

Comments
 (0)