Remove default PartialOrd and Ord derives for salsa-structs (#868)
Some checks are pending
Book / Book (push) Waiting to run
Book / Deploy (push) Blocked by required conditions
Release-plz / Release-plz PR (push) Waiting to run
Release-plz / Release-plz release (push) Waiting to run
Test / Test (push) Waiting to run
Test / Miri (push) Waiting to run
Test / Benchmarks (push) Waiting to run

This commit is contained in:
Micha Reiser 2025-05-19 13:57:23 +02:00 committed by GitHub
parent 516ce4fd68
commit 96eeecb5af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 3 deletions

View file

@ -60,7 +60,7 @@ macro_rules! setup_input_struct {
]
) => {
$(#[$attr])*
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
$vis struct $Struct(salsa::Id);
#[allow(clippy::all)]

View file

@ -72,7 +72,7 @@ macro_rules! setup_interned_struct {
]
) => {
$(#[$attr])*
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
$vis struct $Struct< $($db_lt_arg)? >(
$Id,
std::marker::PhantomData < & $interior_lt salsa::plumbing::interned::Value <$StructWithStatic> >

View file

@ -91,7 +91,7 @@ macro_rules! setup_tracked_struct {
]
) => {
$(#[$attr])*
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
$vis struct $Struct<$db_lt>(
salsa::Id,
std::marker::PhantomData < & $db_lt salsa::plumbing::tracked_struct::Value < $Struct<'static> > >

View file

@ -0,0 +1,37 @@
//! Test that `PartialOrd` and `Ord` can be derived for tracked structs
use salsa::{Database, DatabaseImpl};
use test_log::test;
#[salsa::input]
#[derive(PartialOrd, Ord)]
struct Input {
value: usize,
}
#[salsa::tracked(debug)]
#[derive(Ord, PartialOrd)]
struct MyTracked<'db> {
value: usize,
}
#[salsa::tracked]
fn create_tracked(db: &dyn Database, input: Input) -> MyTracked<'_> {
MyTracked::new(db, input.value(db))
}
#[test]
fn execute() {
DatabaseImpl::new().attach(|db| {
let input1 = Input::new(db, 20);
let input2 = Input::new(db, 10);
// Compares by ID and not by value.
assert!(input1 <= input2);
let t0: MyTracked = create_tracked(db, input1);
let t1: MyTracked = create_tracked(db, input2);
assert!(t0 <= t1);
})
}