summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs')
-rw-r--r--src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs
index 0a3374d11..d8d38c167 100644
--- a/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs
+++ b/src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs
@@ -12,18 +12,21 @@ fn lintable_examples() {
// Try with reference
let slice: Option<&[u32]> = Some(&[1, 2, 3]);
if let Some(slice) = slice {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
println!("{}", slice[0]);
}
// Try with copy
let slice: Option<[u32; 3]> = Some([1, 2, 3]);
if let Some(slice) = slice {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
println!("{}", slice[0]);
}
// Try with long slice and small indices
let slice: Option<[u32; 9]> = Some([1, 2, 3, 4, 5, 6, 7, 8, 9]);
if let Some(slice) = slice {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
println!("{}", slice[2]);
println!("{}", slice[0]);
}
@@ -31,6 +34,7 @@ fn lintable_examples() {
// Multiple bindings
let slice_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([5, 6, 7]);
if let SomeEnum::One(slice) | SomeEnum::Three(slice) = slice_wrapped {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
println!("{}", slice[0]);
}
@@ -38,6 +42,8 @@ fn lintable_examples() {
let a_wrapped: SomeEnum<[u32; 3]> = SomeEnum::One([9, 5, 1]);
let b_wrapped: Option<[u32; 2]> = Some([4, 6]);
if let (SomeEnum::Three(a), Some(b)) = (a_wrapped, b_wrapped) {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
+ //~| ERROR: this binding can be a slice pattern to avoid indexing
println!("{} -> {}", a[2], b[1]);
}
@@ -45,6 +51,7 @@ fn lintable_examples() {
// borrowed and `String` doesn't implement copy
let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]);
if let Some(ref slice) = slice {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
println!("{:?}", slice[1]);
}
println!("{:?}", slice);
@@ -53,6 +60,7 @@ fn lintable_examples() {
// a reference
let slice: Option<[String; 2]> = Some([String::from("1"), String::from("2")]);
if let Some(slice) = &slice {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
println!("{:?}", slice[0]);
}
println!("{:?}", slice);
@@ -122,6 +130,7 @@ fn check_slice_in_struct() {
// Test 1: Field access
if let Some(slice) = wrap.inner {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
if wrap.is_awesome {
println!("This is awesome! {}", slice[0]);
}
@@ -129,6 +138,7 @@ fn check_slice_in_struct() {
// Test 2: function access
if let Some(slice) = wrap.inner {
+ //~^ ERROR: this binding can be a slice pattern to avoid indexing
if wrap.is_super_awesome() {
println!("This is super awesome! {}", slice[0]);
}