Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ generic std gap is planned here even when moq never calls it.
- [A box's clone_from, and a vector's AsRef and AsMut](/quest/m3/ts-box-vec-conversions.md) - `clone_from` of a `Box<String>` and `AsRef<[T]>` of a `Vec` translate
- [A std map with a crate's own BuildHasher](/quest/m3/ts-map-own-hasher.md) - std's and hashbrown's maps built with a crate's own hasher translate for keys that are JS objects
- [A crate's own hasher that JS copies](/quest/m3/ts-copied-hasher.md) - an enum `Hasher`, whose `&mut` is a place, hashes as a struct one does
- [A reference to a closure as a string pattern](/quest/m3/ts-closure-patterns.md) - `s.contains(&f)` and `s.split(&mut f)` translate, leaving the closure to its owner to drop
24 changes: 24 additions & 0 deletions quest/m3/ts-closure-patterns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# [S] A reference to a closure as a string pattern

## Goal

[rust2-ts](/ts/README.md) translates a `str` search given a reference to a closure as its
pattern, `s.contains(&f)` or `s.split(&mut f)`. The search calls the closure as std's does
and never drops it, which leaves the drop to its owner. Differential tests against native
Rust prove it, covering closures that own a value that drops and searches that return a
value and an iterator.

## Plan

Found in [#471](https://github.com/moq-dev/rust2/pull/471), which made a search drop a
closure it owns. A reference to one is refused as a pattern other than a `char`, a
`&str`, a predicate, or chars, as the README's list of what is refused says. std takes
`&F` for an `F: Fn` and `&mut F` for an `F: FnMut`, as each implements `FnMut`.

The closure drop logic that #471 extended already tells a lent closure from an owned one,
and wraps a lent one in `rt.lent` for an iterator that would drop what it holds. A
`&mut` to a function JS copies is that function's place. Watch that a lent closure is
neither dropped by the search nor by the iterator it returns, and drop the refusal from the
README once it translates.

Public API: the translator's output.