mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-08-04 19:08:32 +00:00
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
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:
parent
516ce4fd68
commit
96eeecb5af
4 changed files with 40 additions and 3 deletions
|
@ -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)]
|
||||
|
|
|
@ -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> >
|
||||
|
|
|
@ -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> > >
|
||||
|
|
37
tests/tracked_with_struct_ord.rs
Normal file
37
tests/tracked_with_struct_ord.rs
Normal 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);
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue