makepad/libs/relax/compiler/tests/round9_derives.rs
Admin b22a714840 makepad run: the Rust JIT (libs/relax) and makepad-remote
The JIT that runs makepad apps from source: lexer, front end, type checker,
lazy borrow checker (Gandalf; `--check-first` opts in), codegen, session and
warm/cold caches keyed by compiler stamp, provided crates bound late,
startup images, live patching. User-facing name is `makepad run` (binary
`makepad`, MAKEPAD_RUN_* env, ~/.makepad-run); libs/relax stays the internal
library name. `makepad check` reports rustc-style diagnostics with rustc
error codes and checks a whole workspace (`--workspace`). Runs on macOS,
Linux, Windows and Android. makepad-remote: one tool schema for apps and the
WM (app/1): grabs, captures, traces, frame profiles and tweaks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00

43 lines
1.2 KiB
Rust

use std::cell::Cell;
struct Counted<'a>(&'a Cell<u32>);
impl Clone for Counted<'_> {
fn clone(&self) -> Self { self.0.set(self.0.get() + 1); Self(self.0) }
}
impl Copy for Counted<'_> {}
#[derive(Clone, Copy)]
struct Simple<'a>(Counted<'a>);
#[derive(Clone, Copy)]
struct Generic<T>(T);
#[derive(Clone, Copy)]
union Union<T: Copy> { value: T }
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(packed)]
struct Packed<T> { x: u8, value: T }
#[derive(Clone, PartialEq, Eq)]
enum Choice<T> { Empty, Tuple(T), Named { value: T } }
#[test]
fn clone_forms() {
let n = Cell::new(0);
let s = Simple(Counted(&n));
let _ = s.clone();
assert_eq!(n.get(), 0);
let g = Generic(Counted(&n));
let _ = g.clone();
assert_eq!(n.get(), 1);
let u = Union { value: Counted(&n) };
let _ = u.clone();
assert_eq!(n.get(), 1);
}
#[test]
fn derived_comparisons_and_packed_fields() {
let p = Packed { x: 1, value: 23u32 };
assert!(p == p.clone());
assert!(p != Packed { x: 1, value: 24u32 });
let a = Choice::Named { value: String::from("hello") };
assert!(a == a.clone());
assert!(a != Choice::Tuple(String::from("hello")));
assert!(Choice::<String>::Empty == Choice::Empty);
}