about summary refs log tree commit diff
path: root/tests/ui/precondition-checks/vec-from-parts.rs
blob: ace90770360e5ccd60624d614f15e1a31e46b741 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//@ run-crash
//@ compile-flags: -Cdebug-assertions=yes
//@ error-pattern: unsafe precondition(s) violated: Vec::from_parts_in requires that length <= capacity
#![feature(allocator_api)]

use std::ptr::NonNull;

fn main() {
    let ptr: NonNull<i32> = std::ptr::NonNull::dangling();
    // Test Vec::from_parts_in with length > capacity
    unsafe {
        let alloc = std::alloc::Global;
        let _vec = Vec::from_parts_in(ptr, 10, 5, alloc);
    }
}