diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /src/tools/clippy/tests/ui/index_refutable_slice/if_let_slice_binding.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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.rs | 10 |
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]); } |