Skip to content

Commit 2468c61

Browse files
Silence unused borrows warning in unit tests
1 parent 4f8b259 commit 2468c61

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

library/alloc/tests/str.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ mod slice_index {
504504
#[test]
505505
#[should_panic]
506506
fn test_slice_fail() {
507-
&"中华Việt Nam"[0..2];
507+
let _ = &"中华Việt Nam"[0..2];
508508
}
509509

510510
panic_cases! {
@@ -655,13 +655,13 @@ mod slice_index {
655655
#[test]
656656
#[should_panic(expected = "byte index 1024 is out of bounds of `Lorem ipsum dolor sit amet")]
657657
fn test_slice_fail_truncated_1() {
658-
&LOREM_PARAGRAPH[..1024];
658+
let _ = &LOREM_PARAGRAPH[..1024];
659659
}
660660
// check the truncation in the panic message
661661
#[test]
662662
#[should_panic(expected = "luctus, im`[...]")]
663663
fn test_slice_fail_truncated_2() {
664-
&LOREM_PARAGRAPH[..1024];
664+
let _ = &LOREM_PARAGRAPH[..1024];
665665
}
666666
}
667667

@@ -676,7 +676,7 @@ fn test_str_slice_rangetoinclusive_ok() {
676676
#[should_panic]
677677
fn test_str_slice_rangetoinclusive_notok() {
678678
let s = "abcαβγ";
679-
&s[..=3];
679+
let _ = &s[..=3];
680680
}
681681

682682
#[test]
@@ -692,7 +692,7 @@ fn test_str_slicemut_rangetoinclusive_ok() {
692692
fn test_str_slicemut_rangetoinclusive_notok() {
693693
let mut s = "abcαβγ".to_owned();
694694
let s: &mut str = &mut s;
695-
&mut s[..=3];
695+
let _ = &mut s[..=3];
696696
}
697697

698698
#[test]

library/alloc/tests/vec.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -478,35 +478,35 @@ fn test_index_out_of_bounds() {
478478
#[should_panic]
479479
fn test_slice_out_of_bounds_1() {
480480
let x = vec![1, 2, 3, 4, 5];
481-
&x[!0..];
481+
let _ = &x[!0..];
482482
}
483483

484484
#[test]
485485
#[should_panic]
486486
fn test_slice_out_of_bounds_2() {
487487
let x = vec![1, 2, 3, 4, 5];
488-
&x[..6];
488+
let _ = &x[..6];
489489
}
490490

491491
#[test]
492492
#[should_panic]
493493
fn test_slice_out_of_bounds_3() {
494494
let x = vec![1, 2, 3, 4, 5];
495-
&x[!0..4];
495+
let _ = &x[!0..4];
496496
}
497497

498498
#[test]
499499
#[should_panic]
500500
fn test_slice_out_of_bounds_4() {
501501
let x = vec![1, 2, 3, 4, 5];
502-
&x[1..6];
502+
let _ = &x[1..6];
503503
}
504504

505505
#[test]
506506
#[should_panic]
507507
fn test_slice_out_of_bounds_5() {
508508
let x = vec![1, 2, 3, 4, 5];
509-
&x[3..2];
509+
let _ = &x[3..2];
510510
}
511511

512512
#[test]

library/std/src/sys_common/wtf8/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn wtf8_slice() {
301301
#[test]
302302
#[should_panic]
303303
fn wtf8_slice_not_code_point_boundary() {
304-
&Wtf8::from_str("aé 💩")[2..4];
304+
let _ = &Wtf8::from_str("aé 💩")[2..4];
305305
}
306306

307307
#[test]
@@ -312,18 +312,18 @@ fn wtf8_slice_from() {
312312
#[test]
313313
#[should_panic]
314314
fn wtf8_slice_from_not_code_point_boundary() {
315-
&Wtf8::from_str("aé 💩")[2..];
315+
let _ = &Wtf8::from_str("aé 💩")[2..];
316316
}
317317

318318
#[test]
319319
fn wtf8_slice_to() {
320-
assert_eq!(&Wtf8::from_str("aé 💩")[..4].bytes, b"a\xC3\xA9 ");
320+
let _ = assert_eq!(&Wtf8::from_str("aé 💩")[..4].bytes, b"a\xC3\xA9 ");
321321
}
322322

323323
#[test]
324324
#[should_panic]
325325
fn wtf8_slice_to_not_code_point_boundary() {
326-
&Wtf8::from_str("aé 💩")[5..];
326+
let _ = &Wtf8::from_str("aé 💩")[5..];
327327
}
328328

329329
#[test]

0 commit comments

Comments
 (0)