]> git.lizzy.rs Git - rust.git/blob - tests/codegen/vec-shrink-panik.rs
Rollup merge of #107190 - fmease:fix-81698, r=compiler-errors
[rust.git] / tests / codegen / vec-shrink-panik.rs
1 // compile-flags: -O
2 // ignore-debug: the debug assertions get in the way
3 #![crate_type = "lib"]
4 #![feature(shrink_to)]
5
6 // Make sure that `Vec::shrink_to_fit` never emits panics via `RawVec::shrink_to_fit`,
7 // "Tried to shrink to a larger capacity", because the length is *always* <= capacity.
8
9 // CHECK-LABEL: @shrink_to_fit
10 #[no_mangle]
11 pub fn shrink_to_fit(vec: &mut Vec<u32>) {
12     // CHECK-NOT: panic
13     vec.shrink_to_fit();
14 }
15
16 // CHECK-LABEL: @issue71861
17 #[no_mangle]
18 pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> {
19     // CHECK-NOT: panic
20
21     // Call to panic_cannot_unwind in case of double-panic is expected,
22     // but other panics are not.
23     // CHECK: cleanup
24     // CHECK-NEXT: ; call core::panicking::panic_cannot_unwind
25     // CHECK-NEXT: panic_cannot_unwind
26
27     // CHECK-NOT: panic
28     vec.into_boxed_slice()
29 }
30
31 // CHECK-LABEL: @issue75636
32 #[no_mangle]
33 pub fn issue75636<'a>(iter: &[&'a str]) -> Box<[&'a str]> {
34     // CHECK-NOT: panic
35
36     // Call to panic_cannot_unwind in case of double-panic is expected,
37     // but other panics are not.
38     // CHECK: cleanup
39     // CHECK-NEXT: ; call core::panicking::panic_cannot_unwind
40     // CHECK-NEXT: panic_cannot_unwind
41
42     // CHECK-NOT: panic
43     iter.iter().copied().collect()
44 }
45
46 // CHECK: ; core::panicking::panic_cannot_unwind
47 // CHECK: declare void @{{.*}}panic_cannot_unwind