aya-ebpf: add a dedicated generic_const_exprs cfg

reviewable/pr1271/r1
Tamir Duberstein 1 week ago
parent 630a767117
commit 8a2deddac7
No known key found for this signature in database

@ -28,11 +28,12 @@ fn main() {
}
println!("))");
println!("cargo::rustc-check-cfg=cfg(unstable)");
println!("cargo::rustc-check-cfg=cfg(generic_const_exprs,unstable)");
}
#[rustversion::nightly]
fn check_rust_version() {
println!("cargo:rustc-cfg=generic_const_exprs");
println!("cargo:rustc-cfg=unstable");
}

@ -8,7 +8,12 @@
html_logo_url = "https://aya-rs.dev/assets/images/crabby.svg",
html_favicon_url = "https://aya-rs.dev/assets/images/crabby.svg"
)]
#![cfg_attr(unstable, expect(incomplete_features), feature(generic_const_exprs))]
// TODO(https://github.com/rust-lang/rust/issues/141492): reenable this.
#![cfg_attr(
generic_const_exprs,
expect(incomplete_features),
feature(generic_const_exprs)
)]
#![cfg_attr(unstable, feature(never_type))]
#![cfg_attr(target_arch = "bpf", feature(asm_experimental_arch))]
#![warn(clippy::cast_lossless, clippy::cast_sign_loss)]

@ -14,7 +14,7 @@ use crate::{
maps::PinningType,
};
#[cfg(unstable)]
#[cfg(generic_const_exprs)]
mod const_assert {
pub struct Assert<const COND: bool> {}
@ -22,7 +22,7 @@ mod const_assert {
impl IsTrue for Assert<true> {}
}
#[cfg(unstable)]
#[cfg(generic_const_exprs)]
use const_assert::{Assert, IsTrue};
#[repr(transparent)]
@ -101,7 +101,7 @@ impl RingBuf {
/// Reserve memory in the ring buffer that can fit `T`.
///
/// Returns `None` if the ring buffer is full.
#[cfg(unstable)]
#[cfg(generic_const_exprs)]
pub fn reserve<T: 'static>(&self, flags: u64) -> Option<RingBufEntry<T>>
where
Assert<{ 8 % mem::align_of::<T>() == 0 }>: IsTrue,
@ -117,7 +117,7 @@ impl RingBuf {
/// be equal or smaller than 8. If you use this with a `T` that isn't properly aligned, this
/// function will be compiled to a panic; depending on your panic_handler, this may make
/// the eBPF program fail to load, or it may make it have undefined behavior.
#[cfg(not(unstable))]
#[cfg(not(generic_const_exprs))]
pub fn reserve<T: 'static>(&self, flags: u64) -> Option<RingBufEntry<T>> {
assert_eq!(8 % mem::align_of::<T>(), 0);
self.reserve_impl(flags)

Loading…
Cancel
Save