The controllers test compiles again: a closure can't name the lifetime its Ctx borrows #321

Merged
enricobuehler merged 1 commits from worktree-console-ui-ctx-lifetime into main 2026-08-19 06:18:43 +00:00
Owner

Unblocks the red clippy leg on #320.

What broke

crates/pf-console-ui/src/screens/controllers.rs built its test Ctx from a closure:

let ctx = |platform, settings: &mut Settings| Ctx {  };

A closure cannot be generic over the lifetime in its return type, so the Ctx<'2> it produced could never be tied to the &mut Settings<'1> it borrows:

error: lifetime may not live long enough
   --> crates/pf-console-ui/src/screens/controllers.rs:411:55
    | returning this value requires that `'1` must outlive `'2`
error: could not compile `pf-console-ui` (lib test)

Nothing platform-specific about it — it just never compiled on any target that builds this crate. It went unnoticed on macOS because pf-console-ui is cfg-gated to linux/windows/android and compiles to an empty lib there.

The fix

A plain fn where the lifetime is written down once — the same helper shape the add_host.rs and library.rs test modules already use:

fn ctx<'a>(
    platform: Platform,
    settings: &'a mut Settings,
    library: &'a crate::library::LibraryShared,
    pads: &'a [PadInfo],
) -> Ctx<'a> {  }

One file, +23/−13, test-only. No shipping code touched.

Checks

All in the punktfunk-rust-ci image, since macOS checks nothing here:

  • cargo clippy -p pf-console-ui --all-targets -- -D warnings — clean (this is the same lib test target CI failed on)
  • cargo test -p pf-console-ui — 185 passed, 0 failed, 1 ignored
  • cargo fmt -p pf-console-ui -- --check — clean

Base

Targets worktree-release-next-prep, not mainscreens/controllers.rs only exists on the release branch, so this is the only base it applies to. Merging it turns #320's clippy leg green.

Unblocks the red clippy leg on #320. ## What broke `crates/pf-console-ui/src/screens/controllers.rs` built its test `Ctx` from a closure: ```rust let ctx = |platform, settings: &mut Settings| Ctx { … }; ``` A closure cannot be generic over the lifetime in its **return** type, so the `Ctx<'2>` it produced could never be tied to the `&mut Settings<'1>` it borrows: ``` error: lifetime may not live long enough --> crates/pf-console-ui/src/screens/controllers.rs:411:55 | returning this value requires that `'1` must outlive `'2` error: could not compile `pf-console-ui` (lib test) ``` Nothing platform-specific about it — it just never compiled on any target that builds this crate. It went unnoticed on macOS because `pf-console-ui` is `cfg`-gated to linux/windows/android and compiles to an empty lib there. ## The fix A plain `fn` where the lifetime is written down once — the same helper shape the `add_host.rs` and `library.rs` test modules already use: ```rust fn ctx<'a>( platform: Platform, settings: &'a mut Settings, library: &'a crate::library::LibraryShared, pads: &'a [PadInfo], ) -> Ctx<'a> { … } ``` One file, +23/−13, test-only. No shipping code touched. ## Checks All in the `punktfunk-rust-ci` image, since macOS checks nothing here: - `cargo clippy -p pf-console-ui --all-targets -- -D warnings` — clean (this is the same `lib test` target CI failed on) - `cargo test -p pf-console-ui` — 185 passed, 0 failed, 1 ignored - `cargo fmt -p pf-console-ui -- --check` — clean ## Base Targets `worktree-release-next-prep`, not `main` — `screens/controllers.rs` only exists on the release branch, so this is the only base it applies to. Merging it turns #320's clippy leg green.
enricobuehler changed target branch from worktree-release-next-prep to main 2026-08-19 06:18:25 +00:00
enricobuehler added 1 commit 2026-08-19 06:18:25 +00:00
fix(console-ui): the controllers test builds its Ctx in a fn, not a closure
ci / bun-nix (pull_request) Successful in 31s
ci / web (pull_request) Successful in 1m7s
ci / docs-site (pull_request) Successful in 1m16s
windows-client / client (arm64, --no-default-features, aarch64-pc-windows-msvc, C:\t-a64) (pull_request) Successful in 3m36s
ci / rust-arm64 (pull_request) Successful in 4m13s
android / android (pull_request) Successful in 5m49s
windows-client / client (x64, , x86_64-pc-windows-msvc, C:\t) (pull_request) Successful in 6m52s
ci / rust (pull_request) Successful in 19m45s
fcdb2a53de
A closure cannot be generic over the lifetime in its return type, so the
`Ctx<'_>` this one built could never be tied to the `&mut Settings` it
borrows — `lifetime may not live long enough`, and the lib test target
failed to compile.

Same shape the add_host and library test modules already use: a plain
`fn ctx<'a>(…) -> Ctx<'a>` where the lifetime is written down once.
enricobuehler merged commit 6c32890014 into main 2026-08-19 06:18:43 +00:00
enricobuehler deleted branch worktree-console-ui-ctx-lifetime 2026-08-19 06:18:47 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unom/punktfunk#321