Skip to content

Commit

Permalink
fix: make tests check no_std, fix clippy/fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Dec 3, 2023
1 parent 56e230f commit 9deda74
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: MIRIFLAGS=-Zmiri-strict-provenance cargo miri test
- name: Test (gecko-ffi) with Miri
run: MIRIFLAGS=-Zmiri-strict-provenance cargo miri test --features=gecko-ffi

build:
runs-on: ubuntu-latest
steps:
Expand All @@ -39,7 +39,9 @@ jobs:
run: cargo test --features=serde --verbose
- name: Run tests (gecko-ffi)
run: cargo test --tests --features=gecko-ffi --verbose

- name: Run tests (no_std)
run: cargo test --tests --no-default-features --verbose

fmt:
runs-on: ubuntu-latest
steps:
Expand All @@ -54,8 +56,8 @@ jobs:
with:
command: fmt
args: --all -- --check


clippy:
runs-on: ubuntu-latest
steps:
Expand All @@ -72,8 +74,8 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --tests --examples


docs:
runs-on: ubuntu-latest
env:
Expand Down
27 changes: 17 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,12 @@
//! [pinned]: https://doc.rust-lang.org/std/pin/index.html

#![cfg_attr(not(feature = "std"), no_std)]

#![allow(clippy::comparison_chain, clippy::missing_safety_doc)]

extern crate alloc;

use alloc::{vec::Vec, boxed::Box};
use alloc::alloc::*;
use alloc::{boxed::Box, vec::Vec};
use core::borrow::*;
use core::cmp::*;
use core::convert::TryFrom;
Expand Down Expand Up @@ -1971,7 +1970,7 @@ impl<T> FromIterator<T> for ThinVec<T> {
#[inline]
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> ThinVec<T> {
let mut vec = ThinVec::new();
vec.extend(iter.into_iter());
vec.extend(iter);
vec
}
}
Expand Down Expand Up @@ -2640,10 +2639,11 @@ impl std::io::Write for ThinVec<u8> {
#[cfg(test)]
mod tests {
use super::{ThinVec, MAX_CAP};
use crate::alloc::{string::ToString, vec};

#[test]
fn test_size_of() {
use std::mem::size_of;
use core::mem::size_of;
assert_eq!(size_of::<ThinVec<u8>>(), size_of::<&u8>());

assert_eq!(size_of::<Option<ThinVec<u8>>>(), size_of::<&u8>());
Expand Down Expand Up @@ -2831,6 +2831,7 @@ mod tests {
assert_eq!(v.into_iter().count(), 0);

let v = ThinVec::<i32>::new();
#[allow(clippy::never_loop)]
for _ in v.into_iter() {
unreachable!();
}
Expand All @@ -2840,6 +2841,7 @@ mod tests {
let mut v = ThinVec::<i32>::new();
assert_eq!(v.drain(..).len(), 0);

#[allow(clippy::never_loop)]
for _ in v.drain(..) {
unreachable!()
}
Expand All @@ -2853,6 +2855,7 @@ mod tests {
let mut v = ThinVec::<i32>::new();
assert_eq!(v.splice(.., []).len(), 0);

#[allow(clippy::never_loop)]
for _ in v.splice(.., []) {
unreachable!()
}
Expand Down Expand Up @@ -3016,8 +3019,12 @@ mod std_tests {
#![allow(clippy::reversed_empty_ranges)]

use super::*;
use std::mem::size_of;
use std::usize;
use crate::alloc::{
format,
string::{String, ToString},
};
use core::mem::size_of;
use core::usize;

struct DropCounter<'a> {
count: &'a mut u32,
Expand Down Expand Up @@ -3675,7 +3682,7 @@ mod std_tests {
fn test_splice_forget() {
let mut v = thin_vec![1, 2, 3, 4, 5];
let a = [10, 11, 12];
::std::mem::forget(v.splice(2..4, a.iter().cloned()));
::core::mem::forget(v.splice(2..4, a.iter().cloned()));
assert_eq!(v, &[1, 2]);
}

Expand Down Expand Up @@ -4194,16 +4201,16 @@ mod std_tests {
let v: ThinVec<$typename> = ThinVec::with_capacity(1 /* ensure allocation */);
let head_ptr: *mut $typename = v.data_raw();
assert_eq!(
head_ptr as usize % std::mem::align_of::<$typename>(),
head_ptr as usize % core::mem::align_of::<$typename>(),
0,
"expected Header::data<{}> to be aligned",
stringify!($typename)
);
}};
}

const HEADER_SIZE: usize = std::mem::size_of::<Header>();
assert_eq!(2 * std::mem::size_of::<usize>(), HEADER_SIZE);
const HEADER_SIZE: usize = core::mem::size_of::<Header>();
assert_eq!(2 * core::mem::size_of::<usize>(), HEADER_SIZE);

#[repr(C, align(128))]
struct Funky<T>(T);
Expand Down

0 comments on commit 9deda74

Please sign in to comment.