Skip to content

feat(ts): translate a Box, Arc, or Rc of dyn Debug or dyn Display - #445

Merged
moq-bot[bot] merged 3 commits into
mainfrom
ts-dyn-fmt
Nov 2, 2026
Merged

moq-bot[bot] merged 3 commits into
mainfrom
ts-dyn-fmt

Conversation

@kixelated

@kixelated kixelated commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A &dyn Debug or &dyn Display translates as a function writing its value, but a Box, Arc, or Rc of one is refused where it is built, as "a trait object of another crate's trait". #247 found Arc<dyn Debug> refused, and the trait objects quest's goal names it. moq builds none today; this is std coverage the quest's plan calls for.

Approach

A Box<dyn Debug> or Box<dyn Display> is the same rt.Fmt a &dyn of its value is: rt.fmtOwned(value, write, drop), a function writing the value, whose [Symbol.dispose] drops it when it drops. An Arc or Rc of one goes through the existing rt.ArcDyn over what a box of its value makes, so the last pointer drops the value. An upcast that drops auto traits (Box<dyn Debug + Send> to Box<dyn Debug>) is the same function. An upcast from another trait object, and a &mut dyn Debug, stay refused.

Tests: fmt::objects in the lang fixture's differential test against native wasm32 covers boxes of dyn Debug and dyn Display over the crate's type, a tuple, a String, and a usize, written with {:?}, {:#?}, width, fill, and alignment. It drops them in order through a Vec's drop and truncate, and covers an upcast dropping Send. It shares one value as an Arc<dyn Debug + Send + Sync> and as an Rc<dyn Display> and an Rc<dyn Debug> of one Rc, checking counts and that the value drops with the last pointer, whichever it is.

Census at the moq pin: unchanged (976 / 232 / 141 for moq-net / model / kio), since moq builds none.

Impact

  • The translator's output: these pointers translate instead of failing. New runtime export rt.fmtOwned.
  • No breaking change.

Alternatives

  • An object with fmt$Debug, as the crate's own traits with a Debug supertrait get: a &dyn Debug is already an rt.Fmt, and Debug for Box<T>/Arc<T> forwards to it, so one representation serves all pointers.

Follow-ups

  • &mut dyn Debug, and an upcast from another trait object to dyn Debug (such as from dyn Error), stay refused.
  • Debug of a RefCell is an existing refusal, met while writing the fixture.

Review

mechanical fix by codex / Codex: Merged base preserving both sides of the harness conflict and regenerated its TypeScript snapshot; passed in ts/: UPDATE_EXPECT=1 cargo test --locked -p rust2-ts --test fixtures lang -- --exact; cargo test --locked -p rust2-ts --bin rust2-ts; cargo fmt --all --check; tsc -p runtime. (head a016fe3)

Codex gpt-6.1-sol at medium effort, via quest review, round 1 on head 519bc63038289e755df9f68d06b41e92837fc390: no findings.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 2, 2026 15:45
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fea1c977-26b5-4ccf-bb5d-abe5b677ba0f
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kixelated
kixelated enabled auto-merge (squash) November 2, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant