소스 검색

Allow aya-ebpf to clippy with stable rust

The const-assert crate doesn't even compile with stable rust, so we
shouldn't depend on it. Instead we replicate its functionality behind
cfg(unstable) which is set at build time based on the toolchain in use.
Tamir Duberstein 7 달 전
부모
커밋
1de7e728b6
4개의 변경된 파일16개의 추가작업 그리고 20개의 파일을 삭제
  1. 0 8
      ebpf/aya-ebpf/Cargo.toml
  2. 1 5
      ebpf/aya-ebpf/src/lib.rs
  3. 13 5
      ebpf/aya-ebpf/src/maps/ring_buf.rs
  4. 2 2
      xtask/public-api/aya-ebpf.txt

+ 0 - 8
ebpf/aya-ebpf/Cargo.toml

@@ -12,14 +12,6 @@ edition.workspace = true
 aya-ebpf-cty = { version = "^0.2.2", path = "../aya-ebpf-cty" }
 aya-ebpf-macros = { version = "^0.1.1", path = "../../aya-ebpf-macros" }
 aya-ebpf-bindings = { version = "^0.1.1", path = "../aya-ebpf-bindings" }
-const-assert = { workspace = true, optional = true }
 
 [build-dependencies]
 rustversion = { workspace = true }
-
-[features]
-default = []
-# TODO(https://github.com/rust-lang/rust/issues/76560): Always utilize the
-# logic gated behind this feature. This is not currently possible because the
-# underlying `const_generic_exprs` language feature is still incomplete.
-const_assert = ["const-assert"]

+ 1 - 5
ebpf/aya-ebpf/src/lib.rs

@@ -8,11 +8,7 @@
     html_logo_url = "https://aya-rs.dev/assets/images/crabby.svg",
     html_favicon_url = "https://aya-rs.dev/assets/images/crabby.svg"
 )]
-#![cfg_attr(
-    feature = "const_assert",
-    allow(incomplete_features),
-    feature(generic_const_exprs)
-)]
+#![cfg_attr(unstable, allow(incomplete_features), feature(generic_const_exprs))]
 #![cfg_attr(unstable, feature(never_type))]
 #![cfg_attr(target_arch = "bpf", feature(asm_experimental_arch))]
 #![allow(clippy::missing_safety_doc)]

+ 13 - 5
ebpf/aya-ebpf/src/maps/ring_buf.rs

@@ -5,9 +5,6 @@ use core::{
     ops::{Deref, DerefMut},
 };
 
-#[cfg(feature = "const_assert")]
-use const_assert::{Assert, IsTrue};
-
 use crate::{
     bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_RINGBUF},
     helpers::{
@@ -17,6 +14,17 @@ use crate::{
     maps::PinningType,
 };
 
+#[cfg(unstable)]
+mod const_assert {
+    pub struct Assert<const COND: bool> {}
+
+    pub trait IsTrue {}
+
+    impl IsTrue for Assert<true> {}
+}
+#[cfg(unstable)]
+use const_assert::{Assert, IsTrue};
+
 #[repr(transparent)]
 pub struct RingBuf {
     def: UnsafeCell<bpf_map_def>,
@@ -93,7 +101,7 @@ impl RingBuf {
     /// Reserve memory in the ring buffer that can fit `T`.
     ///
     /// Returns `None` if the ring buffer is full.
-    #[cfg(feature = "const_assert")]
+    #[cfg(unstable)]
     pub fn reserve<T: 'static>(&self, flags: u64) -> Option<RingBufEntry<T>>
     where
         Assert<{ 8 % mem::align_of::<T>() == 0 }>: IsTrue,
@@ -109,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(feature = "const_assert"))]
+    #[cfg(not(unstable))]
     pub fn reserve<T: 'static>(&self, flags: u64) -> Option<RingBufEntry<T>> {
         assert_eq!(8 % mem::align_of::<T>(), 0);
         self.reserve_impl(flags)

+ 2 - 2
xtask/public-api/aya-ebpf.txt

@@ -469,7 +469,7 @@ impl aya_ebpf::maps::ring_buf::RingBuf
 pub fn aya_ebpf::maps::ring_buf::RingBuf::output<T: ?core::marker::Sized>(&self, data: &T, flags: u64) -> core::result::Result<(), i64>
 pub const fn aya_ebpf::maps::ring_buf::RingBuf::pinned(byte_size: u32, flags: u32) -> Self
 pub fn aya_ebpf::maps::ring_buf::RingBuf::query(&self, flags: u64) -> u64
-pub fn aya_ebpf::maps::ring_buf::RingBuf::reserve<T: 'static>(&self, flags: u64) -> core::option::Option<aya_ebpf::maps::ring_buf::RingBufEntry<T>> where const_assert::Assert<{ _ }>: const_assert::IsTrue
+pub fn aya_ebpf::maps::ring_buf::RingBuf::reserve<T: 'static>(&self, flags: u64) -> core::option::Option<aya_ebpf::maps::ring_buf::RingBufEntry<T>> where Assert<{ _ }>: IsTrue
 pub const fn aya_ebpf::maps::ring_buf::RingBuf::with_byte_size(byte_size: u32, flags: u32) -> Self
 impl core::marker::Sync for aya_ebpf::maps::ring_buf::RingBuf
 impl !core::marker::Freeze for aya_ebpf::maps::ring_buf::RingBuf
@@ -1195,7 +1195,7 @@ impl aya_ebpf::maps::ring_buf::RingBuf
 pub fn aya_ebpf::maps::ring_buf::RingBuf::output<T: ?core::marker::Sized>(&self, data: &T, flags: u64) -> core::result::Result<(), i64>
 pub const fn aya_ebpf::maps::ring_buf::RingBuf::pinned(byte_size: u32, flags: u32) -> Self
 pub fn aya_ebpf::maps::ring_buf::RingBuf::query(&self, flags: u64) -> u64
-pub fn aya_ebpf::maps::ring_buf::RingBuf::reserve<T: 'static>(&self, flags: u64) -> core::option::Option<aya_ebpf::maps::ring_buf::RingBufEntry<T>> where const_assert::Assert<{ _ }>: const_assert::IsTrue
+pub fn aya_ebpf::maps::ring_buf::RingBuf::reserve<T: 'static>(&self, flags: u64) -> core::option::Option<aya_ebpf::maps::ring_buf::RingBufEntry<T>> where Assert<{ _ }>: IsTrue
 pub const fn aya_ebpf::maps::ring_buf::RingBuf::with_byte_size(byte_size: u32, flags: u32) -> Self
 impl core::marker::Sync for aya_ebpf::maps::ring_buf::RingBuf
 impl !core::marker::Freeze for aya_ebpf::maps::ring_buf::RingBuf