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

51 lines
1.3 KiB
Rust

// Integer literal variables stay open until the whole body is checked (rustc_hir_typeck
// fallback.rs: `{integer}` -> i32 only after typeck of the body), boot lane B1c
// (objc-sys encode.rs `let mut bytes = [0; CAP]` filled from `code.bytes()`). rustc: all pass.
const CAP: usize = 8;
enum Code {
Inline(u8, [u8; CAP]),
#[allow(dead_code)]
Other,
}
fn inline(code: &str) -> Code {
let mut bytes = [0; CAP];
for (dst, byte) in bytes.iter_mut().zip(code.bytes()) {
*dst = byte;
}
Code::Inline(code.len() as u8, bytes)
}
fn first_even(v: &[u32]) -> Option<&u32> {
v.iter().find(|x| **x % 2 == 0)
}
#[test]
fn literals_learn_from_later_uses() {
match inline("ab") {
Code::Inline(n, b) => assert!(n == 2 && b[1] == b'b' && b[2] == 0),
Code::Other => panic!(),
}
let mut a = [0; 4];
for d in a.iter_mut() {
*d = 7u8;
}
let x: [u8; 4] = a;
assert!(x[3] == 7);
let mut it = [0; 2];
let mut m = it.iter_mut();
let d = m.next().unwrap();
*d = 9u16;
assert!(it[0] == 9u16);
let v = vec![3, 5, 8, 9];
assert!(first_even(&v).copied() == Some(8));
let y = 1 << 40;
let z: u64 = y;
assert!(z == 1u64 << 40);
let f = 1.5;
let g: f32 = f;
assert!(g == 1.5f32);
let i = 7;
assert!(i / 2 == 3);
}