Skip to content

feat(ts): translate String + &str and Cow<str>'s + as += does - #479

Merged
kixelated merged 3 commits into
mainfrom
quest/m3/ts-string-add
Nov 3, 2026
Merged

kixelated merged 3 commits into
mainfrom
quest/m3/ts-string-add

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

rust2-ts refused String + &str ("unsupported call to <String as Add<&str>>::add") while += mapped. Cow<str>'s + and += (of a &str or another Cow<str>) were refused too, though a Cow<str> is the same JS string.

Approach

  • library.rs: Add::add whose Self is a JS string (String or Cow<str>) is JS + of the moved text. Library mappings only see std's impls, so a crate's own Add on String still calls the crate's.
  • call.rs: the push/push_str/add_assign arm now takes any std AddAssign on a JS string (Cow<str> included), and skips a crate's own impl AddAssign<Local> for String, which it used to swallow.
  • Differential tests against native Rust (lang/strs and lang/cows fixtures):
    • strs::edit: +=, mem::take(s) + &piece, a chain with "" and &&str, and String::with_capacity(a) + s through deref of the &mut String, over empty and multi-width text. The moved-from string's capacity reuse is unobservable, as capacity is refused.
    • strs::edits: + of the moved local itself.
    • cows: + and += of &str and Cow, including an empty left side, where std borrows the right side.
  • ts/README.md notes +.

Impact

  • Translator output: String + &str, Cow<str> + &str, Cow<str> + Cow<str>, and Cow<str> += &str | Cow<str> translate instead of being refused. No public Rust API change.

Alternatives

  • String only, per the quest's letter. Dropped: Cow<str>'s + is the same gap with the same representation, so leaving it would split one problem across PRs.

Follow-ups

Checks

  • just ci passed on 0f46b6c, merged with main at 3d37327.
  • Mutation check: swapping the + operands fails the native differential of lang::strs (1746 differences) and lang::cows (13).

Review

  • Reviewer: Codex, gpt-6.1-sol, medium effort (quest review), round 2.
  • Head: 0f46b6c
  • Findings: none.

🤖 Generated with Claude Code

kixelated and others added 2 commits November 2, 2026 19:42
Quest-Claim: e3a4eec625b7d82b
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Adding to a String feat(ts): translate String + &str and Cow<str>'s + as += does Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 04:13
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 15 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

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: c9d254b4-38dd-442e-962c-0205500f7642
Commits

Reviewing files that changed from the base of the PR and between 3d37327 and 0f46b6c.

Files selected for processing: 11
  • quest/m3/README.md
  • quest/m3/ts-operator-paths.md
  • quest/m3/ts-reassigned-pop.md
  • quest/m3/ts-string-add.md
  • ts/README.md
  • ts/fixtures/lang/cows/expected/cows.ts
  • ts/fixtures/lang/cows/src/cows.rs
  • ts/fixtures/lang/strs/expected/strs.ts
  • ts/fixtures/lang/strs/src/strs.rs
  • ts/src/lower/library.rs
  • ts/src/lower/mir/call.rs
  • 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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

# Conflicts:
#	ts/fixtures/lang/cows/expected/cows.ts
@kixelated
kixelated enabled auto-merge November 3, 2026 04:48
@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit c8e0397 Nov 3, 2026
5 checks passed
@kixelated
kixelated deleted the quest/m3/ts-string-add branch November 3, 2026 04:55
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