mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-14 06:22:34 +02:00
`feature(raw_ref_op)` became stable in Rust 1.82.0 which is the current MSRV of pin-init with no default features. Earlier Rust versions will now need to enable `raw_ref_op` to continue to work with pin-init. This reduces visual complexity and improves consistency with existing reference syntax. Suggested-by: Benno Lossin <lossin@kernel.org> Link: https://github.com/Rust-for-Linux/linux/issues/1148 Closes: https://github.com/Rust-for-Linux/pin-init/issues/99 Signed-off-by: Antonio Hickey <contact@antoniohickey.com> Link: https://github.com/Rust-for-Linux/pin-init/commit/e27763004e2f6616b089437fbe9b3719cd72bd5c [ Reworded commit message. - Benno ] Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260319093542.3756606-6-lossin@kernel.org Signed-off-by: Benno Lossin <lossin@kernel.org>
47 lines
1.0 KiB
Rust
47 lines
1.0 KiB
Rust
// SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
|
#![cfg_attr(USE_RUSTC_FEATURES, feature(lint_reasons))]
|
|
#![cfg_attr(USE_RUSTC_FEATURES, feature(raw_ref_op))]
|
|
|
|
use pin_init::*;
|
|
|
|
// Struct with size over 1GiB
|
|
#[derive(Debug)]
|
|
#[allow(dead_code)]
|
|
pub struct BigStruct {
|
|
buf: [u8; 1024 * 1024 * 1024],
|
|
a: u64,
|
|
b: u64,
|
|
c: u64,
|
|
d: u64,
|
|
managed_buf: ManagedBuf,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct ManagedBuf {
|
|
buf: [u8; 1024 * 1024],
|
|
}
|
|
|
|
impl ManagedBuf {
|
|
pub fn new() -> impl Init<Self> {
|
|
init!(ManagedBuf { buf <- init_zeroed() })
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
|
{
|
|
// we want to initialize the struct in-place, otherwise we would get a stackoverflow
|
|
let buf: Box<BigStruct> = Box::init(init!(BigStruct {
|
|
buf <- init_zeroed(),
|
|
a: 7,
|
|
b: 186,
|
|
c: 7789,
|
|
d: 34,
|
|
managed_buf <- ManagedBuf::new(),
|
|
}))
|
|
.unwrap();
|
|
println!("{}", core::mem::size_of_val(&*buf));
|
|
}
|
|
}
|