Rollup merge of #129517 - cjgillot:known-panic-array, r=pnkfelix
Compute array length from type for unconditional panic lint. Fixes https://github.com/rust-lang/rust/issues/98444 The cases that involve slicing are harder, so https://github.com/rust-lang/rust/issues/38035 remains open.
This commit is contained in:
commit
7bac9cd747
@ -86,6 +86,7 @@ mod issue9612 {
|
|||||||
util();
|
util();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unconditional_panic)]
|
||||||
fn util() {
|
fn util() {
|
||||||
let _a: u8 = 4.try_into().unwrap();
|
let _a: u8 = 4.try_into().unwrap();
|
||||||
let _a: u8 = 5.try_into().expect("");
|
let _a: u8 = 5.try_into().expect("");
|
||||||
|
@ -86,6 +86,7 @@ fn test_fn() {
|
|||||||
util();
|
util();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unconditional_panic)]
|
||||||
fn util() {
|
fn util() {
|
||||||
let _a: u8 = 4.try_into().unwrap();
|
let _a: u8 = 4.try_into().unwrap();
|
||||||
let _a: u8 = 5.try_into().expect("");
|
let _a: u8 = 5.try_into().expect("");
|
||||||
|
@ -274,7 +274,7 @@ LL | let _ = &boxed_slice[1];
|
|||||||
| ~~~~~~~~~~~~~~~
|
| ~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: called `.get().unwrap()` on a slice
|
error: called `.get().unwrap()` on a slice
|
||||||
--> tests/ui-toml/unwrap_used/unwrap_used.rs:93:17
|
--> tests/ui-toml/unwrap_used/unwrap_used.rs:94:17
|
||||||
|
|
|
|
||||||
LL | let _ = Box::new([0]).get(1).unwrap();
|
LL | let _ = Box::new([0]).get(1).unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -70,6 +70,7 @@ fn main() {
|
|||||||
mod issue9909 {
|
mod issue9909 {
|
||||||
#![allow(clippy::identity_op, clippy::unwrap_used, dead_code)]
|
#![allow(clippy::identity_op, clippy::unwrap_used, dead_code)]
|
||||||
|
|
||||||
|
#[allow(unconditional_panic)]
|
||||||
fn reduced() {
|
fn reduced() {
|
||||||
let f = &[1, 2, 3];
|
let f = &[1, 2, 3];
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ fn main() {
|
|||||||
mod issue9909 {
|
mod issue9909 {
|
||||||
#![allow(clippy::identity_op, clippy::unwrap_used, dead_code)]
|
#![allow(clippy::identity_op, clippy::unwrap_used, dead_code)]
|
||||||
|
|
||||||
|
#[allow(unconditional_panic)]
|
||||||
fn reduced() {
|
fn reduced() {
|
||||||
let f = &[1, 2, 3];
|
let f = &[1, 2, 3];
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
|
|||||||
= help: consider using `expect()` to provide a better panic message
|
= help: consider using `expect()` to provide a better panic message
|
||||||
|
|
||||||
error: called `.get().unwrap()` on a slice
|
error: called `.get().unwrap()` on a slice
|
||||||
--> tests/ui/get_unwrap.rs:77:24
|
--> tests/ui/get_unwrap.rs:78:24
|
||||||
|
|
|
|
||||||
LL | let _x: &i32 = f.get(1 + 2).unwrap();
|
LL | let _x: &i32 = f.get(1 + 2).unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -277,7 +277,7 @@ LL | let _x: &i32 = &f[1 + 2];
|
|||||||
| ~~~~~~~~~
|
| ~~~~~~~~~
|
||||||
|
|
||||||
error: called `.get().unwrap()` on a slice
|
error: called `.get().unwrap()` on a slice
|
||||||
--> tests/ui/get_unwrap.rs:80:18
|
--> tests/ui/get_unwrap.rs:81:18
|
||||||
|
|
|
|
||||||
LL | let _x = f.get(1 + 2).unwrap().to_string();
|
LL | let _x = f.get(1 + 2).unwrap().to_string();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -288,7 +288,7 @@ LL | let _x = f[1 + 2].to_string();
|
|||||||
| ~~~~~~~~
|
| ~~~~~~~~
|
||||||
|
|
||||||
error: called `.get().unwrap()` on a slice
|
error: called `.get().unwrap()` on a slice
|
||||||
--> tests/ui/get_unwrap.rs:83:18
|
--> tests/ui/get_unwrap.rs:84:18
|
||||||
|
|
|
|
||||||
LL | let _x = f.get(1 + 2).unwrap().abs();
|
LL | let _x = f.get(1 + 2).unwrap().abs();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
@ -299,7 +299,7 @@ LL | let _x = f[1 + 2].abs();
|
|||||||
| ~~~~~~~~
|
| ~~~~~~~~
|
||||||
|
|
||||||
error: called `.get_mut().unwrap()` on a slice
|
error: called `.get_mut().unwrap()` on a slice
|
||||||
--> tests/ui/get_unwrap.rs:100:33
|
--> tests/ui/get_unwrap.rs:101:33
|
||||||
|
|
|
|
||||||
LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap();
|
LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap();
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
Loading…
Reference in New Issue
Block a user