File tree Expand file tree Collapse file tree 3 files changed +69
-1
lines changed Expand file tree Collapse file tree 3 files changed +69
-1
lines changed Original file line number Diff line number Diff line change @@ -530,3 +530,25 @@ mod issue_11952 {
530
530
IntoFuture::into_future(foo([], &0));
531
531
}
532
532
}
533
+
534
+ fn borrow_checks() {
535
+ use std::collections::HashSet;
536
+
537
+ fn inner(a: &[&str]) {
538
+ let mut s = HashSet::from([vec!["a"]]);
539
+ s.remove(a); //~ ERROR: unnecessary use of `to_vec`
540
+ }
541
+
542
+ let mut s = HashSet::from(["a".to_string()]);
543
+ s.remove("b"); //~ ERROR: unnecessary use of `to_owned`
544
+ s.remove("b"); //~ ERROR: unnecessary use of `to_string`
545
+ // Should not warn.
546
+ s.remove("b");
547
+
548
+ let mut s = HashSet::from([vec!["a"]]);
549
+ s.remove(["b"].as_slice()); //~ ERROR: unnecessary use of `to_vec`
550
+
551
+ // Should not warn.
552
+ s.remove(&["b"].to_vec().clone());
553
+ s.remove(["a"].as_slice());
554
+ }
Original file line number Diff line number Diff line change @@ -530,3 +530,25 @@ mod issue_11952 {
530
530
IntoFuture :: into_future ( foo ( [ ] . to_vec ( ) , & 0 ) ) ;
531
531
}
532
532
}
533
+
534
+ fn borrow_checks ( ) {
535
+ use std:: collections:: HashSet ;
536
+
537
+ fn inner ( a : & [ & str ] ) {
538
+ let mut s = HashSet :: from ( [ vec ! [ "a" ] ] ) ;
539
+ s. remove ( & a. to_vec ( ) ) ; //~ ERROR: unnecessary use of `to_vec`
540
+ }
541
+
542
+ let mut s = HashSet :: from ( [ "a" . to_string ( ) ] ) ;
543
+ s. remove ( & "b" . to_owned ( ) ) ; //~ ERROR: unnecessary use of `to_owned`
544
+ s. remove ( & "b" . to_string ( ) ) ; //~ ERROR: unnecessary use of `to_string`
545
+ // Should not warn.
546
+ s. remove ( "b" ) ;
547
+
548
+ let mut s = HashSet :: from ( [ vec ! [ "a" ] ] ) ;
549
+ s. remove ( & [ "b" ] . to_vec ( ) ) ; //~ ERROR: unnecessary use of `to_vec`
550
+
551
+ // Should not warn.
552
+ s. remove ( & [ "b" ] . to_vec ( ) . clone ( ) ) ;
553
+ s. remove ( [ "a" ] . as_slice ( ) ) ;
554
+ }
Original file line number Diff line number Diff line change @@ -523,5 +523,29 @@ error: unnecessary use of `to_vec`
523
523
LL | IntoFuture::into_future(foo([].to_vec(), &0));
524
524
| ^^^^^^^^^^^ help: use: `[]`
525
525
526
- error: aborting due to 80 previous errors
526
+ error: unnecessary use of `to_vec`
527
+ --> tests/ui/unnecessary_to_owned.rs:539:18
528
+ |
529
+ LL | s.remove(&a.to_vec());
530
+ | ^^^^^^^^^^^ help: replace it with: `a`
531
+
532
+ error: unnecessary use of `to_owned`
533
+ --> tests/ui/unnecessary_to_owned.rs:543:14
534
+ |
535
+ LL | s.remove(&"b".to_owned());
536
+ | ^^^^^^^^^^^^^^^ help: replace it with: `"b"`
537
+
538
+ error: unnecessary use of `to_string`
539
+ --> tests/ui/unnecessary_to_owned.rs:544:14
540
+ |
541
+ LL | s.remove(&"b".to_string());
542
+ | ^^^^^^^^^^^^^^^^ help: replace it with: `"b"`
543
+
544
+ error: unnecessary use of `to_vec`
545
+ --> tests/ui/unnecessary_to_owned.rs:549:14
546
+ |
547
+ LL | s.remove(&["b"].to_vec());
548
+ | ^^^^^^^^^^^^^^^ help: replace it with: `["b"].as_slice()`
549
+
550
+ error: aborting due to 84 previous errors
527
551
You can’t perform that action at this time.
0 commit comments