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

100 lines
2.3 KiB
Rust

// rustc --edition=2021 --test fullcheck_relative_use.rs
// makepad test fullcheck_relative_use.rs
// In edition 2018+, an unprefixed use starts in the current scope. The
// view's child re-exports both a type and a same-named style function, and
// imports the parent scope back through a glob, as lowered .rx views do.
pub mod split {
// A crate-root decoy: resolving view's `use split::SplitPane` here
// would give the wrong field and method types.
pub struct SplitPane {
pub unrelated: bool,
}
}
mod split_pane {
pub struct DrawQuad {
pub drawn: u32,
}
impl DrawQuad {
pub fn draw_abs(&mut self, amount: u32) {
self.drawn += amount;
}
}
pub struct SplitPane {
pub cam_time: f64,
pub draw_bg: DrawQuad,
}
#[allow(non_snake_case)]
pub fn SplitPane() -> SplitPane {
SplitPane { cam_time: 1.0, draw_bg: DrawQuad { drawn: 0 } }
}
}
mod view {
// Put the consumer first so import resolution must reach a fixed point.
use split::SplitPane;
pub struct View {
pane: SplitPane,
}
pub fn exercise() -> (f64, u32) {
let mut view = View { pane: SplitPane() };
view.draw();
(view.pane.cam_time, view.pane.draw_bg.drawn)
}
mod split {
use super::*;
pub(super) use crate::split_pane::SplitPane;
impl View {
pub fn draw(&mut self) {
let Self { pane } = self;
pane.cam_time += 2.0;
pane.draw_bg.draw_abs(7);
}
}
}
}
mod grouped {
use split::{self as pane_module, SplitPane as Pane};
mod split {
pub(super) use crate::split_pane::SplitPane;
}
pub fn exercise() -> f64 {
let pane: Pane = pane_module::SplitPane();
pane.cam_time
}
}
#[test]
fn relative_child_reexport_preserves_type_and_value_namespaces() {
assert_eq!(view::exercise(), (3.0, 7));
}
#[test]
fn grouped_relative_use_and_self_alias_name_the_child() {
assert_eq!(grouped::exercise(), 1.0);
}
#[test]
fn block_relative_use_names_the_local_module() {
use split::SplitPane;
mod split {
pub(super) use crate::split_pane::SplitPane;
}
let mut pane: SplitPane = SplitPane();
pane.draw_bg.draw_abs(5);
assert_eq!(pane.cam_time, 1.0);
assert_eq!(pane.draw_bg.drawn, 5);
}