Skip to content

Commit 0ab7e6c

Browse files
Factor out lint_vec_extend
1 parent 276e85b commit 0ab7e6c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

clippy_lints/src/methods.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t
794794
}
795795
}
796796

797-
fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
798-
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.tables().expr_ty(&args[0]));
799-
if !match_type(cx, obj_ty, &paths::VEC) {
800-
return;
801-
}
797+
fn lint_vec_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
802798
let arg_ty = cx.tcx.tables().expr_ty(&args[1]);
803799
if let Some(slice) = derefs_to_slice(cx, &args[1], arg_ty) {
804800
span_lint_and_then(cx, EXTEND_FROM_SLICE, expr.span, "use of `extend` to extend a Vec by a slice", |db| {
@@ -811,6 +807,13 @@ fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
811807
}
812808
}
813809

810+
fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
811+
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.tables().expr_ty(&args[0]));
812+
if match_type(cx, obj_ty, &paths::VEC) {
813+
lint_vec_extend(cx, expr, args);
814+
}
815+
}
816+
814817
fn lint_cstring_as_ptr(cx: &LateContext, expr: &hir::Expr, new: &hir::Expr, unwrap: &hir::Expr) {
815818
if_let_chain!{[
816819
let hir::ExprCall(ref fun, ref args) = new.node,

0 commit comments

Comments
 (0)