Skip to content

Commit

Permalink
feat(crabnet): fix warnings and test regression
Browse files Browse the repository at this point in the history
* Remove the pointer extension trait for `NonNull` as of the `non_null_convenience` feature.
  CC: rust-lang/rust#117691
* Update the test stderr files, to match with the new error style.

Signed-off-by: Anhad Singh <[email protected]>
  • Loading branch information
Andy-Python-Programmer committed Mar 24, 2024
1 parent 3e5d0a2 commit 58a74ea
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 29 deletions.
25 changes: 7 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#![no_std]
#![feature(allocator_api, trivial_bounds, new_uninit, associated_type_defaults)]
#![feature(
non_null_convenience,
allocator_api,
trivial_bounds,
new_uninit,
associated_type_defaults
)]

extern crate alloc;

Expand Down Expand Up @@ -91,23 +97,6 @@ where
fn into_boxed_bytes_in<A: Allocator>(self, alloc: A) -> Box<[u8], A>;
}

trait PointerExtension {
unsafe fn add(self, count: usize) -> Self;
unsafe fn sub(self, count: usize) -> Self;
}

impl<T> PointerExtension for NonNull<T> {
#[inline]
unsafe fn add(self, count: usize) -> Self {
NonNull::new_unchecked(self.as_ptr().add(count))
}

#[inline]
unsafe fn sub(self, count: usize) -> Self {
NonNull::new_unchecked(self.as_ptr().sub(count))
}
}

// impl for [T; N]
unsafe impl<const N: usize, T> StackingAnchor<[T; N]> for [T; N] {}
unsafe impl<const N: usize, T, U: Protocol> StackingAnchor<[T; N]> for crate::Stacked<U, [T; N]> {}
Expand Down
2 changes: 1 addition & 1 deletion src/transport/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use byte_endian::BigEndian;
use static_assertions::const_assert_eq;

use crate::network::Ipv4;
use crate::{Parsable, Parsed, PointerExtension, Protocol, Stack, Stacked, StackingAnchor};
use crate::{Parsable, Parsed, Protocol, Stack, Stacked, StackingAnchor};

#[derive(Default, Debug, Copy, Clone, PartialEq)]
#[repr(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion src/transport/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use byte_endian::BigEndian;
use static_assertions::const_assert_eq;

use crate::network::Ipv4;
use crate::{Parsable, PointerExtension, Protocol, Stack, Stacked, StackingAnchor};
use crate::{Parsable, Protocol, Stack, Stacked, StackingAnchor};

#[repr(C, packed)]
pub struct Udp {
Expand Down
10 changes: 2 additions & 8 deletions tests/ui/udp_no_parent.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ error[E0599]: the method `into_boxed_bytes` exists for struct `Stacked<Udp, [u8;
::: src/lib.rs
|
| pub struct Stacked<U: Protocol, L: Protocol> {
| --------------------------------------------
| |
| doesn't satisfy `_: IntoBoxedBytes`
| doesn't satisfy `_: IsSafeToWrite`
| -------------------------------------------- doesn't satisfy `_: IntoBoxedBytes` or `_: IsSafeToWrite`
|
= note: the following trait bounds were not satisfied:
`Stacked<crabnet::transport::Udp, [u8; 4]>: IsSafeToWrite`
Expand All @@ -29,10 +26,7 @@ error[E0599]: the method `into_boxed_bytes` exists for struct `Udp`, but its tra
::: src/transport/udp.rs
|
| pub struct Udp {
| --------------
| |
| doesn't satisfy `crabnet::transport::Udp: IntoBoxedBytes`
| doesn't satisfy `crabnet::transport::Udp: IsSafeToWrite`
| -------------- doesn't satisfy `crabnet::transport::Udp: IntoBoxedBytes` or `crabnet::transport::Udp: IsSafeToWrite`
|
= note: the following trait bounds were not satisfied:
`crabnet::transport::Udp: IsSafeToWrite`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/valid_parent.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0277]: the trait bound `Eth: StackingAnchor<Ipv4>` is not satisfied
--> tests/ui/valid_parent.rs:8:17
|
8 | let x = eth / udp;
| ^ the trait `StackingAnchor<Ipv4>` is not implemented for `Eth`
| ^ the trait `StackingAnchor<Ipv4>` is not implemented for `Eth`, which is required by `Eth: Div<_>`
|
= help: the trait `StackingAnchor<Eth>` is implemented for `Eth`
= help: for that trait implementation, expected `Eth`, found `Ipv4`
Expand Down

0 comments on commit 58a74ea

Please sign in to comment.