update via comments

This commit is contained in:
f001 2017-02-12 20:40:38 +08:00
parent 5a039f68f7
commit b3570db094
3 changed files with 10 additions and 8 deletions

View File

@ -500,21 +500,21 @@ declare_lint! {
"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");
}
}

View 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();
}

View 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();