Skip to content

Commit d5d300c

Browse files
committed
Update tests
1 parent 81f5c69 commit d5d300c

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

tests/ui/methods.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,33 @@ fn iter_clone_collect() {
547547
let v3 : HashSet<isize> = v.iter().cloned().collect();
548548
let v4 : VecDeque<isize> = v.iter().cloned().collect();
549549
}
550+
551+
fn chars_cmp_with_unwrap() {
552+
let s = String::from("foo");
553+
if s.chars().next().unwrap() == 'f' { // s.starts_with('f')
554+
// Nothing here
555+
}
556+
if s.chars().next_back().unwrap() == 'o' { // s.ends_with('o')
557+
// Nothing here
558+
}
559+
if s.chars().last().unwrap() == 'o' { // s.ends_with('o')
560+
// Nothing here
561+
}
562+
if s.chars().next().unwrap() != 'f' { // !s.starts_with('f')
563+
// Nothing here
564+
}
565+
if s.chars().next_back().unwrap() != 'o' { // !s.ends_with('o')
566+
// Nothing here
567+
}
568+
if s.chars().last().unwrap() != 'o' { // !s.ends_with('o')
569+
// Nothing here
570+
}
571+
}
572+
573+
#[allow(unnecessary_operation)]
574+
fn ends_with() {
575+
"".chars().last() == Some(' ');
576+
Some(' ') != "".chars().last();
577+
"".chars().next_back() == Some(' ');
578+
Some(' ') != "".chars().next_back();
579+
}

tests/ui/methods.stderr

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,5 +738,103 @@ error: called `cloned().collect()` on a slice to create a `Vec`. Calling `to_vec
738738
|
739739
= note: `-D iter-cloned-collect` implied by `-D warnings`
740740

741-
error: aborting due to 107 previous errors
741+
error: you should use the `starts_with` method
742+
--> $DIR/methods.rs:553:8
743+
|
744+
553 | if s.chars().next().unwrap() == 'f' { // s.starts_with('f')
745+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.starts_with('f')`
746+
747+
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
748+
--> $DIR/methods.rs:553:8
749+
|
750+
553 | if s.chars().next().unwrap() == 'f' { // s.starts_with('f')
751+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
752+
753+
error: you should use the `ends_with` method
754+
--> $DIR/methods.rs:556:8
755+
|
756+
556 | if s.chars().next_back().unwrap() == 'o' { // s.ends_with('o')
757+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')`
758+
|
759+
= note: `-D chars-last-cmp` implied by `-D warnings`
760+
761+
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
762+
--> $DIR/methods.rs:556:8
763+
|
764+
556 | if s.chars().next_back().unwrap() == 'o' { // s.ends_with('o')
765+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
766+
767+
error: you should use the `ends_with` method
768+
--> $DIR/methods.rs:559:8
769+
|
770+
559 | if s.chars().last().unwrap() == 'o' { // s.ends_with('o')
771+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `s.ends_with('o')`
772+
773+
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
774+
--> $DIR/methods.rs:559:8
775+
|
776+
559 | if s.chars().last().unwrap() == 'o' { // s.ends_with('o')
777+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
778+
779+
error: you should use the `starts_with` method
780+
--> $DIR/methods.rs:562:8
781+
|
782+
562 | if s.chars().next().unwrap() != 'f' { // !s.starts_with('f')
783+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.starts_with('f')`
784+
785+
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
786+
--> $DIR/methods.rs:562:8
787+
|
788+
562 | if s.chars().next().unwrap() != 'f' { // !s.starts_with('f')
789+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
790+
791+
error: you should use the `ends_with` method
792+
--> $DIR/methods.rs:565:8
793+
|
794+
565 | if s.chars().next_back().unwrap() != 'o' { // !s.ends_with('o')
795+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')`
796+
797+
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
798+
--> $DIR/methods.rs:565:8
799+
|
800+
565 | if s.chars().next_back().unwrap() != 'o' { // !s.ends_with('o')
801+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
802+
803+
error: you should use the `ends_with` method
804+
--> $DIR/methods.rs:568:8
805+
|
806+
568 | if s.chars().last().unwrap() != 'o' { // !s.ends_with('o')
807+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!s.ends_with('o')`
808+
809+
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
810+
--> $DIR/methods.rs:568:8
811+
|
812+
568 | if s.chars().last().unwrap() != 'o' { // !s.ends_with('o')
813+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
814+
815+
error: you should use the `ends_with` method
816+
--> $DIR/methods.rs:575:5
817+
|
818+
575 | "".chars().last() == Some(' ');
819+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')`
820+
821+
error: you should use the `ends_with` method
822+
--> $DIR/methods.rs:576:5
823+
|
824+
576 | Some(' ') != "".chars().last();
825+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')`
826+
827+
error: you should use the `ends_with` method
828+
--> $DIR/methods.rs:577:5
829+
|
830+
577 | "".chars().next_back() == Some(' ');
831+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `"".ends_with(' ')`
832+
833+
error: you should use the `ends_with` method
834+
--> $DIR/methods.rs:578:5
835+
|
836+
578 | Some(' ') != "".chars().next_back();
837+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: like this: `!"".ends_with(' ')`
838+
839+
error: aborting due to 123 previous errors
742840

0 commit comments

Comments
 (0)