diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index e5098313..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "cargo" - directory: "/" - schedule: - interval: "daily" \ No newline at end of file diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 00000000..441db727 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,95 @@ +name: checks +on: + pull_request: + merge_group: + types: [checks_requested] + workflow_dispatch: +jobs: + benchmarks: + name: Benchmarks + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v7 + - name: install + uses: dtolnay/rust-toolchain@nightly + - name: default features + run: cargo bench --no-run + - name: all features + run: cargo bench --all-features --no-run + practices: + name: Practices + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v7 + - name: install + uses: dtolnay/rust-toolchain@nightly + - name: style + run: | + rustup component add rustfmt + cargo fmt --all --check + - name: clippy + run: | + rustup component add clippy + cargo clippy + - name: docs + run: cargo doc --all-features + miri: + name: Miri + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v7 + - name: install + uses: dtolnay/rust-toolchain@nightly + - name: default features + run: | + rustup component add miri + cargo miri test + - name: all features + run: cargo miri test --all-features + stable: + name: Stable + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v7 + - name: install + uses: dtolnay/rust-toolchain@stable + - name: test default features + run: cargo test + nightly: + name: Nightly + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v7 + - name: install + uses: dtolnay/rust-toolchain@nightly + - name: test default features + run: cargo test + - name: test all features + run: cargo test --all-features + nostd: + name: NoStd + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v7 + - name: install + uses: dtolnay/rust-toolchain@stable + with: + target: thumbv7m-none-eabi + - name: test default features + run: cargo test + msrv: + name: MSRV + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v7 + - name: install + uses: dtolnay/rust-toolchain@1.86 + - name: test default features + run: cargo test \ No newline at end of file diff --git a/.github/workflows/fuzzing.yml b/.github/workflows/fuzzing.yml new file mode 100644 index 00000000..a1a88f08 --- /dev/null +++ b/.github/workflows/fuzzing.yml @@ -0,0 +1,21 @@ +name: fuzzing +on: + workflow_dispatch: + schedule: + - cron: "0 0 * * *" +jobs: + fuzz: + name: Fuzz + if: github.repository == 'servo/rust-smallvec' + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v7 + - name: install + uses: dtolnay/rust-toolchain@stable + - name: fuzzing + run: | + sudo apt-get update -y + sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev + sudo apt-get install -y libelf-dev libdw-dev cmake gcc libiberty-dev + ./travis-fuzz.sh \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 2a836946..00000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: Rust - -on: - push: - branches: [v2] - pull_request: - merge_group: - types: [checks_requested] - workflow_dispatch: - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - name: Build and test (${{ matrix.name }}) - runs-on: ubuntu-latest - strategy: - matrix: - include: - - name: stable - toolchain: stable - fuzz: true - - name: beta - toolchain: beta - fuzz: true - - name: nightly - toolchain: nightly - nightly: true - - name: MSRV - toolchain: "1.86.0" - - name: no_std - toolchain: stable - target: thumbv7m-none-eabi - no_std: true - steps: - - uses: actions/checkout@v7 - - - name: Install packages for fuzzing - if: matrix.fuzz - run: sudo apt-get update -y && sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev - - - name: Install toolchain - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.toolchain }} - target: ${{ matrix.target }} - - - name: Style check - if: matrix.nightly - run: rustup component add rustfmt && cargo fmt --all --check - - - name: Clippy check - if: matrix.nightly - run: rustup component add clippy && cargo clippy --all-features --all-targets -- -D warnings - - - name: Build - run: cargo build --verbose - - - name: Run tests - if: ${{ !matrix.no_std }} - run: cargo test --verbose - - - name: Cargo test no default features - if: matrix.nightly - run: cargo test --verbose --no-default-features - - - name: Cargo test all features - if: matrix.nightly - run: cargo test --verbose --all-features - - - name: Cargo doc all features - if: matrix.nightly - run: cargo doc --all-features --verbose - - - name: Cargo bench no default features - if: matrix.nightly - run: cargo clean && cargo bench --verbose --no-default-features - - - name: Cargo bench all features - if: matrix.nightly - run: cargo clean && cargo bench --verbose --all-features - - - name: miri - if: matrix.nightly - run: rustup component add miri && cargo miri test --verbose --all-features - - - name: fuzz - if: matrix.fuzz - working-directory: fuzz - run: ./travis-fuzz.sh - - build_result: - name: homu build finished - runs-on: ubuntu-latest - needs: build - - steps: - - name: Mark the job as successful - run: exit 0 - if: success() - - name: Mark the job as unsuccessful - run: exit 1 - if: "!success()" diff --git a/src/taggedlen.rs b/src/taggedlen.rs index c3571657..2254b15d 100644 --- a/src/taggedlen.rs +++ b/src/taggedlen.rs @@ -60,19 +60,21 @@ impl TaggedLen { /// current len+n must be smaller than MAX_LEN on 64-bit target #[inline(always)] pub const unsafe fn add(&mut self, n: usize) { - #[cold] - #[inline(never)] - const fn assert_failed() { - panic!("smallvec length overflow") - } #[cfg(any(debug_assertions, not(target_pointer_width = "64")))] - match self.len().checked_add(n) { - Some(value) => { - if value > Self::MAX_LEN { - assert_failed() + { + #[cold] + #[inline(never)] + const fn assert_failed() { + panic!("smallvec length overflow") + } + match self.len().checked_add(n) { + Some(value) => { + if value > Self::MAX_LEN { + assert_failed() + } } + None => assert_failed() } - None => assert_failed() } self.0 += n << Self::SHIFT; } diff --git a/tests/borsh.rs b/tests/borsh.rs index 1c99798f..5ab0453e 100644 --- a/tests/borsh.rs +++ b/tests/borsh.rs @@ -16,7 +16,7 @@ fn round_trip() { #[test] fn round_trip_zst() { - let smallvec = SmallVec::<(), 5>::from([(); 0x100000]); + let smallvec = SmallVec::<(), 5>::from([(); 0x100]); let bytes = to_vec(&smallvec).unwrap(); let new = SmallVec::<(), 100>::deserialize(&mut bytes.as_ref()).unwrap(); assert_eq!(new, smallvec);