update via comments
This commit is contained in:
parent
5a039f68f7
commit
b3570db094
@ -500,21 +500,21 @@ declare_lint! {
|
|||||||
"using `x.extend(s.chars())` where s is a `&str` or `String`"
|
"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.
|
/// **Known problems:** None.
|
||||||
///
|
///
|
||||||
/// **Example:**
|
/// **Example:**
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// let s = [1,2,3,4,5];
|
/// 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
|
/// ```rust
|
||||||
/// let s = [1,2,3,4,5];
|
/// let s = [1,2,3,4,5];
|
||||||
/// let s2 : Vec<isize> = s.to_owned();
|
/// let s2 : Vec<isize> = s.to_vec();
|
||||||
/// ```
|
/// ```
|
||||||
declare_lint! {
|
declare_lint! {
|
||||||
pub ITER_CLONED_COLLECT,
|
pub ITER_CLONED_COLLECT,
|
||||||
@ -908,8 +908,7 @@ fn lint_iter_cloned_collect(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir
|
|||||||
span_lint(cx,
|
span_lint(cx,
|
||||||
ITER_CLONED_COLLECT,
|
ITER_CLONED_COLLECT,
|
||||||
expr.span,
|
expr.span,
|
||||||
"called `cloned().collect()` on a slice to create a `Vec`. This is more succinctly expressed by \
|
"called `cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable");
|
||||||
calling `to_owned(x)`");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,4 +693,7 @@ fn temporary_cstring() {
|
|||||||
fn iter_clone_collect() {
|
fn iter_clone_collect() {
|
||||||
let v = [1,2,3,4,5];
|
let v = [1,2,3,4,5];
|
||||||
let v2 : Vec<isize> = v.iter().cloned().collect();
|
let v2 : Vec<isize> = v.iter().cloned().collect();
|
||||||
|
|
||||||
|
let v3 : HashSet<isize> = v.iter().cloned().collect();
|
||||||
|
let v4 : VecDeque<isize> = v.iter().cloned().collect();
|
||||||
}
|
}
|
||||||
|
@ -950,7 +950,7 @@ help: assign the `CString` to a variable to extend its lifetime
|
|||||||
687 | CString::new("foo").unwrap().as_ptr();
|
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
|
--> $DIR/methods.rs:695:27
|
||||||
|
|
|
|
||||||
695 | let v2 : Vec<isize> = v.iter().cloned().collect();
|
695 | let v2 : Vec<isize> = v.iter().cloned().collect();
|
||||||
|
Loading…
Reference in New Issue
Block a user