Skip to content

Commit

Permalink
Fix tests on nightly (bytecodealliance#1999)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Feb 4, 2025
1 parent 549c283 commit 7946672
Showing 1 changed file with 9 additions and 2 deletions.
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 7946672

Please sign in to comment.