From b3570db09486ebf1352f799678f08cc647988689 Mon Sep 17 00:00:00 2001 From: f001 Date: Sun, 12 Feb 2017 20:40:38 +0800 Subject: [PATCH] update via comments --- clippy_lints/src/methods.rs | 13 ++++++------- tests/ui/methods.rs | 3 +++ tests/ui/methods.stderr | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 916b62bf2b7..46bf23cc210 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -500,21 +500,21 @@ "using `x.extend(s.chars())` where s is a `&str` or `String`" } -/// **What it does:** Checks for the use of `.cloned().collect()` on slice to create a Vec. +/// **What it does:** Checks for the use of `.cloned().collect()` on slice to create a `Vec`. /// -/// **Why is this bad?** `.to_owned()` is clearer +/// **Why is this bad?** `.to_vec()` is clearer /// /// **Known problems:** None. /// /// **Example:** /// ```rust /// let s = [1,2,3,4,5]; -/// let s2 : Vec = s.iter().cloned().collect(); +/// let s2 : Vec = s[..].iter().cloned().collect(); /// ``` -/// The correct use would be: +/// The better use would be: /// ```rust /// let s = [1,2,3,4,5]; -/// let s2 : Vec = s.to_owned(); +/// let s2 : Vec = s.to_vec(); /// ``` declare_lint! { pub ITER_CLONED_COLLECT, @@ -908,8 +908,7 @@ fn lint_iter_cloned_collect(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir span_lint(cx, ITER_CLONED_COLLECT, expr.span, - "called `cloned().collect()` on a slice to create a `Vec`. This is more succinctly expressed by \ - calling `to_owned(x)`"); + "called `cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable"); } } diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs index 8eb4ff6870f..e1cd7ae38ea 100644 --- a/tests/ui/methods.rs +++ b/tests/ui/methods.rs @@ -693,4 +693,7 @@ fn temporary_cstring() { fn iter_clone_collect() { let v = [1,2,3,4,5]; let v2 : Vec = v.iter().cloned().collect(); + + let v3 : HashSet = v.iter().cloned().collect(); + let v4 : VecDeque = v.iter().cloned().collect(); } diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr index a62784e3302..da4f5c3f807 100644 --- a/tests/ui/methods.stderr +++ b/tests/ui/methods.stderr @@ -950,7 +950,7 @@ help: assign the `CString` to a variable to extend its lifetime 687 | CString::new("foo").unwrap().as_ptr(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -warning: called `cloned().collect()` on a slice to create a `Vec`. This is more succinctly expressed by calling `to_owned(x)` +warning: called `cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable --> $DIR/methods.rs:695:27 | 695 | let v2 : Vec = v.iter().cloned().collect(); -- 2.44.0