makepad/libs/relax/compiler/tests/match_arms_lub_deref.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

46 lines
1.4 KiB
Rust

struct D { node: String, cutoff: String, res: String }
impl D {
fn path(&self, field: &str) -> String {
let given = match field {
"cutoff" => &self.cutoff,
"res" => &self.res,
_ => "",
};
if given.is_empty() { format!("{}.{field}", self.node) } else { given.to_string() }
}
fn first(&self, b: bool) -> usize {
let s = if b { &self.node } else { "x" };
s.len()
}
}
#[test]
fn match_arms_deref_coerce_to_later_str() {
let d = D { node: "n".into(), cutoff: "c".into(), res: String::new() };
assert_eq!(d.path("cutoff"), "c");
assert_eq!(d.path("res"), "n.res");
assert_eq!(d.path("zz"), "n.zz");
}
#[test]
fn if_arms_deref_coerce_to_later_str() {
let d = D { node: "node".into(), cutoff: String::new(), res: String::new() };
assert_eq!(d.first(true), 4);
assert_eq!(d.first(false), 1);
}
#[test]
fn match_arms_copy_all_deref_steps() {
let first = Box::new(String::from("first"));
let second = Box::new(String::from("second"));
let first_ref = &first;
let second_ref = &second;
for field in 0..3 {
// A built-in reference deref followed by Box::deref and String::deref.
let given = match field {
0 => &first_ref,
1 => &second_ref,
_ => "fallback",
};
assert_eq!(given, match field { 0 => "first", 1 => "second", _ => "fallback" });
}
}