]> git.lizzy.rs Git - rust.git/commitdiff
update via comments
authorf001 <changchun.fan@qq.com>
Sun, 12 Feb 2017 12:40:38 +0000 (20:40 +0800)
committerf001 <changchun.fan@qq.com>
Sun, 12 Feb 2017 12:40:38 +0000 (20:40 +0800)
clippy_lints/src/methods.rs
tests/ui/methods.rs
tests/ui/methods.stderr

index 916b62bf2b74589f15b80752795ec597b630ae5a..46bf23cc21053889da189a8c29780bb445c252a1 100644 (file)
     "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<isize> = s.iter().cloned().collect();
+/// let s2 : Vec<isize> = 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<isize> = s.to_owned();
+/// let s2 : Vec<isize> = 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");
     }
 }
 
index 8eb4ff6870f78d2a81a2b659a759dd89cdc300ff..e1cd7ae38ea49a89ba47b27beff6e94819a7e8a7 100644 (file)
@@ -693,4 +693,7 @@ fn temporary_cstring() {
 fn iter_clone_collect() {
     let v = [1,2,3,4,5];
     let v2 : Vec<isize> = v.iter().cloned().collect();
+
+    let v3 : HashSet<isize> = v.iter().cloned().collect();
+    let v4 : VecDeque<isize> = v.iter().cloned().collect();
 }
index a62784e3302b638700aed0d8c08fcbd7ff5f0f17..da4f5c3f8074efa6dab42d9b0d90e1c077bed6ee 100644 (file)
@@ -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<isize> = v.iter().cloned().collect();