Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Block warnings (with warnings fixes) #106

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Ideally this should be replaced with a call out to Murdock; until that is
# practical, building representative examples.

# Ad RUSTFLAGS=-Dwarnings: While this is generally discouraged (for it means
# that new Rust versions break CI), in this case we don't get new Rust versions
# all the time but only on riotdocker updates, and that's a good time to
# reflect on whether the new warnings make sense or not.

name: test

on:
Expand Down Expand Up @@ -58,7 +63,7 @@ jobs:

- name: Build the example
run: |
make all BOARD=${{ matrix.board }} -C RIOT/${{ matrix.example }}
RUSTFLAGS=-Dwarnings make all BOARD=${{ matrix.board }} -C RIOT/${{ matrix.example }}

enumerate-wrappers-tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -128,7 +133,7 @@ jobs:
cd ${{ matrix.testdir }}
if BOARDS=${{ matrix.board }} make info-boards-supported | grep -q .
then
BOARD=${{ matrix.board }} make all
BOARD=${{ matrix.board }} RUSTFLAGS=-Dwarnings make all

if [ "native" = "${{ matrix.board }}" ] && make test/available BOARD=native
then
Expand Down
84 changes: 45 additions & 39 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,49 +61,55 @@ impl PointerToCStr for *const i8 {
}
}

/// Trait that eases conversions from a char slice (no matter the signedness, they are used
/// inconsistently in RIOT) to a CStr. The result is often used with `?.to_str().ok()?`.
pub(crate) trait SliceToCStr {
/// Cast self around until it is suitable input to [`core::ffi::CStr::from_bytes_until_nul()`],
/// and run that function.
///
/// Note that while "the slice until any null byte" could be safely used in Rust (as a slice or
/// even a str), its presence in C practically always indicates an error, also because that
/// data wouldn't be usable by other C code using its string conventions.
///
/// It is using a local error type because while the semantics of `from_bytes_until_nul` are
/// the right ones considering how this is used on C fields that are treated with `strlen()`
/// etc., that function is not stable yet and emulated.
fn to_cstr(&self) -> Result<&core::ffi::CStr, FromBytesUntilNulError>;
}
// Gated because it is only used there -- expand as needed.
#[cfg(riot_module_vfs)]
mod slice_to_cstr {
/// Trait that eases conversions from a char slice (no matter the signedness, they are used
/// inconsistently in RIOT) to a CStr. The result is often used with `?.to_str().ok()?`.
pub(crate) trait SliceToCStr {
/// Cast self around until it is suitable input to [`core::ffi::CStr::from_bytes_until_nul()`],
/// and run that function.
///
/// Note that while "the slice until any null byte" could be safely used in Rust (as a slice or
/// even a str), its presence in C practically always indicates an error, also because that
/// data wouldn't be usable by other C code using its string conventions.
///
/// It is using a local error type because while the semantics of `from_bytes_until_nul` are
/// the right ones considering how this is used on C fields that are treated with `strlen()`
/// etc., that function is not stable yet and emulated.
fn to_cstr(&self) -> Result<&core::ffi::CStr, FromBytesUntilNulError>;
}

// Unlike in the from_ptr case, this is consistently taking u8, so only the i8 case gets casting.
// Unlike in the from_ptr case, this is consistently taking u8, so only the i8 case gets casting.

impl SliceToCStr for [u8] {
fn to_cstr(&self) -> Result<&core::ffi::CStr, FromBytesUntilNulError> {
// Emulate from_bytes_until_null
let index = self
.iter()
.position(|&c| c == 0)
.ok_or(FromBytesUntilNulError {})?;
impl SliceToCStr for [u8] {
fn to_cstr(&self) -> Result<&core::ffi::CStr, FromBytesUntilNulError> {
// Emulate from_bytes_until_null
let index = self
.iter()
.position(|&c| c == 0)
.ok_or(FromBytesUntilNulError {})?;

core::ffi::CStr::from_bytes_with_nul(&self[..index + 1])
// Actually the error is unreachable
.map_err(|_| FromBytesUntilNulError {})
core::ffi::CStr::from_bytes_with_nul(&self[..index + 1])
// Actually the error is unreachable
.map_err(|_| FromBytesUntilNulError {})
}
}
}

impl SliceToCStr for [i8] {
fn to_cstr(&self) -> Result<&core::ffi::CStr, FromBytesUntilNulError> {
let s: &[u8] = unsafe { core::mem::transmute(self) };
s.to_cstr()
impl SliceToCStr for [i8] {
fn to_cstr(&self) -> Result<&core::ffi::CStr, FromBytesUntilNulError> {
let s: &[u8] = unsafe { core::mem::transmute(self) };
s.to_cstr()
}
}
}

/// Error from [SliceToCStr::to_cstr].
///
/// This will become [core::ffi:FromBytesUntilNulError] once that's stable, and may be changed
/// without a breaking release even though it's technically a breaking change. (At this point, that
/// type will be `pub use`d here and deprecated).
#[derive(Debug)]
pub struct FromBytesUntilNulError {}
/// Error from [SliceToCStr::to_cstr].
///
/// This will become [core::ffi:FromBytesUntilNulError] once that's stable, and may be changed
/// without a breaking release even though it's technically a breaking change. (At this point, that
/// type will be `pub use`d here and deprecated).
#[derive(Debug)]
pub struct FromBytesUntilNulError {}
}
#[cfg(riot_module_vfs)]
pub use slice_to_cstr::*;
2 changes: 1 addition & 1 deletion src/impl_critical_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use critical_section::RawRestoreState;

struct CriticalSection(usize);
struct CriticalSection;
critical_section::set_impl!(CriticalSection);

unsafe impl critical_section::Impl for CriticalSection {
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,10 @@ pub mod led;
#[cfg(riot_module_auto_init)]
pub mod auto_init;

// Gated like socket_embedded_nal_async_udp as it is only used there -- expand as needed.
#[cfg(all(
riot_module_sock_udp,
riot_module_sock_aux_local,
feature = "with_embedded_nal_async"
))]
mod async_helpers;
2 changes: 2 additions & 0 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ impl Into<riot_sys::sock_udp_ep_t> for UdpEp {
}
}

// Gated to its users to avoid dead code warnings
#[cfg(any(feature = "with_embedded_nal", feature = "with_embedded_nal_async"))]
macro_rules! implementation_no_std_net {
($nsn_crate:ident) => {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion src/ztimer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl<const HZ: u32> Clock<HZ> {
ticks: Ticks<HZ>,
in_thread: M,
) -> R {
use core::{cell::UnsafeCell, mem::ManuallyDrop};
use core::cell::UnsafeCell;

// This is zero-initialized, which is the more efficient mode for ztimer_t.
let mut timer = riot_sys::ztimer_t::default();
Expand Down
4 changes: 2 additions & 2 deletions tests/led/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ fn main() {
];
loop {
for i in 0..=255 {
for j in 0..8 {
for (j, led) in leds.iter_mut().enumerate() {
if (i ^ (i - 1)) & (1 << j) != 0 {
leds[j].toggle().unwrap();
led.toggle().unwrap();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/random/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use riot_wrappers::riot_main;
riot_main!(main);

fn check_csrng(mut rng: impl rand_core::CryptoRng + rand_core::RngCore) {
use rngcheck::{helpers::*, nist::*};
use rngcheck::nist::*;

// This is also in https://github.com/ryankurte/rngcheck/pull/3
struct BitIter<'a, R: rand_core::RngCore> {
Expand Down
12 changes: 9 additions & 3 deletions tests/ztimer-async/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ fn main() -> ! {
static_cell::StaticCell::new();
let executor: &'static mut _ = EXECUTOR.init(embassy_executor_riot::Executor::new());
executor.run(|spawner| {
spawner.spawn(amain(spawner));
spawner
.spawn(amain(spawner))
.expect("Task did not get spawned before");
})
}

Expand All @@ -38,8 +40,12 @@ async fn amain(spawner: embassy_executor::Spawner) {
drop(locked);
println!("And now for something more complex...");

spawner.spawn(ten_tenths());
spawner.spawn(five_fifths());
spawner
.spawn(ten_tenths())
.expect("Task did not get spawned before");
spawner
.spawn(five_fifths())
.expect("Task did not get spawned before");
}

#[embassy_executor::task]
Expand Down
Loading