Skip to content

Commit b3570db

Browse files
committed
update via comments
1 parent 5a039f6 commit b3570db

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

clippy_lints/src/methods.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,21 +500,21 @@ declare_lint! {
500500
"using `x.extend(s.chars())` where s is a `&str` or `String`"
501501
}
502502

503-
/// **What it does:** Checks for the use of `.cloned().collect()` on slice to create a Vec.
503+
/// **What it does:** Checks for the use of `.cloned().collect()` on slice to create a `Vec`.
504504
///
505-
/// **Why is this bad?** `.to_owned()` is clearer
505+
/// **Why is this bad?** `.to_vec()` is clearer
506506
///
507507
/// **Known problems:** None.
508508
///
509509
/// **Example:**
510510
/// ```rust
511511
/// let s = [1,2,3,4,5];
512-
/// let s2 : Vec<isize> = s.iter().cloned().collect();
512+
/// let s2 : Vec<isize> = s[..].iter().cloned().collect();
513513
/// ```
514-
/// The correct use would be:
514+
/// The better use would be:
515515
/// ```rust
516516
/// let s = [1,2,3,4,5];
517-
/// let s2 : Vec<isize> = s.to_owned();
517+
/// let s2 : Vec<isize> = s.to_vec();
518518
/// ```
519519
declare_lint! {
520520
pub ITER_CLONED_COLLECT,
@@ -908,8 +908,7 @@ fn lint_iter_cloned_collect(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir
908908
span_lint(cx,
909909
ITER_CLONED_COLLECT,
910910
expr.span,
911-
"called `cloned().collect()` on a slice to create a `Vec`. This is more succinctly expressed by \
912-
calling `to_owned(x)`");
911+
"called `cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable");
913912
}
914913
}
915914

tests/ui/methods.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,7 @@ fn temporary_cstring() {
693693
fn iter_clone_collect() {
694694
let v = [1,2,3,4,5];
695695
let v2 : Vec<isize> = v.iter().cloned().collect();
696+
697+
let v3 : HashSet<isize> = v.iter().cloned().collect();
698+
let v4 : VecDeque<isize> = v.iter().cloned().collect();
696699
}

tests/ui/methods.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ help: assign the `CString` to a variable to extend its lifetime
950950
687 | CString::new("foo").unwrap().as_ptr();
951951
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
952952

953-
warning: called `cloned().collect()` on a slice to create a `Vec`. This is more succinctly expressed by calling `to_owned(x)`
953+
warning: called `cloned().collect()` on a slice to create a `Vec`. Calling `to_vec()` is both faster and more readable
954954
--> $DIR/methods.rs:695:27
955955
|
956956
695 | let v2 : Vec<isize> = v.iter().cloned().collect();

0 commit comments

Comments
 (0)