summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui-toml/unwrap_used
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:21 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:21 +0000
commit4e8199b572f2035b7749cba276ece3a26630d23e (patch)
treef09feeed6a0fe39d027b1908aa63ea6b35e4b631 /src/tools/clippy/tests/ui-toml/unwrap_used
parentAdding upstream version 1.66.0+dfsg1. (diff)
downloadrustc-4e8199b572f2035b7749cba276ece3a26630d23e.tar.xz
rustc-4e8199b572f2035b7749cba276ece3a26630d23e.zip
Adding upstream version 1.67.1+dfsg1.upstream/1.67.1+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui-toml/unwrap_used')
-rw-r--r--src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs21
-rw-r--r--src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr32
2 files changed, 33 insertions, 20 deletions
diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs
index 0e82fb20e..bc8e8c1f0 100644
--- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs
+++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.rs
@@ -66,8 +66,21 @@ fn main() {
}
}
-#[test]
-fn test() {
- let boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
- let _ = boxed_slice.get(1).unwrap();
+#[cfg(test)]
+mod issue9612 {
+ // should not lint in `#[cfg(test)]` modules
+ #[test]
+ fn test_fn() {
+ let _a: u8 = 2.try_into().unwrap();
+ let _a: u8 = 3.try_into().expect("");
+
+ util();
+ }
+
+ fn util() {
+ let _a: u8 = 4.try_into().unwrap();
+ let _a: u8 = 5.try_into().expect("");
+ // should still warn
+ let _ = Box::new([0]).get(1).unwrap();
+ }
}
diff --git a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
index 681b5eaf5..94b5ef663 100644
--- a/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
+++ b/src/tools/clippy/tests/ui-toml/unwrap_used/unwrap_used.stderr
@@ -10,7 +10,7 @@ note: the lint level is defined here
LL | #![deny(clippy::get_unwrap)]
| ^^^^^^^^^^^^^^^^^^
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:35:17
|
LL | let _ = boxed_slice.get(1).unwrap();
@@ -25,7 +25,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _ = some_slice.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_slice[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:36:17
|
LL | let _ = some_slice.get(0).unwrap();
@@ -39,7 +39,7 @@ error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more conc
LL | let _ = some_vec.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vec[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:37:17
|
LL | let _ = some_vec.get(0).unwrap();
@@ -53,7 +53,7 @@ error: called `.get().unwrap()` on a VecDeque. Using `[]` is more clear and more
LL | let _ = some_vecdeque.get(0).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_vecdeque[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:38:17
|
LL | let _ = some_vecdeque.get(0).unwrap();
@@ -67,7 +67,7 @@ error: called `.get().unwrap()` on a HashMap. Using `[]` is more clear and more
LL | let _ = some_hashmap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_hashmap[&1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:39:17
|
LL | let _ = some_hashmap.get(&1).unwrap();
@@ -81,7 +81,7 @@ error: called `.get().unwrap()` on a BTreeMap. Using `[]` is more clear and more
LL | let _ = some_btreemap.get(&1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&some_btreemap[&1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:40:17
|
LL | let _ = some_btreemap.get(&1).unwrap();
@@ -95,7 +95,7 @@ error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more co
LL | let _: u8 = *boxed_slice.get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:44:22
|
LL | let _: u8 = *boxed_slice.get(1).unwrap();
@@ -109,7 +109,7 @@ error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and mor
LL | *boxed_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `boxed_slice[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:49:10
|
LL | *boxed_slice.get_mut(0).unwrap() = 1;
@@ -123,7 +123,7 @@ error: called `.get_mut().unwrap()` on a slice. Using `[]` is more clear and mor
LL | *some_slice.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_slice[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:50:10
|
LL | *some_slice.get_mut(0).unwrap() = 1;
@@ -137,7 +137,7 @@ error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more
LL | *some_vec.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:51:10
|
LL | *some_vec.get_mut(0).unwrap() = 1;
@@ -151,7 +151,7 @@ error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vecdeque[0]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:52:10
|
LL | *some_vecdeque.get_mut(0).unwrap() = 1;
@@ -165,7 +165,7 @@ error: called `.get().unwrap()` on a Vec. Using `[]` is more clear and more conc
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:64:17
|
LL | let _ = some_vec.get(0..1).unwrap().to_vec();
@@ -179,7 +179,7 @@ error: called `.get_mut().unwrap()` on a Vec. Using `[]` is more clear and more
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `some_vec[0..1]`
-error: used `unwrap()` on `an Option` value
+error: used `unwrap()` on an `Option` value
--> $DIR/unwrap_used.rs:65:17
|
LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
@@ -188,10 +188,10 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
= help: if you don't want to handle the `None` case gracefully, consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a slice. Using `[]` is more clear and more concise
- --> $DIR/unwrap_used.rs:72:13
+ --> $DIR/unwrap_used.rs:84:17
|
-LL | let _ = boxed_slice.get(1).unwrap();
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&boxed_slice[1]`
+LL | let _ = Box::new([0]).get(1).unwrap();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&Box::new([0])[1]`
error: aborting due to 27 previous errors