Skip to content

Commit

Permalink
[222] Fix tests on nightly (#2003)
Browse files Browse the repository at this point in the history
* Fix tests on nightly (#1999)

Ensure that `PartialOrd` and `Ord` implementations for `Alignment` are
the same instead of having one be manual and one be derived. This is
required to account for a small behavior change in nightly Rust.

* Pin CI module
  • Loading branch information
alexcrichton authored Feb 5, 2025
1 parent 892d4b6 commit 71382ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
submodules: true
- uses: ./.github/actions/install-rust
- uses: bytecodealliance/wasmtime/.github/actions/binary-compatible-builds@main
- uses: bytecodealliance/wasmtime/.github/actions/binary-compatible-builds@release-28.0.0
with:
name: ${{ matrix.build }}
if: matrix.build != 'wasm32-wasip1'
Expand Down
11 changes: 9 additions & 2 deletions crates/wit-parser/src/sizealign.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::{
cmp::Ordering,
num::NonZeroUsize,
ops::{Add, AddAssign},
};

use crate::{FlagsRepr, Int, Resolve, Type, TypeDef, TypeDefKind};

/// Architecture specific alignment
#[derive(Eq, PartialEq, PartialOrd, Clone, Copy)]
#[derive(Eq, PartialEq, Clone, Copy)]
pub enum Alignment {
/// This represents 4 byte alignment on 32bit and 8 byte alignment on 64bit architectures
Pointer,
Expand All @@ -29,11 +30,17 @@ impl std::fmt::Debug for Alignment {
}
}

impl PartialOrd for Alignment {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Alignment {
/// Needed for determining the max alignment of an object from its parts.
/// The ordering is: Bytes(1) < Bytes(2) < Bytes(4) < Pointer < Bytes(8)
/// as a Pointer is either four or eight byte aligned, depending on the architecture
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
(Alignment::Pointer, Alignment::Pointer) => std::cmp::Ordering::Equal,
(Alignment::Pointer, Alignment::Bytes(b)) => {
Expand Down

0 comments on commit 71382ee

Please sign in to comment.