mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-19 11:12:43 +00:00
Auto merge of #95274 - jendrikw:slice-must-use, r=Dylan-DPC
add #[must_use] to functions of slice and its iterators. Continuation of #92853. Tracking issue: #89692.
This commit is contained in:
commit
a7da8a6019
@ -5,7 +5,7 @@
|
||||
|
||||
fn main() {
|
||||
let s = String::from("String");
|
||||
s.as_bytes().get(3);
|
||||
let _ = s.as_bytes().get(3);
|
||||
let _ = &s.as_bytes().get(3);
|
||||
s[..].as_bytes().get(3);
|
||||
let _ = s[..].as_bytes().get(3);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
fn main() {
|
||||
let s = String::from("String");
|
||||
s.bytes().nth(3);
|
||||
let _ = s.bytes().nth(3);
|
||||
let _ = &s.bytes().nth(3);
|
||||
s[..].bytes().nth(3);
|
||||
let _ = s[..].bytes().nth(3);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error: called `.byte().nth()` on a `String`
|
||||
--> $DIR/bytes_nth.rs:8:5
|
||||
--> $DIR/bytes_nth.rs:8:13
|
||||
|
|
||||
LL | s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
LL | let _ = s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
|
|
||||
= note: `-D clippy::bytes-nth` implied by `-D warnings`
|
||||
|
||||
@ -13,10 +13,10 @@ LL | let _ = &s.bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `s.as_bytes().get(3)`
|
||||
|
||||
error: called `.byte().nth()` on a `str`
|
||||
--> $DIR/bytes_nth.rs:10:5
|
||||
--> $DIR/bytes_nth.rs:10:13
|
||||
|
|
||||
LL | s[..].bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
|
||||
LL | let _ = s[..].bytes().nth(3);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `s[..].as_bytes().get(3)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -6,16 +6,16 @@ fn main() {
|
||||
let s = [1, 2, 3];
|
||||
let v = vec![1, 2, 3];
|
||||
|
||||
s.get(0);
|
||||
let _ = s.get(0);
|
||||
// Should be replaced by s.get(0)
|
||||
|
||||
s.get(2);
|
||||
let _ = s.get(2);
|
||||
// Should be replaced by s.get(2)
|
||||
|
||||
v.get(5);
|
||||
let _ = v.get(5);
|
||||
// Should be replaced by v.get(5)
|
||||
|
||||
v.get(0);
|
||||
let _ = v.get(0);
|
||||
// Should be replaced by v.get(0)
|
||||
|
||||
let o = Some(5);
|
||||
|
@ -6,16 +6,16 @@ fn main() {
|
||||
let s = [1, 2, 3];
|
||||
let v = vec![1, 2, 3];
|
||||
|
||||
s.iter().next();
|
||||
let _ = s.iter().next();
|
||||
// Should be replaced by s.get(0)
|
||||
|
||||
s[2..].iter().next();
|
||||
let _ = s[2..].iter().next();
|
||||
// Should be replaced by s.get(2)
|
||||
|
||||
v[5..].iter().next();
|
||||
let _ = v[5..].iter().next();
|
||||
// Should be replaced by v.get(5)
|
||||
|
||||
v.iter().next();
|
||||
let _ = v.iter().next();
|
||||
// Should be replaced by v.get(0)
|
||||
|
||||
let o = Some(5);
|
||||
|
@ -1,28 +1,28 @@
|
||||
error: using `.iter().next()` on an array
|
||||
--> $DIR/iter_next_slice.rs:9:5
|
||||
--> $DIR/iter_next_slice.rs:9:13
|
||||
|
|
||||
LL | s.iter().next();
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `s.get(0)`
|
||||
LL | let _ = s.iter().next();
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `s.get(0)`
|
||||
|
|
||||
= note: `-D clippy::iter-next-slice` implied by `-D warnings`
|
||||
|
||||
error: using `.iter().next()` on a Slice without end index
|
||||
--> $DIR/iter_next_slice.rs:12:5
|
||||
--> $DIR/iter_next_slice.rs:12:13
|
||||
|
|
||||
LL | s[2..].iter().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)`
|
||||
LL | let _ = s[2..].iter().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `s.get(2)`
|
||||
|
||||
error: using `.iter().next()` on a Slice without end index
|
||||
--> $DIR/iter_next_slice.rs:15:5
|
||||
--> $DIR/iter_next_slice.rs:15:13
|
||||
|
|
||||
LL | v[5..].iter().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)`
|
||||
LL | let _ = v[5..].iter().next();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try calling: `v.get(5)`
|
||||
|
||||
error: using `.iter().next()` on an array
|
||||
--> $DIR/iter_next_slice.rs:18:5
|
||||
--> $DIR/iter_next_slice.rs:18:13
|
||||
|
|
||||
LL | v.iter().next();
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)`
|
||||
LL | let _ = v.iter().next();
|
||||
| ^^^^^^^^^^^^^^^ help: try calling: `v.get(0)`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user