Skip to content

A use inside an f-string keeps a view alive: expr_uses_symbol walks interpolations (#1249, §21.1 rule 1) - #1254

Merged
ehartford merged 1 commit into
mainfrom
view-borrow-of-owned-root
Sep 21, 2026
Merged

ehartford merged 1 commit into
mainfrom
view-borrow-of-owned-root

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Fixes #1249.

let s = &v; v.push(..); print(f"{s.len()}") compiled and read through an invalidated view. The borrow was registered and check_mutation_against_views found it, but the liveness scan (find_last_use_in_block → expr_uses_symbol) had no NK_FSTRING arm: a view used only inside an interpolation looked dead at the mutation, so the borrow was dropped as stale instead of reported. Every other use shape (let k = s.len(), print(s.len())) was already diagnosed — the matrix isolated the f-string.

expr_uses_symbol now walks an f-string's EXPR segments. That exposed 24 sites in the compiler of one idiom — let name = self.pool_resolve(sym) (a &str view into self) followed by self.emit_error(f"…{name}…"), a mut self call while the view is live — rewritten mechanically (a With script over the diagnostics) to let name: str = …, an owned demand (D22 #781). A query showed no such sites outside src/.

Tests: err_view_of_local_used_after_mutation (Vec push), err_view_of_local_used_after_reassign (str), behav_view_of_local_dead_before_mutation (NLL: a borrow whose last use precedes the mutation stays legal).

Also filed on the way: #1253 (Sema accepts captures[1] on a struct with no index method; prints "" in an f-string).

Battery (seed-driven, worktree, ownership change alone): build, :fixpoint, :move-audit, :drop-audit, :test, :test-green, :last-green all rc=0.

…nterpolations (#1249, §21.1 rule 1)

`let s = &v; v.push(..); print(f"{s.len()}")` compiled and read through
an invalidated view. The borrow was registered and check_mutation_against_views
found it, but its liveness scan (find_last_use_in_block →
expr_uses_symbol) has no NK_FSTRING arm: a view used only inside an
interpolation looked dead at the mutation, so the borrow was removed as
stale instead of reported. Every other use shape (`let k = s.len()`,
`print(s.len())`) was diagnosed — the matrix isolated the f-string.

expr_uses_symbol now walks the EXPR segments of an f-string. That exposed
24 sites in the compiler of one idiom — `let name = self.pool_resolve(sym)`
(a view into self) followed by `self.emit_error(f"…{name}…")`, a `mut self`
call while the view is live — rewritten mechanically to
`let name: str = …` (an annotated binding is an owned demand, D22 #781).

Tests: err_view_of_local_used_after_mutation (Vec push), err_view_of_local_used_after_reassign (str),
behav_view_of_local_dead_before_mutation (NLL: a borrow whose last use precedes the mutation is fine).
ehartford added a commit that referenced this pull request Sep 21, 2026
A 504 from GitHub releases on the Windows x86_64 lane's LLVM SDK fetch
failed PR #1254 23 s in, before any With code ran. curl was invoked as
`curl -fL -o` with no retry on all eight fetches; each now retries five
times with a five-second delay on any transient error.

Co-authored-by: Eric Hartford <[email protected]>
@ehartford
ehartford merged commit caae06d into main Sep 21, 2026
5 of 6 checks passed
@ehartford
ehartford deleted the view-borrow-of-owned-root branch September 24, 2026 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

§21.1 rule 1 not enforced for a plain &local binding: mutate the place, then use the reference — no diagnostic

1 participant