From 11953991ab98774e00f87f3f81cbd1ac0a3fe4f4 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:46:29 -0700 Subject: [PATCH 1/4] chore(quest): claim quest/m2/ts-cow-str.md Quest-Claim: ec07ac14678c056c From 4532b2b5a23ddce8a83820f77945505501e9d970 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:20:52 -0700 Subject: [PATCH 2/4] feat(ts): translate Cow as a JS string A `Cow` is its text, borrowed or owned: constructing either variant, `Deref`, `AsRef`, `From` and `Into` between strings, `into_owned`, `Clone`, `ToString`, `Default`, `Display`, `Debug`, comparisons, ordering, hashing, and keys all treat it as a `String`. `to_mut` borrows the `Cow`'s own place, so `push` through it assigns the longer text there. Code that tells the variants apart, a match on them or `Cow::is_borrowed`, is refused with its span, as is a `Cow` of other than `str`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- quest/m2/README.md | 1 - quest/m2/ts-cow-str.md | 19 -- ts/README.md | 16 +- ts/fixtures/lang/expected/cows.Named.ts | 77 +++++ ts/fixtures/lang/expected/cows.ts | 161 +++++++++ ts/fixtures/lang/expected/harness.ts | 7 +- ts/fixtures/lang/src/cows.rs | 161 +++++++++ ts/fixtures/lang/src/harness.rs | 7 +- ts/fixtures/lang/src/lib.rs | 7 +- ts/fixtures/lang/src/strs.rs | 2 +- ts/fixtures/reject/census.md | 418 +++++++++++++----------- ts/fixtures/reject/expected.txt | 146 +++++---- ts/fixtures/reject/src/lib.rs | 18 + ts/fixtures/reject/ts.toml | 3 + ts/src/lower/body.rs | 2 +- ts/src/lower/collections.rs | 16 +- ts/src/lower/consts.rs | 2 +- ts/src/lower/fmt.rs | 4 +- ts/src/lower/iter.rs | 6 +- ts/src/lower/library.rs | 41 ++- ts/src/lower/mir/call.rs | 12 + ts/src/lower/mir/place.rs | 2 + ts/src/lower/mir/rvalue.rs | 3 + ts/src/lower/mod.rs | 5 + ts/src/lower/task.rs | 4 +- 25 files changed, 816 insertions(+), 324 deletions(-) delete mode 100644 quest/m2/ts-cow-str.md create mode 100644 ts/fixtures/lang/expected/cows.Named.ts create mode 100644 ts/fixtures/lang/expected/cows.ts create mode 100644 ts/fixtures/lang/src/cows.rs diff --git a/quest/m2/README.md b/quest/m2/README.md index 85b9233b7..418faaac5 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -37,7 +37,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md); - [Share what the crate never changes in place](/quest/m2/ts-shared-read.md) - copies of `Copy` aggregates no one writes into in place go away, recovering #83's decode cost - [Output tsc accepts for writes through Result and Poll compares](/quest/m2/ts-tsc-shapes.md) - two shapes whose output fails `tsc` type-check - [Default comparison methods](/quest/m2/ts-cmp-defaults.md) - inherited `ne`, `lt`, `le`, `gt`, `ge` and `[u8]` equality translate -- [Copy-on-write strings](/quest/m2/ts-cow-str.md) - `Cow` translates, finishing `ietf/namespace.rs` - [str slicing and &str patterns](/quest/m2/ts-str-slice.md) - `&s[a..b]` and `&str` patterns translate, so `rfind`'s offsets are usable - [Translate moq-net's model to TypeScript](/quest/m2/ts-model.md) - the driver grows from moq-net's codec to its model, for moq to compare against WASM - [Waiting: Swift 6.4 in nixpkgs-unstable](/quest/m2/uniffi-swift-arm.md) - the nightly UniFFI fixtures move back to arm diff --git a/quest/m2/ts-cow-str.md b/quest/m2/ts-cow-str.md deleted file mode 100644 index 3332f4007..000000000 --- a/quest/m2/ts-cow-str.md +++ /dev/null @@ -1,19 +0,0 @@ -# [M] Copy-on-write strings - -## Goal - -rust2-ts translates `Cow`, so moq-net's `ietf/namespace.rs` translates with no -refusals, proven by differential tests against native Rust. - -## Plan - -Found by [#96](https://github.com/kixelated/rust2/pull/96) on 2026-10-27: after `str`'s -char methods translate, ` as From<&str>>::from` is `namespace.rs`'s last -refusal, and `Cow` accounts for 139 of moq-net's. - -- Choose the representation with the maintainer: a plain JS string, since `str` is - immutable in the output, or a tagged value that keeps `Cow::Borrowed` and - `Cow::Owned` apart for `matches!` and `is_borrowed`. -- Report moq-net's census before and after. - -Public API: the translator's output. diff --git a/ts/README.md b/ts/README.md index d01719fd7..52a1110b6 100644 --- a/ts/README.md +++ b/ts/README.md @@ -56,7 +56,7 @@ in `rt/str.ts`, collections in `rt/collections.ts`, and ownership and async in | Rust | TypeScript | | --- | --- | -| `bool`, `str`, `String` | `boolean`, `string` | +| `bool`, `str`, `String`, `Cow` | `boolean`, `string` | | `char` | `rt.char`: a `number` branded so, its Unicode scalar value | | `u8`-`u32`, `i8`-`i32`, `usize`, `isize` | `rt.u8` and so on: a `number` branded with its type, checked: overflow panics | | `u64`, `i64`, `u128`, `i128` | `rt.u64` and so on: a branded `number` while a safe integer, 32-bit limbs past 2^53, checked the same way | @@ -133,7 +133,9 @@ A `str` is a JS string, which is UTF-16: `chars` steps by code point, and a sear which it calls on each char it reads, in the order std reads them. An offset it returns, from `rfind` or `match_indices`, counts UTF-8 bytes, as Rust's does. A JS string can't change in place, so `String::push` assigns a longer one to the local or field the `&mut` -borrows. +borrows. A `Cow` is its text, borrowed or owned, so `to_mut` borrows the `Cow`'s own +place, and code that tells its variants apart, a `match` on them or `Cow::is_borrowed`, is +refused. Functions and members are camelCase. Functions are monomorphized: each instance is its own function, suffixed after a `$` by its trait, then by its type's type arguments and @@ -266,6 +268,9 @@ they need. function of it is one instance's, typed by its `self`. A type per instance (`Wrap$Pair`) would rename the type for callers, and TS generics with trait dictionaries would undo monomorphization. +- A `Cow` is a JS string, as `str` and `String` are, rather than an object tagged by + its variant: no `Cow` in moq-net or kio tells its variants apart, and a tag would + wrap every value and unwrap it at every read. - `Result` is a plain `{ ok, value } | { ok, error }` object rather than an exception, so `?` and `match` keep Rust's control flow exactly. Making no `Ok` objects at all measured no faster on `just ts bench`, in V8 or JavaScriptCore. @@ -315,8 +320,8 @@ bind to hand-written TS through config ([model](/quest/m2/ts-model.md)). These fail translation: floats, statics, async blocks that borrow a number mutably and async closures, values that drop in a closure dropped without a call that -takes it or in an iterator ([Drop](/quest/m2/ts-drop.md)), a collection holding a type that can be -`undefined`, as `()` and `Option` can, a collection's `capacity`, looking up a key by +takes it or in an iterator ([Drop](/quest/m2/ts-drop.md)), a `Cow` of other than `str`, +a collection holding a type that can be `undefined`, as `()` and `Option` can, a collection's `capacity`, looking up a key by another type it borrows as through the crate's own `Borrow`, a `&mut` to a value a map holds that JS copies kept other than to read and write it, `Hasher::write` of bytes, the adaptors without a mapping in `src/lower/iter.rs` (such as `cycle`, `unzip`, and `partition`), an @@ -349,7 +354,8 @@ built natively for wasm32 and run beside its translation on the same inputs by Bun bundles a caller of `Decoder.u8` and `Decoder.new` through `import * as Decoder`, which must keep only those and what they call. - `lang` covers every integer width's arithmetic and casts, `char`s next to each - encoding's edges and the surrogates, control flow, patterns, `Copy` aggregates, those + encoding's edges and the surrogates, `Cow` borrowed and owned, control flow, + patterns, `Copy` aggregates, those a container stores included, formatting, methods on generic types, iterators, with closures that log what each adaptor reads, and std's collections, over keys whose own `Hash`, `Eq`, and `Ord` diff --git a/ts/fixtures/lang/expected/cows.Named.ts b/ts/fixtures/lang/expected/cows.Named.ts new file mode 100644 index 000000000..cd191bed0 --- /dev/null +++ b/ts/fixtures/lang/expected/cows.Named.ts @@ -0,0 +1,77 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; + +export function clone$Clone(self: Named): Named { + return { name: self.name, id: self.id }; +} + +export function fmt$Debug(self: Named, f: rt.Formatter): rt.Result { + const _3: string = "Named"; + const _4: string = "name"; + const _5: rt.Fmt = (f: rt.Formatter) => rt.fmtStr(self.name, f); + const _7: string = "id"; + const _8: rt.Fmt = (f: rt.Formatter) => rt.u8Display(self.id, f); + return rt.debugStructFinish(rt.debugStructField(rt.debugStructField(rt.fmtDebugStruct(f, _3), _4, _5), _7, _8)); +} + +export function default$Default(): Named { + return { name: "", id: 0 }; +} + +export function eq$PartialEq(self: Named, other: Named): boolean { + if (!(self.id === other.id)) { + return false; + } + return self.name === other.name; +} + +export function hash$Hash_DefaultHasher(self: Named, state: rt.Hasher): void { + rt.hashStr(self.name, state); + rt.hashInt(self.id, state); +} + +export function partialCmp$PartialOrd(self: Named, other: Named): rt.Ordering | undefined { + return cmp$Ord(self, other); +} + +export function cmp$Ord(self: Named, other: Named): rt.Ordering { + const cmp: rt.Ordering = rt.cmpStr(self.name, other.name); + if (cmp === 0) { + return rt.cmp(self.id, other.id); + } + return cmp; +} + +/** A `Cow` in a field, with each derived impl reading it. */ +export interface Named { + name: string; + id: rt.u8; +} + +/** Borrowed unless it has to make the text, as moq-net's `Relative::new` is. */ +function new_(s: string, id: rt.u8): Named { + let name!: string; + const trimmed: string = rt.strTrimEndMatches(s, "/"); + if (!((trimmed.length === 0))) { + name = trimmed; + } else { + const arg = ([id] as [rt.u8])[0]; + const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.u8Display(arg, f)]; + name = rt.fmtFormat(["#", args2[0]]); + } + return { name, id }; +} + +/** Through `to_mut` of the field. */ +export function tag(self: Named, c: rt.char): void { + self.name = self.name + String.fromCodePoint(c); +} + +export function intoOwned(self: Named): Named { + return { name: self.name, id: self.id }; +} + +export { new_ as new }; + +//# sourceMappingURL=cows.Named.ts.map diff --git a/ts/fixtures/lang/expected/cows.ts b/ts/fixtures/lang/expected/cows.ts new file mode 100644 index 000000000..e16be4204 --- /dev/null +++ b/ts/fixtures/lang/expected/cows.ts @@ -0,0 +1,161 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import * as Named from "./cows.Named.ts"; +import { put } from "./fmt.ts"; +import { text } from "./strs.ts"; + +export function cow(s: string, owned: boolean): string { + if (!owned) { + return s; + } + return s; +} + +export function cows(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { + let shared!: rt.Arc; + let unwind: number = 0; + try { + const s: string = text(data); + const owned: boolean = (kind & 128) !== 0; + const _10: rt.Iter = rt.strSplit(s, "/"); + const first: string = rt.optionUnwrapOr(rt.iterToOption(_10.next()), ""); + const _14: rt.u8 = rt.u8Rem(kind, 6); + if (_14 === 0) { + const c: string = cow(s, owned); + rt.byteVecPush(out, rt.stringLen(c) & 0xff); + rt.byteVecPush(out, c.length === 0 ? 1 : 0); + rt.byteVecPush(out, rt.iterCount(rt.strChars(c)) & 0xff); + put(out, c); + put(out, c); + put(out, c); + put(out, c); + put(out, c); + put(out, ""); + put(out, "fallback"); + put(out, s); + shared = new rt.Arc(s); + unwind = 256; + put(out, shared.value); + const _80: rt.Iter = rt.strSplit(s, "\\"); + const part: string = rt.optionUnwrapOr(rt.optionMap(rt.iterNth(_80, 1), (a03: string): string => { + return a03; + }), "fallback"); + unwind = 255; + put(out, part); + const into: string = cow(first, owned); + unwind = 254; + put(out, into); + const fromStr: string = first; + unwind = 253; + put(out, fromStr); + unwind = 0; + rt.drop(shared); + } else if (_14 === 1) { + let c2: string = cow(s, owned); + c2 = c2 + "!"; + c2 = c2 + "?"; + c2 = c2 + "𐀀"; + put(out, c2); + put(out, s); + const v: string[] = [cow(first, owned), cow(s, !owned)]; + const at = rt.idx(v, 1); + v[at] = v[at] + "v"; + const iterS: string[] = v; + let iterI: number = 0; + while (true) { + const _126: string | rt.Done = iterI < iterS.length ? iterS[iterI++] : rt.DONE; + if (_126 === rt.DONE) { + break; + } + put(out, _126); + } + put(out, c2); + } else if (_14 === 2) { + const a: string = cow(s, owned); + const b: string = cow(first, !owned); + const iter2: rt.Iter = rt.iterSlice([a === first, a === first, a === s, first === a, s === a, a === b, a !== b, rt.cmpStr(a, b) < 0, rt.cmpStr(a, b) >= 0, rt.cmpStr(a, b) === 1]); + while (true) { + const _179: boolean | rt.Done = iter2.next(); + if (_179 === rt.DONE) { + break; + } + rt.byteVecPush(out, _179 ? 1 : 0); + } + const _190: string = a; + const _191: string = b; + const _189: string = rt.ordMax(_190, _191, rt.cmpStr); + rt.byteVecPush(out, _189 === b ? 1 : 0); + } else if (_14 === 3) { + const n: Named.Named = Named.new(first, kind); + const m2: Named.Named = Named.clone$Clone(n); + Named.tag(n, 120); + const args2: rt.Fmt[] = [(f: rt.Formatter) => Named.fmt$Debug(n, f), (f: rt.Formatter) => Named.fmt$Debug(m2, f)]; + put(out, rt.fmtFormat([args2[0], " ", args2[1]])); + rt.byteVecPush(out, Named.eq$PartialEq(n, m2) ? 1 : 0); + rt.byteVecPush(out, Named.cmp$Ord(n, m2) > 0 ? 1 : 0); + rt.byteVecPush(out, Named.partialCmp$PartialOrd(n, m2) === -1 ? 1 : 0); + const o: Named.Named = Named.intoOwned(n); + put(out, o.name); + [Named.default$Default(), Named.new("", kind)] as [Named.Named, Named.Named]; + const arg4 = Named.default$Default(); + const _250: rt.Fmt = (f: rt.Formatter) => Named.fmt$Debug(arg4, f); + const arg5 = Named.new("", kind); + const args4: rt.Fmt[] = [_250, (f: rt.Formatter) => Named.fmt$Debug(arg5, f)]; + put(out, rt.fmtFormat([args4[0], " ", args4[1]])); + } else if (_14 === 4) { + const counts: rt.BTreeMap = rt.btreeNew(rt.cmpStr) as rt.BTreeMap; + const iter3: rt.Iter<[rt.usize, string]> = rt.iterEnumerate(rt.strSplit(s, "/")); + while (true) { + const _261: [rt.usize, string] | rt.Done = iter3.next(); + if (_261 === rt.DONE) { + break; + } + const _269: string = cow(_261[1], rt.usizeRem(_261[0], 2) === 1 === owned); + const place = rt.entryOrInsertMut(rt.entry(counts, _269), 0); + place.v = rt.u8Add(place.v, 1); + } + const iter4: rt.Iter<[string, rt.u8]> = rt.btreeIter(counts); + while (true) { + const _278: [string, rt.u8] | rt.Done = iter4.next(); + if (_278 === rt.DONE) { + break; + } + put(out, _278[0]); + rt.byteVecPush(out, _278[1]); + } + rt.byteVecPush(out, rt.optionUnwrapOr(rt.btreeGet(counts, first), 255)); + const names: rt.HashSet = rt.hashNew(rt.hashing(Named.hash$Hash_DefaultHasher, Named.eq$PartialEq)) as rt.HashSet; + const iter5: rt.Iter = rt.strSplit(s, "/"); + while (true) { + const _298: string | rt.Done = iter5.next(); + if (_298 === rt.DONE) { + break; + } + const _304: Named.Named = Named.new(_298, 0); + rt.hashAdd(names, _304); + } + rt.byteVecPush(out, rt.hashLen(names) & 0xff); + const _314: Named.Named = Named.new(first, 0); + rt.byteVecPush(out, rt.hashContains(names, _314) ? 1 : 0); + } else { + [cow(s, owned)] as [string]; + const arg = cow(s, owned); + const _327: rt.Fmt = (f: rt.Formatter) => rt.fmtPad(f, arg); + const arg2 = cow(s, owned); + const args6: rt.Fmt[] = [_327, (f: rt.Formatter) => rt.fmtStr(arg2, f)]; + put(out, rt.fmtFormat(["[", args6[0], "|", rt.fmtSpec({ align: ">", width: 6 }, args6[0]), "|", rt.fmtSpec({ align: "<", width: 5 }, args6[0]), "|", rt.fmtSpec({ align: "^", width: 7 }, args6[0]), "|", rt.fmtSpec({ fill: "*", align: "^", width: 3 }, args6[0]), "|", args6[1], "]"])); + const arg3 = ([cow(first, owned)] as [string | undefined])[0]; + const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtOption(arg3, f, rt.fmtStr)]; + put(out, rt.fmtFormat([args8[0]])); + } + } catch (e) { + if (unwind === 0) { + throw e; + } + rt.drop(shared); + throw e; + } +} + +//# sourceMappingURL=cows.ts.map diff --git a/ts/fixtures/lang/expected/harness.ts b/ts/fixtures/lang/expected/harness.ts index 3d9d0d683..e9081c64b 100644 --- a/ts/fixtures/lang/expected/harness.ts +++ b/ts/fixtures/lang/expected/harness.ts @@ -3,6 +3,7 @@ import * as rt from "./rt.ts"; import { chars } from "./chars.ts"; import { hashMaps, sets, btreeMaps, deques, vecs, stores } from "./collections.ts"; +import { cows } from "./cows.ts"; import { ints, strings, derived, written, panics } from "./fmt.ts"; import { methods } from "./generics.ts"; import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast, convert } from "./ints.ts"; @@ -20,7 +21,7 @@ export function run(input: rt.ByteSlice): rt.ByteVec { const _10: [rt.u8, rt.u8] = [input.data[input.start], input.data[input.start + 1]]; const op: rt.u8 = _10[0]; const kind: rt.u8 = _10[1]; - const _14: rt.u8 = rt.u8Rem(op, 44); + const _14: rt.u8 = rt.u8Rem(op, 45); if (_14 === 0) { u8Op(kind, rt.byteSliceRange(input, 2), out); } else if (_14 === 1) { @@ -125,8 +126,10 @@ export function run(input: rt.ByteSlice): rt.ByteVec { strs(kind, rt.byteSliceRange(input, 2), out); } else if (_14 === 42) { vecs(rt.byteSliceRange(input, 2), out); - } else { + } else if (_14 === 43) { stores(rt.byteSliceRange(input, 2), out); + } else { + cows(kind, rt.byteSliceRange(input, 2), out); } return out; } diff --git a/ts/fixtures/lang/src/cows.rs b/ts/fixtures/lang/src/cows.rs new file mode 100644 index 000000000..51a940b8a --- /dev/null +++ b/ts/fixtures/lang/src/cows.rs @@ -0,0 +1,161 @@ +//! `Cow`, borrowed and owned alike: made, read through `Deref`, compared, ordered, +//! hashed, printed, and held in a field and as a key, and changed through `to_mut`, which +//! leaves the text it borrowed as it was. Each case runs once borrowed and once owned. + +use std::borrow::Cow; +use std::cmp::Ordering; +use std::collections::{BTreeMap, HashSet}; +use std::sync::Arc; + +use crate::fmt::put; +use crate::strs::text; + +const FALLBACK: Cow<'static, str> = Cow::Borrowed("fallback"); + +/// A `Cow` in a field, with each derived impl reading it. +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] +struct Named<'a> { + name: Cow<'a, str>, + id: u8, +} + +impl<'a> Named<'a> { + /// Borrowed unless it has to make the text, as moq-net's `Relative::new` is. + fn new(s: &'a str, id: u8) -> Self { + let trimmed = s.trim_end_matches('/'); + let name = match trimmed.is_empty() { + true => Cow::Owned(format!("#{id}")), + false => Cow::Borrowed(trimmed), + }; + Self { name, id } + } + + /// Through `to_mut` of the field. + fn tag(&mut self, c: char) { + self.name.to_mut().push(c); + } + + fn into_owned(self) -> Named<'static> { + Named { + name: Cow::Owned(self.name.into_owned()), + id: self.id, + } + } +} + +fn cow(s: &str, owned: bool) -> Cow<'_, str> { + match owned { + true => Cow::Owned(s.to_string()), + false => s.into(), + } +} + +pub fn cows(kind: u8, data: &[u8], out: &mut Vec) { + let s = text(data); + let owned = kind & 0x80 != 0; + let first = s.split('/').next().unwrap_or(""); + match kind % 6 { + 0 => { + // What reads the text, and what makes one from it or out of it. + let c = cow(&s, owned); + out.push(c.len() as u8); + out.push(c.is_empty() as u8); + out.push(c.chars().count() as u8); + put(out, &c); + put(out, c.as_ref()); + put(out, &c.clone()); + put(out, &c.to_string()); + let held: String = c.into_owned(); + put(out, &held); + let empty: Cow<'_, str> = Default::default(); + put(out, &empty); + put(out, &FALLBACK); + let from_string: Cow<'_, str> = Cow::from(s.clone()); + put(out, &String::from(from_string)); + let from_ref: Cow<'_, str> = Cow::from(&s); + let shared: Arc = Arc::from(from_ref); + put(out, &shared); + let part = s.split('\\').nth(1).map(Cow::Borrowed).unwrap_or(FALLBACK); + put(out, &part); + let into: String = cow(first, owned).into(); + put(out, &into); + // The same conversions between a `str` and a `String`. + let from_str = String::from(first); + put(out, from_str.as_ref()); + } + 1 => { + // `to_mut` of a local, twice through one reference, and of a vector's element. + let mut c = cow(&s, owned); + c.to_mut().push('!'); + let m = c.to_mut(); + m.push('?'); + m.push('\u{10000}'); + put(out, &c); + put(out, &s); + let mut v = vec![cow(first, owned), cow(&s, !owned)]; + v[1].to_mut().push('v'); + for c in &v { + put(out, c); + } + put(out, &c.into_owned()); + } + 2 => { + // Comparisons with each string type, either way around, and ordering. + let a = cow(&s, owned); + let b = cow(first, !owned); + let bits = [ + a == *first, + a == first, + a == s, + first == a, + s == a, + a == b, + a != b, + a.cmp(&b).is_lt(), + a.cmp(&b).is_ge(), + a.partial_cmp(&b) == Some(Ordering::Greater), + ]; + for bit in bits { + out.push(bit as u8); + } + out.push((a.max(b.clone()) == b) as u8); + } + 3 => { + // A field: derived impls, `to_mut` through `&mut self`, and `into_owned`. + let mut n = Named::new(first, kind); + let m = n.clone(); + n.tag('x'); + put(out, &format!("{n:?} {m:?}")); + out.push((n == m) as u8); + out.push(n.cmp(&m).is_gt() as u8); + out.push((n.partial_cmp(&m) == Some(Ordering::Less)) as u8); + let o = n.into_owned(); + put(out, &o.name); + put(out, &format!("{:?} {:?}", Named::default(), Named::new("", kind))); + } + 4 => { + // Keys: counted in a B-tree, found by a `&str`, and a field's hash in a set. + let mut counts: BTreeMap, u8> = BTreeMap::new(); + for (i, part) in s.split('/').enumerate() { + *counts.entry(cow(part, (i % 2 == 1) == owned)).or_insert(0) += 1; + } + for (k, v) in &counts { + put(out, k); + out.push(*v); + } + out.push(counts.get(first).copied().unwrap_or(0xff)); + let mut names = HashSet::new(); + for part in s.split('/') { + names.insert(Named::new(part, 0)); + } + out.push(names.len() as u8); + out.push(names.contains(&Named::new(first, 0)) as u8); + } + _ => { + // Formatting, with the specs `str`'s take. + let c = cow(&s, owned); + put(out, &format!("[{c}|{c:>6}|{c:<5}|{c:^7}|{c:*^3}|{c:?}]")); + put(out, &format!("{:?}", Some(cow(first, owned)))); + } + } +} diff --git a/ts/fixtures/lang/src/harness.rs b/ts/fixtures/lang/src/harness.rs index 5430d8c80..4e513ffba 100644 --- a/ts/fixtures/lang/src/harness.rs +++ b/ts/fixtures/lang/src/harness.rs @@ -1,7 +1,7 @@ //! The entry point both sides of the differential test run. The first byte picks a //! case and the rest is its input. -use crate::{chars, collections, fmt, generics, ints, iters, keys, shapes, strs}; +use crate::{chars, collections, cows, fmt, generics, ints, iters, keys, shapes, strs}; /// The native side's entry: [`run`], except that a case starting with 0xff prints a /// [`fmt::Fault`], which the translated side prints from TypeScript in `caller.ts`. @@ -19,7 +19,7 @@ pub fn run(input: &[u8]) -> Vec { return out; }; let (op, kind) = (*op, *kind); - match op % 44 { + match op % 45 { 0 => ints::u8_op(kind, data, &mut out), 1 => ints::u16_op(kind, data, &mut out), 2 => ints::u32_op(kind, data, &mut out), @@ -73,7 +73,8 @@ pub fn run(input: &[u8]) -> Vec { 40 => chars::chars(kind, data, &mut out), 41 => strs::strs(kind, data, &mut out), 42 => collections::vecs(data, &mut out), - _ => collections::stores(data, &mut out), + 43 => collections::stores(data, &mut out), + _ => cows::cows(kind, data, &mut out), } out } diff --git a/ts/fixtures/lang/src/lib.rs b/ts/fixtures/lang/src/lib.rs index af8569eda..e5c95d016 100644 --- a/ts/fixtures/lang/src/lib.rs +++ b/ts/fixtures/lang/src/lib.rs @@ -1,13 +1,14 @@ //! The language the driver translates, exercised against native Rust: every integer -//! width's arithmetic and casts, `char`s and the `str` methods over them, control flow, -//! patterns, `Copy` aggregates, closures, traits, generic types, formatting, collections, -//! and the standard library calls it maps. +//! width's arithmetic and casts, `char`s and the `str` methods over them, `Cow`, +//! control flow, patterns, `Copy` aggregates, closures, traits, generic types, formatting, +//! collections, and the standard library calls it maps. //! //! `harness::run` is the entry point both sides of the differential test run, and //! `fmt::Fault` an error only `caller.ts` prints. mod chars; mod collections; +mod cows; mod fmt; mod generics; pub mod harness; diff --git a/ts/fixtures/lang/src/strs.rs b/ts/fixtures/lang/src/strs.rs index 48a5c1c34..e53c02fdb 100644 --- a/ts/fixtures/lang/src/strs.rs +++ b/ts/fixtures/lang/src/strs.rs @@ -26,7 +26,7 @@ const ALPHABET: [char; 16] = [ ]; /// A char of the alphabet for each byte, by its low bits. -fn text(data: &[u8]) -> String { +pub fn text(data: &[u8]) -> String { let mut s = String::new(); for &b in data { s.push(ALPHABET[(b % 16) as usize]); diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index 006ab4684..a701a7aa3 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,52 +1,54 @@ # Census of `reject-fixture` -- Refusals: 74 -- Function instances: 61 +- Refusals: 80 +- Function instances: 64 - Generic functions no instance reached, lowered over their type parameters: 2 ## By construct | Count | Construct | First | | ---: | --- | --- | -| 7 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:16:2 | -| 7 | unsupported call to `_` | fixtures/reject/src/lib.rs:32:4 | -| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:27:15 | -| 6 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:15:13 | -| 4 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:107:2 | -| 4 | unsupported type `_` | fixtures/reject/src/lib.rs:6:14 | -| 3 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:55:2 | -| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:127:20 | -| 2 | a field of `_` | fixtures/reject/src/lib.rs:289:7 | -| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:186:1 | -| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:172:23 | -| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:166:2 | -| 1 | `Binary` formatting, as in `{:b}`, is not supported | fixtures/reject/src/lib.rs:84:3 | -| 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:86:3 | -| 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:85:3 | -| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:89:3 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:294:6 | -| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:317:6 | -| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:349:2 | -| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | fixtures/reject/src/lib.rs:359:6 | -| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:325:9 | -| 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:118:2 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:199:51 | -| 1 | a coercion to `_` | fixtures/reject/src/lib.rs:372:2 | -| 1 | a constant of type `_` | fixtures/reject/src/lib.rs:102:2 | -| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:283:14 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:258:13 | -| 1 | a precision, as in `{:.2}`, is not supported | fixtures/reject/src/lib.rs:81:3 | -| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:114:1 | -| 1 | a scalar constant of type `_` | fixtures/reject/src/lib.rs:7:2 | -| 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:88:3 | -| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:74:2 | -| 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:7:2 | -| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:299:52 | -| 1 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:50:1 | -| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:299:52 | -| 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:87:3 | -| 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:82:3 | -| 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:83:3 | +| 8 | unsupported call to `_` | fixtures/reject/src/lib.rs:33:4 | +| 7 | an assignment through a reference to `_` | fixtures/reject/src/lib.rs:17:2 | +| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | fixtures/reject/src/lib.rs:28:15 | +| 6 | `_`: a JS value of `_` is a copy, so a reference can't change it | fixtures/reject/src/lib.rs:16:13 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | fixtures/reject/src/lib.rs:388:2 | +| 4 | replacing the value behind a reference to `_` | fixtures/reject/src/lib.rs:108:2 | +| 4 | unsupported type `_` | fixtures/reject/src/lib.rs:7:14 | +| 3 | an iterator that owns `_`, which drops, which is not supported yet | fixtures/reject/src/lib.rs:56:2 | +| 2 | `_` is not supported: it would be pending two ways with one value | fixtures/reject/src/lib.rs:128:20 | +| 2 | a field of `_` | fixtures/reject/src/lib.rs:290:7 | +| 2 | an iterator of the crate implementing `_`, which is not supported yet | fixtures/reject/src/lib.rs:187:1 | +| 2 | constructing `_` from another crate | fixtures/reject/src/lib.rs:173:23 | +| 2 | overriding `_`, which std's adaptors call in place of `next` or beside it | fixtures/reject/src/lib.rs:167:2 | +| 1 | `Binary` formatting, as in `{:b}`, is not supported | fixtures/reject/src/lib.rs:85:3 | +| 1 | `LowerExp` formatting, as in `{:e}`, is not supported | fixtures/reject/src/lib.rs:87:3 | +| 1 | `Octal` formatting, as in `{:o}`, is not supported | fixtures/reject/src/lib.rs:86:3 | +| 1 | `Pointer` formatting, as in `{:p}`, is not supported | fixtures/reject/src/lib.rs:90:3 | +| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | fixtures/reject/src/lib.rs:295:6 | +| 1 | `_` is not supported yet | fixtures/reject/src/lib.rs:399:18 | +| 1 | `_` of `_` by `_`, which is not supported yet | fixtures/reject/src/lib.rs:318:6 | +| 1 | `_` through a held type's own, which is not supported yet | fixtures/reject/src/lib.rs:350:2 | +| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | fixtures/reject/src/lib.rs:360:6 | +| 1 | `_`, which is not supported yet | fixtures/reject/src/lib.rs:326:9 | +| 1 | a `_` cast from `_` to `_` | fixtures/reject/src/lib.rs:119:2 | +| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | fixtures/reject/src/lib.rs:200:51 | +| 1 | a coercion to `_` | fixtures/reject/src/lib.rs:373:2 | +| 1 | a constant of type `_` | fixtures/reject/src/lib.rs:103:2 | +| 1 | a copy of a closure that changes what it captured | fixtures/reject/src/lib.rs:284:14 | +| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | fixtures/reject/src/lib.rs:259:13 | +| 1 | a precision, as in `{:.2}`, is not supported | fixtures/reject/src/lib.rs:82:3 | +| 1 | a printable type must implement `Display` or `Debug` | fixtures/reject/src/lib.rs:115:1 | +| 1 | a scalar constant of type `_` | fixtures/reject/src/lib.rs:8:2 | +| 1 | a width or precision from an argument, as in `{:1$}`, is not supported | fixtures/reject/src/lib.rs:89:3 | +| 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:75:2 | +| 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:8:2 | +| 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:300:52 | +| 1 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:51:1 | +| 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:300:52 | +| 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:88:3 | +| 1 | the `+` flag of a format spec is not supported | fixtures/reject/src/lib.rs:83:3 | +| 1 | the `-` flag of a format spec is not supported | fixtures/reject/src/lib.rs:84:3 | ## By API @@ -54,360 +56,380 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | -| 6 | `Option` | fixtures/reject/src/lib.rs:27:15 | -| 6 | `f64` | fixtures/reject/src/lib.rs:6:14 | -| 6 | `u8` | fixtures/reject/src/lib.rs:64:10 | -| 4 | `std::string::String` | fixtures/reject/src/lib.rs:94:16 | -| 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:55:2 | -| 4 | `u32` | fixtures/reject/src/lib.rs:15:13 | -| 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:123:2 | -| 2 | `Iterator` | fixtures/reject/src/lib.rs:166:2 | -| 2 | `Meters` | fixtures/reject/src/lib.rs:107:2 | -| 2 | `Poll` | fixtures/reject/src/lib.rs:127:20 | -| 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:294:6 | -| 2 | `std::option::Option` | fixtures/reject/src/lib.rs:294:6 | -| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:143:2 | -| 2 | `std::slice` | fixtures/reject/src/lib.rs:32:4 | -| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:186:1 | -| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:240:1 | -| 1 | `HashMap` | fixtures/reject/src/lib.rs:317:6 | -| 1 | `Hasher` | fixtures/reject/src/lib.rs:325:9 | -| 1 | `IntToFloat` | fixtures/reject/src/lib.rs:118:2 | -| 1 | `Noisy` | fixtures/reject/src/lib.rs:253:20 | -| 1 | `[u8; 1]` | fixtures/reject/src/lib.rs:272:22 | -| 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:10:16 | -| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:199:51 | -| 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:172:23 | -| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:193:14 | -| 1 | `std::mem` | fixtures/reject/src/lib.rs:48:18 | -| 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:289:48 | -| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:289:7 | -| 1 | `std::ops::Range` | fixtures/reject/src/lib.rs:207:8 | -| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:153:11 | -| 1 | `std::str` | fixtures/reject/src/lib.rs:382:4 | -| 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:148:2 | -| 1 | `u64` | fixtures/reject/src/lib.rs:118:2 | -| 1 | `{async closure}` | fixtures/reject/src/lib.rs:74:2 | +| 6 | `Option` | fixtures/reject/src/lib.rs:28:15 | +| 6 | `f64` | fixtures/reject/src/lib.rs:7:14 | +| 6 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:388:2 | +| 6 | `u8` | fixtures/reject/src/lib.rs:65:10 | +| 4 | `std::string::String` | fixtures/reject/src/lib.rs:95:16 | +| 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:56:2 | +| 4 | `u32` | fixtures/reject/src/lib.rs:16:13 | +| 3 | `std::sync::Arc` | fixtures/reject/src/lib.rs:124:2 | +| 2 | `Iterator` | fixtures/reject/src/lib.rs:167:2 | +| 2 | `Meters` | fixtures/reject/src/lib.rs:108:2 | +| 2 | `Poll` | fixtures/reject/src/lib.rs:128:20 | +| 2 | `std::collections::HashMap` | fixtures/reject/src/lib.rs:295:6 | +| 2 | `std::option::Option` | fixtures/reject/src/lib.rs:295:6 | +| 2 | `std::pin::Pin` | fixtures/reject/src/lib.rs:144:2 | +| 2 | `std::slice` | fixtures/reject/src/lib.rs:33:4 | +| 1 | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:187:1 | +| 1 | `FusedIterator` | fixtures/reject/src/lib.rs:241:1 | +| 1 | `HashMap` | fixtures/reject/src/lib.rs:318:6 | +| 1 | `Hasher` | fixtures/reject/src/lib.rs:326:9 | +| 1 | `IntToFloat` | fixtures/reject/src/lib.rs:119:2 | +| 1 | `Noisy` | fixtures/reject/src/lib.rs:254:20 | +| 1 | `[u8; 1]` | fixtures/reject/src/lib.rs:273:22 | +| 1 | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | +| 1 | `std::iter::Chain` | fixtures/reject/src/lib.rs:200:51 | +| 1 | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | +| 1 | `std::iter::Rev` | fixtures/reject/src/lib.rs:194:14 | +| 1 | `std::mem` | fixtures/reject/src/lib.rs:49:18 | +| 1 | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:290:48 | +| 1 | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:290:7 | +| 1 | `std::ops::Range` | fixtures/reject/src/lib.rs:208:8 | +| 1 | `std::slice::Iter` | fixtures/reject/src/lib.rs:154:11 | +| 1 | `std::str` | fixtures/reject/src/lib.rs:383:4 | +| 1 | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:149:2 | +| 1 | `u64` | fixtures/reject/src/lib.rs:119:2 | +| 1 | `{async closure}` | fixtures/reject/src/lib.rs:75:2 | ## By type or path | Count | Construct | Type or path | First | | ---: | --- | --- | --- | -| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:27:15 | -| 3 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:6:14 | -| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:127:20 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut std::string::String`, `std::string::String` | fixtures/reject/src/lib.rs:94:16 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u32`, `u32` | fixtures/reject/src/lib.rs:15:13 | -| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:64:10 | -| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:143:2 | -| 2 | an assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:65:3 | -| 2 | an iterator that owns `_`, which drops, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:55:2 | -| 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:107:2 | -| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:294:6 | -| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:317:6 | -| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:349:2 | -| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | `std::option::Option` | fixtures/reject/src/lib.rs:359:6 | -| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:325:9 | -| 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:118:2 | -| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:199:51 | -| 1 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:372:2 | -| 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:102:2 | -| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:289:48 | -| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:289:7 | -| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:258:13 | -| 1 | a scalar constant of type `_` | `f64` | fixtures/reject/src/lib.rs:7:2 | -| 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:74:2 | -| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:123:2 | -| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:148:2 | -| 1 | an assignment through a reference to `_` | `u32` | fixtures/reject/src/lib.rs:16:2 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:186:1 | -| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:240:1 | -| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:253:20 | -| 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:7:2 | -| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:299:52 | -| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:172:23 | -| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:193:14 | -| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:299:52 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:166:2 | -| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:220:2 | -| 1 | replacing the value behind a reference to `_` | `[u8; 1]` | fixtures/reject/src/lib.rs:272:22 | -| 1 | replacing the value behind a reference to `_` | `std::string::String` | fixtures/reject/src/lib.rs:377:4 | -| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:153:11 | -| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:96:10 | -| 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:48:18 | -| 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:207:8 | -| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:367:4 | -| 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:32:4 | -| 1 | unsupported call to `_` | `std::str::split` | fixtures/reject/src/lib.rs:382:4 | -| 1 | unsupported type `_` | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:10:16 | +| 6 | `_` is not supported: its `None` and `Some` would both be `undefined` | `Option` | fixtures/reject/src/lib.rs:28:15 | +| 4 | a variant of `_`, which is not supported: either is the same JS string | `std::borrow::Cow` | fixtures/reject/src/lib.rs:388:2 | +| 3 | unsupported type `_` | `f64` | fixtures/reject/src/lib.rs:7:14 | +| 2 | `_` is not supported: it would be pending two ways with one value | `Poll` | fixtures/reject/src/lib.rs:128:20 | +| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut std::string::String`, `std::string::String` | fixtures/reject/src/lib.rs:95:16 | +| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u32`, `u32` | fixtures/reject/src/lib.rs:16:13 | +| 2 | `_`: a JS value of `_` is a copy, so a reference can't change it | `&mut u8`, `u8` | fixtures/reject/src/lib.rs:65:10 | +| 2 | an assignment through a reference to `_` | `std::pin::Pin` | fixtures/reject/src/lib.rs:144:2 | +| 2 | an assignment through a reference to `_` | `u8` | fixtures/reject/src/lib.rs:66:3 | +| 2 | an iterator that owns `_`, which drops, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:56:2 | +| 2 | replacing the value behind a reference to `_` | `Meters` | fixtures/reject/src/lib.rs:108:2 | +| 1 | `_` holds `_`, which is `undefined` as `None` is, which is not supported | `std::collections::HashMap`, `std::option::Option` | fixtures/reject/src/lib.rs:295:6 | +| 1 | `_` is not supported yet | `std::borrow::Cow` | fixtures/reject/src/lib.rs:399:18 | +| 1 | `_` of `_` by `_`, which is not supported yet | `HashMap::contains_key`, `std::collections::HashMap`, `u8` | fixtures/reject/src/lib.rs:318:6 | +| 1 | `_` through a held type's own, which is not supported yet | `::ne` | fixtures/reject/src/lib.rs:350:2 | +| 1 | `_`, a mutable reference to a value a map holds, kept other than to read and write it | `std::option::Option` | fixtures/reject/src/lib.rs:360:6 | +| 1 | `_`, which is not supported yet | `Hasher::write` | fixtures/reject/src/lib.rs:326:9 | +| 1 | a `_` cast from `_` to `_` | `IntToFloat`, `u64`, `f64` | fixtures/reject/src/lib.rs:119:2 | +| 1 | a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` | `std::iter::Chain` | fixtures/reject/src/lib.rs:200:51 | +| 1 | a coercion to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:373:2 | +| 1 | a constant of type `_` | `&u8` | fixtures/reject/src/lib.rs:103:2 | +| 1 | a field of `_` | `std::ops::RangeFrom` | fixtures/reject/src/lib.rs:290:48 | +| 1 | a field of `_` | `std::ops::RangeTo` | fixtures/reject/src/lib.rs:290:7 | +| 1 | a mutable borrow of a subslice of `_`, which JS would copy, having no views | `u32` | fixtures/reject/src/lib.rs:259:13 | +| 1 | a scalar constant of type `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | +| 1 | a zero-sized constant of type `_` | `{async closure}` | fixtures/reject/src/lib.rs:75:2 | +| 1 | an assignment through a reference to `_` | `std::sync::Arc` | fixtures/reject/src/lib.rs:124:2 | +| 1 | an assignment through a reference to `_` | `std::sync::MutexGuard` | fixtures/reject/src/lib.rs:149:2 | +| 1 | an assignment through a reference to `_` | `u32` | fixtures/reject/src/lib.rs:17:2 | +| 1 | an iterator of the crate implementing `_`, which is not supported yet | `DoubleEndedIterator` | fixtures/reject/src/lib.rs:187:1 | +| 1 | an iterator of the crate implementing `_`, which is not supported yet | `FusedIterator` | fixtures/reject/src/lib.rs:241:1 | +| 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:254:20 | +| 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | +| 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:300:52 | +| 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | +| 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:194:14 | +| 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:300:52 | +| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::fold` | fixtures/reject/src/lib.rs:167:2 | +| 1 | overriding `_`, which std's adaptors call in place of `next` or beside it | `Iterator::size_hint` | fixtures/reject/src/lib.rs:221:2 | +| 1 | replacing the value behind a reference to `_` | `[u8; 1]` | fixtures/reject/src/lib.rs:273:22 | +| 1 | replacing the value behind a reference to `_` | `std::string::String` | fixtures/reject/src/lib.rs:378:4 | +| 1 | unsupported call to `_` | `::deref` | fixtures/reject/src/lib.rs:400:2 | +| 1 | unsupported call to `_` | `::cycle` | fixtures/reject/src/lib.rs:154:11 | +| 1 | unsupported call to `_` | `::write_fmt` | fixtures/reject/src/lib.rs:97:10 | +| 1 | unsupported call to `_` | `std::mem::size_of_val` | fixtures/reject/src/lib.rs:49:18 | +| 1 | unsupported call to `_` | `std::ops::Range::contains` | fixtures/reject/src/lib.rs:208:8 | +| 1 | unsupported call to `_` | `std::slice::copy_within` | fixtures/reject/src/lib.rs:368:4 | +| 1 | unsupported call to `_` | `std::slice::sort` | fixtures/reject/src/lib.rs:33:4 | +| 1 | unsupported call to `_` | `std::str::split` | fixtures/reject/src/lib.rs:383:4 | +| 1 | unsupported type `_` | `dyn std::ops::Fn(u8) -> u8` | fixtures/reject/src/lib.rs:11:16 | ## Spans -
an assignment through a reference to `_` (7) +
unsupported call to `_` (8) -- fixtures/reject/src/lib.rs:16:2: an assignment through a reference to `u32` -- fixtures/reject/src/lib.rs:65:3: an assignment through a reference to `u8` -- fixtures/reject/src/lib.rs:123:2: an assignment through a reference to `std::sync::Arc` -- fixtures/reject/src/lib.rs:143:2: an assignment through a reference to `std::pin::Pin>` -- fixtures/reject/src/lib.rs:148:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` -- fixtures/reject/src/lib.rs:266:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>` -- fixtures/reject/src/lib.rs:360:3: an assignment through a reference to `u8` +- fixtures/reject/src/lib.rs:33:4: unsupported call to `std::slice::::sort` +- fixtures/reject/src/lib.rs:49:18: unsupported call to `std::mem::size_of_val::` +- fixtures/reject/src/lib.rs:97:10: unsupported call to `::write_fmt` +- fixtures/reject/src/lib.rs:154:11: unsupported call to ` as std::iter::Iterator>::cycle` +- fixtures/reject/src/lib.rs:208:8: unsupported call to `std::ops::Range::::contains::` +- fixtures/reject/src/lib.rs:368:4: unsupported call to `core::slice::::copy_within::>` +- fixtures/reject/src/lib.rs:383:4: unsupported call to `core::str::::split::<&str>` +- fixtures/reject/src/lib.rs:400:2: unsupported call to ` as std::ops::Deref>::deref`
-
unsupported call to `_` (7) +
an assignment through a reference to `_` (7) -- fixtures/reject/src/lib.rs:32:4: unsupported call to `std::slice::::sort` -- fixtures/reject/src/lib.rs:48:18: unsupported call to `std::mem::size_of_val::` -- fixtures/reject/src/lib.rs:96:10: unsupported call to `::write_fmt` -- fixtures/reject/src/lib.rs:153:11: unsupported call to ` as std::iter::Iterator>::cycle` -- fixtures/reject/src/lib.rs:207:8: unsupported call to `std::ops::Range::::contains::` -- fixtures/reject/src/lib.rs:367:4: unsupported call to `core::slice::::copy_within::>` -- fixtures/reject/src/lib.rs:382:4: unsupported call to `core::str::::split::<&str>` +- fixtures/reject/src/lib.rs:17:2: an assignment through a reference to `u32` +- fixtures/reject/src/lib.rs:66:3: an assignment through a reference to `u8` +- fixtures/reject/src/lib.rs:124:2: an assignment through a reference to `std::sync::Arc` +- fixtures/reject/src/lib.rs:144:2: an assignment through a reference to `std::pin::Pin>` +- fixtures/reject/src/lib.rs:149:2: an assignment through a reference to `std::sync::MutexGuard<'_, u8>` +- fixtures/reject/src/lib.rs:267:2: an assignment through a reference to `std::pin::Pin<&mut Noisy>` +- fixtures/reject/src/lib.rs:361:3: an assignment through a reference to `u8`
`_` is not supported: its `None` and `Some` would both be `undefined` (6) -- fixtures/reject/src/lib.rs:27:15: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:28:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:36:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:36:42: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:132:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` -- fixtures/reject/src/lib.rs:294:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:28:15: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:29:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:37:2: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:37:42: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:133:19: `Option>` is not supported: its `None` and `Some` would both be `undefined` +- fixtures/reject/src/lib.rs:295:2: `Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined`
`_`: a JS value of `_` is a copy, so a reference can't change it (6) -- fixtures/reject/src/lib.rs:15:13: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:21:2: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:64:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:94:16: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:359:29: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it -- fixtures/reject/src/lib.rs:376:15: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:16:13: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:22:2: `&mut u32`: a JS value of `u32` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:65:10: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:95:16: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:360:29: `&mut u8`: a JS value of `u8` is a copy, so a reference can't change it +- fixtures/reject/src/lib.rs:377:15: `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it + +
+ +
a variant of `_`, which is not supported: either is the same JS string (4) + +- fixtures/reject/src/lib.rs:388:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:389:30: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:390:27: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string +- fixtures/reject/src/lib.rs:395:2: a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string
replacing the value behind a reference to `_` (4) -- fixtures/reject/src/lib.rs:107:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:111:2: replacing the value behind a reference to `Meters` -- fixtures/reject/src/lib.rs:272:22: replacing the value behind a reference to `[u8; 1]` -- fixtures/reject/src/lib.rs:377:4: replacing the value behind a reference to `std::string::String` +- fixtures/reject/src/lib.rs:108:2: replacing the value behind a reference to `Meters` +- fixtures/reject/src/lib.rs:112:2: replacing the value behind a reference to `Meters` +- fixtures/reject/src/lib.rs:273:22: replacing the value behind a reference to `[u8; 1]` +- fixtures/reject/src/lib.rs:378:4: replacing the value behind a reference to `std::string::String`
unsupported type `_` (4) -- fixtures/reject/src/lib.rs:6:14: unsupported type `f64` -- fixtures/reject/src/lib.rs:6:25: unsupported type `f64` -- fixtures/reject/src/lib.rs:10:16: unsupported type `dyn std::ops::Fn(u8) -> u8` -- fixtures/reject/src/lib.rs:116:51: unsupported type `f64` +- fixtures/reject/src/lib.rs:7:14: unsupported type `f64` +- fixtures/reject/src/lib.rs:7:25: unsupported type `f64` +- fixtures/reject/src/lib.rs:11:16: unsupported type `dyn std::ops::Fn(u8) -> u8` +- fixtures/reject/src/lib.rs:117:51: unsupported type `f64`
an iterator that owns `_`, which drops, which is not supported yet (3) -- fixtures/reject/src/lib.rs:55:2: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:248:4: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet -- fixtures/reject/src/lib.rs:253:20: an iterator that owns `Noisy`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:56:2: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:249:4: an iterator that owns `std::vec::Vec`, which drops, which is not supported yet +- fixtures/reject/src/lib.rs:254:20: an iterator that owns `Noisy`, which drops, which is not supported yet
`_` is not supported: it would be pending two ways with one value (2) -- fixtures/reject/src/lib.rs:127:20: `Poll>>` is not supported: it would be pending two ways with one value -- fixtures/reject/src/lib.rs:137:54: `Poll>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:128:20: `Poll>>` is not supported: it would be pending two ways with one value +- fixtures/reject/src/lib.rs:138:54: `Poll>` is not supported: it would be pending two ways with one value
a field of `_` (2) -- fixtures/reject/src/lib.rs:289:7: a field of `std::ops::RangeTo` -- fixtures/reject/src/lib.rs:289:48: a field of `std::ops::RangeFrom` +- fixtures/reject/src/lib.rs:290:7: a field of `std::ops::RangeTo` +- fixtures/reject/src/lib.rs:290:48: a field of `std::ops::RangeFrom`
an iterator of the crate implementing `_`, which is not supported yet (2) -- fixtures/reject/src/lib.rs:186:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet -- fixtures/reject/src/lib.rs:240:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet +- fixtures/reject/src/lib.rs:187:1: an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet +- fixtures/reject/src/lib.rs:241:1: an iterator of the crate implementing `FusedIterator`, which is not supported yet
constructing `_` from another crate (2) -- fixtures/reject/src/lib.rs:172:23: constructing `std::iter::Map` from another crate -- fixtures/reject/src/lib.rs:193:14: constructing `std::iter::Rev` from another crate +- fixtures/reject/src/lib.rs:173:23: constructing `std::iter::Map` from another crate +- fixtures/reject/src/lib.rs:194:14: constructing `std::iter::Rev` from another crate
overriding `_`, which std's adaptors call in place of `next` or beside it (2) -- fixtures/reject/src/lib.rs:166:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it -- fixtures/reject/src/lib.rs:220:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it +- fixtures/reject/src/lib.rs:167:2: overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it +- fixtures/reject/src/lib.rs:221:2: overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it
`Binary` formatting, as in `{:b}`, is not supported (1) -- fixtures/reject/src/lib.rs:84:3: `Binary` formatting, as in `{:b}`, is not supported +- fixtures/reject/src/lib.rs:85:3: `Binary` formatting, as in `{:b}`, is not supported
`LowerExp` formatting, as in `{:e}`, is not supported (1) -- fixtures/reject/src/lib.rs:86:3: `LowerExp` formatting, as in `{:e}`, is not supported +- fixtures/reject/src/lib.rs:87:3: `LowerExp` formatting, as in `{:e}`, is not supported
`Octal` formatting, as in `{:o}`, is not supported (1) -- fixtures/reject/src/lib.rs:85:3: `Octal` formatting, as in `{:o}`, is not supported +- fixtures/reject/src/lib.rs:86:3: `Octal` formatting, as in `{:o}`, is not supported
`Pointer` formatting, as in `{:p}`, is not supported (1) -- fixtures/reject/src/lib.rs:89:3: `Pointer` formatting, as in `{:p}`, is not supported +- fixtures/reject/src/lib.rs:90:3: `Pointer` formatting, as in `{:p}`, is not supported
`_` holds `_`, which is `undefined` as `None` is, which is not supported (1) -- fixtures/reject/src/lib.rs:294:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported +- fixtures/reject/src/lib.rs:295:6: `std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported + +
+ +
`_` is not supported yet (1) + +- fixtures/reject/src/lib.rs:399:18: `std::borrow::Cow<'_, [u8]>` is not supported yet
`_` of `_` by `_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:317:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet +- fixtures/reject/src/lib.rs:318:6: `HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet
`_` through a held type's own, which is not supported yet (1) -- fixtures/reject/src/lib.rs:349:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet +- fixtures/reject/src/lib.rs:350:2: ` as PartialEq>::ne` through a held type's own, which is not supported yet
`_`, a mutable reference to a value a map holds, kept other than to read and write it (1) -- fixtures/reject/src/lib.rs:359:6: `std::option::Option<&mut u8>`, a mutable reference to a value a map holds, kept other than to read and write it +- fixtures/reject/src/lib.rs:360:6: `std::option::Option<&mut u8>`, a mutable reference to a value a map holds, kept other than to read and write it
`_`, which is not supported yet (1) -- fixtures/reject/src/lib.rs:325:9: `Hasher::write`, which is not supported yet +- fixtures/reject/src/lib.rs:326:9: `Hasher::write`, which is not supported yet
a `_` cast from `_` to `_` (1) -- fixtures/reject/src/lib.rs:118:2: a `IntToFloat` cast from `u64` to `f64` +- fixtures/reject/src/lib.rs:119:2: a `IntToFloat` cast from `u64` to `f64`
a `zip` of `_`, whose closures std calls one item further through `next` than through `fold` (1) -- fixtures/reject/src/lib.rs:199:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:199:15: 199:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` +- fixtures/reject/src/lib.rs:200:51: a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:200:15: 200:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold`
a coercion to `_` (1) -- fixtures/reject/src/lib.rs:372:2: a coercion to `std::sync::Arc<[u8]>` +- fixtures/reject/src/lib.rs:373:2: a coercion to `std::sync::Arc<[u8]>`
a constant of type `_` (1) -- fixtures/reject/src/lib.rs:102:2: a constant of type `&u8` +- fixtures/reject/src/lib.rs:103:2: a constant of type `&u8`
a copy of a closure that changes what it captured (1) -- fixtures/reject/src/lib.rs:283:14: a copy of a closure that changes what it captured +- fixtures/reject/src/lib.rs:284:14: a copy of a closure that changes what it captured
a mutable borrow of a subslice of `_`, which JS would copy, having no views (1) -- fixtures/reject/src/lib.rs:258:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views +- fixtures/reject/src/lib.rs:259:13: a mutable borrow of a subslice of `u32`, which JS would copy, having no views
a precision, as in `{:.2}`, is not supported (1) -- fixtures/reject/src/lib.rs:81:3: a precision, as in `{:.2}`, is not supported +- fixtures/reject/src/lib.rs:82:3: a precision, as in `{:.2}`, is not supported
a printable type must implement `Display` or `Debug` (1) -- fixtures/reject/src/lib.rs:114:1: a printable type must implement `Display` or `Debug` +- fixtures/reject/src/lib.rs:115:1: a printable type must implement `Display` or `Debug`
a scalar constant of type `_` (1) -- fixtures/reject/src/lib.rs:7:2: a scalar constant of type `f64` +- fixtures/reject/src/lib.rs:8:2: a scalar constant of type `f64`
a width or precision from an argument, as in `{:1$}`, is not supported (1) -- fixtures/reject/src/lib.rs:88:3: a width or precision from an argument, as in `{:1$}`, is not supported +- fixtures/reject/src/lib.rs:89:3: a width or precision from an argument, as in `{:1$}`, is not supported
a zero-sized constant of type `_` (1) -- fixtures/reject/src/lib.rs:74:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:73:10: 73:18}` +- fixtures/reject/src/lib.rs:75:2: a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:74:10: 74:18}`
arithmetic on `_` (1) -- fixtures/reject/src/lib.rs:7:2: arithmetic on `f64` +- fixtures/reject/src/lib.rs:8:2: arithmetic on `f64`
comparing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:299:52: comparing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:300:52: comparing `std::vec::Vec` as a key, which is not supported yet
dropping a closure that owns a value that drops, which is not supported yet (1) -- fixtures/reject/src/lib.rs:50:1: dropping a closure that owns a value that drops, which is not supported yet +- fixtures/reject/src/lib.rs:51:1: dropping a closure that owns a value that drops, which is not supported yet
hashing `_` as a key, which is not supported yet (1) -- fixtures/reject/src/lib.rs:299:52: hashing `std::vec::Vec` as a key, which is not supported yet +- fixtures/reject/src/lib.rs:300:52: hashing `std::vec::Vec` as a key, which is not supported yet
hex `Debug`, as in `{:x?}`, is not supported (1) -- fixtures/reject/src/lib.rs:87:3: hex `Debug`, as in `{:x?}`, is not supported +- fixtures/reject/src/lib.rs:88:3: hex `Debug`, as in `{:x?}`, is not supported
the `+` flag of a format spec is not supported (1) -- fixtures/reject/src/lib.rs:82:3: the `+` flag of a format spec is not supported +- fixtures/reject/src/lib.rs:83:3: the `+` flag of a format spec is not supported
the `-` flag of a format spec is not supported (1) -- fixtures/reject/src/lib.rs:83:3: the `-` flag of a format spec is not supported +- fixtures/reject/src/lib.rs:84:3: the `-` flag of a format spec is not supported
diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 18d649881..4fa58de9d 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -1,71 +1,77 @@ -a root must not be generic at fixtures/reject/src/lib.rs:116:1 +a root must not be generic at fixtures/reject/src/lib.rs:117:1 no item `missing` in the crate -a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:114:1 -unsupported type `f64` at fixtures/reject/src/lib.rs:6:14 -a scalar constant of type `f64` at fixtures/reject/src/lib.rs:7:2 -arithmetic on `f64` at fixtures/reject/src/lib.rs:7:2 -unsupported type `f64` at fixtures/reject/src/lib.rs:6:25 -unsupported type `dyn std::ops::Fn(u8) -> u8` at fixtures/reject/src/lib.rs:10:16 -`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:15:13 -an assignment through a reference to `u32` at fixtures/reject/src/lib.rs:16:2 -`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:21:11 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:28:2 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:27:15 -unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.rs:32:4 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:36:2 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:36:42 -unsupported call to `std::mem::size_of_val::` at fixtures/reject/src/lib.rs:48:18 -dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:50:1 -an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:55:11 -`&mut u8`: a JS value of `u8` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:64:10 -an assignment through a reference to `u8` at fixtures/reject/src/lib.rs:65:3 -a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:73:10: 73:18}` at fixtures/reject/src/lib.rs:74:2 -a precision, as in `{:.2}`, is not supported at fixtures/reject/src/lib.rs:81:3 -the `+` flag of a format spec is not supported at fixtures/reject/src/lib.rs:82:3 -the `-` flag of a format spec is not supported at fixtures/reject/src/lib.rs:83:3 -`Binary` formatting, as in `{:b}`, is not supported at fixtures/reject/src/lib.rs:84:12 -`Octal` formatting, as in `{:o}`, is not supported at fixtures/reject/src/lib.rs:85:12 -`LowerExp` formatting, as in `{:e}`, is not supported at fixtures/reject/src/lib.rs:86:12 -hex `Debug`, as in `{:x?}`, is not supported at fixtures/reject/src/lib.rs:87:3 -a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:88:15 -a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:88:3 -`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:89:12 -`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:94:16 -unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:96:10 -a constant of type `&u8` at fixtures/reject/src/lib.rs:102:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:107:2 -replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:111:2 -an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:123:2 -`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:127:20 -`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:132:19 -`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:137:54 -an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:143:2 -an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:148:2 -unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:153:11 -constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:172:23 -constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:193:14 -a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:199:15: 199:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:199:51 -unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:207:8 -an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:248:4 -an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:253:20 -a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:258:13 -an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:266:2 -replacing the value behind a reference to `[u8; 1]` at fixtures/reject/src/lib.rs:272:22 -a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:283:14 -a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:289:7 -a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:289:48 -`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:294:2 -`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:294:6 -hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:299:52 -comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:299:52 -`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:317:6 -unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:367:4 -a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:372:2 -`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:376:15 -replacing the value behind a reference to `std::string::String` at fixtures/reject/src/lib.rs:377:4 -unsupported call to `core::str::::split::<&str>` at fixtures/reject/src/lib.rs:382:4 -overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:166:2 -an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:186:1 -overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:220:2 -an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:240:1 -`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:325:9 +a printable type must implement `Display` or `Debug` at fixtures/reject/src/lib.rs:115:1 +unsupported type `f64` at fixtures/reject/src/lib.rs:7:14 +a scalar constant of type `f64` at fixtures/reject/src/lib.rs:8:2 +arithmetic on `f64` at fixtures/reject/src/lib.rs:8:2 +unsupported type `f64` at fixtures/reject/src/lib.rs:7:25 +unsupported type `dyn std::ops::Fn(u8) -> u8` at fixtures/reject/src/lib.rs:11:16 +`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:16:13 +an assignment through a reference to `u32` at fixtures/reject/src/lib.rs:17:2 +`&mut u32`: a JS value of `u32` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:22:11 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:29:2 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:28:15 +unsupported call to `std::slice::::sort` at fixtures/reject/src/lib.rs:33:4 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:37:2 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:37:42 +unsupported call to `std::mem::size_of_val::` at fixtures/reject/src/lib.rs:49:18 +dropping a closure that owns a value that drops, which is not supported yet at fixtures/reject/src/lib.rs:51:1 +an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:56:11 +`&mut u8`: a JS value of `u8` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:65:10 +an assignment through a reference to `u8` at fixtures/reject/src/lib.rs:66:3 +a zero-sized constant of type `{async closure@fixtures/reject/src/lib.rs:74:10: 74:18}` at fixtures/reject/src/lib.rs:75:2 +a precision, as in `{:.2}`, is not supported at fixtures/reject/src/lib.rs:82:3 +the `+` flag of a format spec is not supported at fixtures/reject/src/lib.rs:83:3 +the `-` flag of a format spec is not supported at fixtures/reject/src/lib.rs:84:3 +`Binary` formatting, as in `{:b}`, is not supported at fixtures/reject/src/lib.rs:85:12 +`Octal` formatting, as in `{:o}`, is not supported at fixtures/reject/src/lib.rs:86:12 +`LowerExp` formatting, as in `{:e}`, is not supported at fixtures/reject/src/lib.rs:87:12 +hex `Debug`, as in `{:x?}`, is not supported at fixtures/reject/src/lib.rs:88:3 +a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:89:15 +a width or precision from an argument, as in `{:1$}`, is not supported at fixtures/reject/src/lib.rs:89:3 +`Pointer` formatting, as in `{:p}`, is not supported at fixtures/reject/src/lib.rs:90:12 +`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:95:16 +unsupported call to `::write_fmt` at fixtures/reject/src/lib.rs:97:10 +a constant of type `&u8` at fixtures/reject/src/lib.rs:103:2 +replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:108:2 +replacing the value behind a reference to `Meters` at fixtures/reject/src/lib.rs:112:2 +an assignment through a reference to `std::sync::Arc` at fixtures/reject/src/lib.rs:124:2 +`Poll>>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:128:20 +`Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:133:19 +`Poll>` is not supported: it would be pending two ways with one value at fixtures/reject/src/lib.rs:138:54 +an assignment through a reference to `std::pin::Pin>` at fixtures/reject/src/lib.rs:144:2 +an assignment through a reference to `std::sync::MutexGuard<'_, u8>` at fixtures/reject/src/lib.rs:149:2 +unsupported call to ` as std::iter::Iterator>::cycle` at fixtures/reject/src/lib.rs:154:11 +constructing `std::iter::Map` from another crate at fixtures/reject/src/lib.rs:173:23 +constructing `std::iter::Rev` from another crate at fixtures/reject/src/lib.rs:194:14 +a `zip` of `std::iter::Chain, {closure@fixtures/reject/src/lib.rs:200:15: 200:18}>, std::iter::Copied>>`, whose closures std calls one item further through `next` than through `fold` at fixtures/reject/src/lib.rs:200:51 +unsupported call to `std::ops::Range::::contains::` at fixtures/reject/src/lib.rs:208:8 +an iterator that owns `std::vec::Vec`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:249:4 +an iterator that owns `Noisy`, which drops, which is not supported yet at fixtures/reject/src/lib.rs:254:20 +a mutable borrow of a subslice of `u32`, which JS would copy, having no views at fixtures/reject/src/lib.rs:259:13 +an assignment through a reference to `std::pin::Pin<&mut Noisy>` at fixtures/reject/src/lib.rs:267:2 +replacing the value behind a reference to `[u8; 1]` at fixtures/reject/src/lib.rs:273:22 +a copy of a closure that changes what it captured at fixtures/reject/src/lib.rs:284:14 +a field of `std::ops::RangeTo` at fixtures/reject/src/lib.rs:290:7 +a field of `std::ops::RangeFrom` at fixtures/reject/src/lib.rs:290:48 +`Option<&std::option::Option>` is not supported: its `None` and `Some` would both be `undefined` at fixtures/reject/src/lib.rs:295:2 +`std::collections::HashMap>` holds `std::option::Option`, which is `undefined` as `None` is, which is not supported at fixtures/reject/src/lib.rs:295:6 +hashing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:300:52 +comparing `std::vec::Vec` as a key, which is not supported yet at fixtures/reject/src/lib.rs:300:52 +`HashMap::contains_key` of `std::collections::HashMap` by `u8`, which is not supported yet at fixtures/reject/src/lib.rs:318:6 +unsupported call to `core::slice::::copy_within::>` at fixtures/reject/src/lib.rs:368:4 +a coercion to `std::sync::Arc<[u8]>` at fixtures/reject/src/lib.rs:373:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:388:2 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:390:27 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:389:30 +a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:395:2 +`std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:399:18 +unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:400:2 +`&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:377:15 +replacing the value behind a reference to `std::string::String` at fixtures/reject/src/lib.rs:378:4 +unsupported call to `core::str::::split::<&str>` at fixtures/reject/src/lib.rs:383:4 +overriding `Iterator::fold`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:167:2 +an iterator of the crate implementing `DoubleEndedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:187:1 +overriding `Iterator::size_hint`, which std's adaptors call in place of `next` or beside it at fixtures/reject/src/lib.rs:221:2 +an iterator of the crate implementing `FusedIterator`, which is not supported yet at fixtures/reject/src/lib.rs:241:1 +`Hasher::write`, which is not supported yet at fixtures/reject/src/lib.rs:326:9 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index c08ac00f4..5e91d5bbc 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -2,6 +2,7 @@ //! output is written. #![allow(dead_code, reason = "each item is a translation root, not called from Rust")] +#![feature(cow_is_borrowed)] pub fn float(a: f64) -> f64 { a * 2.0 @@ -381,3 +382,20 @@ pub fn pushed(s: &mut String) { pub fn split_str(s: &str) -> usize { s.split("ab").count() } + +/// A `Cow` is a JS string, which keeps no variant to match on or ask about. +pub fn cow_matched(c: std::borrow::Cow<'_, str>) -> String { + match c { + std::borrow::Cow::Borrowed(s) => s.to_string(), + std::borrow::Cow::Owned(s) => s, + } +} + +pub fn cow_borrowed(c: &std::borrow::Cow<'_, str>) -> bool { + std::borrow::Cow::is_borrowed(c) +} + +/// Only a `Cow` has a JS value yet. +pub fn cow_bytes(c: std::borrow::Cow<'_, [u8]>) -> usize { + c.len() +} diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 28b23a24f..35e5cbb85 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -44,6 +44,9 @@ roots = [ "raw_keys", "shifted", "shared", + "cow_matched", + "cow_borrowed", + "cow_bytes", "pushed", "split_str", "missing", diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index 4ab8c686f..24e7ee2c5 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -160,7 +160,7 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { if let Some(std) = library::Std::of(tcx, adt_id) { let mut values = values; return match (std, variant.index()) { - (library::Std::Option, 1) | (library::Std::Poll, 0) => values.pop().unwrap(), + (library::Std::Option, 1) | (library::Std::Poll, 0) | (library::Std::Cow, _) => values.pop().unwrap(), (library::Std::Result, 0) => Expr::rt("Ok", values), (library::Std::Result, _) => Expr::rt("Err", values), _ => self.err(span, format!("constructing `{}`", tcx.def_path_str(adt_id))), diff --git a/ts/src/lower/collections.rs b/ts/src/lower/collections.rs index 3c5130046..0b57a09af 100644 --- a/ts/src/lower/collections.rs +++ b/ts/src/lower/collections.rs @@ -227,8 +227,8 @@ fn lookup_ty<'tcx>(b: &Body<'_, '_, 'tcx>, std: Std, call: &Call<'tcx>, owner: & fn same_key<'tcx>(b: &Body<'_, '_, 'tcx>, key: Ty<'tcx>, by: Ty<'tcx>) -> bool { let tcx = b.t.tcx; let (key, by) = (peel(b, key), peel(b, by)); - let string = |t: Ty<'tcx>| t.is_str() || b.t.std_of(t) == Some(Std::String); - tcx.erase_and_anonymize_regions(key) == tcx.erase_and_anonymize_regions(by) || (string(key) && string(by)) + tcx.erase_and_anonymize_regions(key) == tcx.erase_and_anonymize_regions(by) + || (library::string(tcx, key) && library::string(tcx, by)) } /// A key, value, or item type of `coll` that can be `undefined` in JS, so that an `Option` @@ -401,7 +401,7 @@ fn hashing<'tcx>(b: &mut Body<'_, '_, 'tcx>, coll: Ty<'tcx>, key: Ty<'tcx>, span let primitive = match key.kind() { ty::Bool | ty::Char | ty::Str => true, ty::Int(_) | ty::Uint(_) => !Int::of(key)?.big(), - ty::Adt(..) if b.t.std_of(key) == Some(Std::String) => true, + ty::Adt(..) if library::string(b.t.tcx, key) => true, ty::Adt(adt, _) if adt.did().is_local() && fieldless(*adt) => derived_eq(b, key), _ => false, }; @@ -794,7 +794,7 @@ fn std_key<'tcx>(b: &Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Str => true, ty::Tuple(tys) => !tys.is_empty() && tys.iter().all(held), ty::Adt(..) if let Some(inner) = option_of(b, ty).or_else(|| arc_of(b, ty)) => held(inner), - ty::Adt(..) => matches!(b.t.std_of(ty), Some(Std::String | Std::Ordering)), + ty::Adt(..) => library::string(b.t.tcx, ty) || b.t.std_of(ty) == Some(Std::Ordering), _ => false, } } @@ -817,7 +817,7 @@ fn cmp_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, partial: bool, span: S match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => Expr::Rt("cmp".into()), ty::Str => Expr::Rt("cmpStr".into()), - ty::Adt(..) if b.t.std_of(ty) == Some(Std::String) => Expr::Rt("cmpStr".into()), + ty::Adt(..) if library::string(tcx, ty) => Expr::Rt("cmpStr".into()), ty::Adt(..) if b.t.std_of(ty) == Some(Std::Ordering) => Expr::Rt("cmp".into()), ty::Tuple(tys) if !tys.is_empty() => { let fns = tys.iter().map(|t| cmp_fn(b, t, partial, span)).collect(); @@ -853,7 +853,7 @@ fn eq_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> Expr { int.func("eq") } ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Str => Expr::Rt("same".into()), - ty::Adt(..) if matches!(b.t.std_of(ty), Some(Std::String | Std::Ordering)) => Expr::Rt("same".into()), + ty::Adt(..) if library::string(tcx, ty) || b.t.std_of(ty) == Some(Std::Ordering) => Expr::Rt("same".into()), ty::Tuple(tys) if !tys.is_empty() => { let fns = tys.iter().map(|t| eq_fn(b, t, span)).collect(); Expr::rt("eqTuple", vec![Expr::Array(fns)]) @@ -888,7 +888,7 @@ fn hash_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, hasher: Ty<'tcx>, spa match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) => Expr::Rt("hashInt".into()), ty::Str => Expr::Rt("hashStr".into()), - ty::Adt(..) if b.t.std_of(ty) == Some(Std::String) => Expr::Rt("hashStr".into()), + ty::Adt(..) if library::string(tcx, ty) => Expr::Rt("hashStr".into()), ty::Adt(..) if b.t.std_of(ty) == Some(Std::Ordering) => Expr::Rt("hashInt".into()), ty::Tuple(tys) if !tys.is_empty() => { let fns = tys.iter().map(|t| hash_fn(b, t, hasher, span)).collect(); @@ -915,7 +915,7 @@ pub fn clone_fn<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>, span: Span) -> E { return copy; } - if (b.t.is_copy(ty) && library::clone_copies(b.t, ty)) || b.t.std_of(ty) == Some(Std::String) { + if (b.t.is_copy(ty) && library::clone_copies(b.t, ty)) || library::string(tcx, ty) { return Expr::undefined(); } let clone = trait_fn(tcx, "Clone", "clone"); diff --git a/ts/src/lower/consts.rs b/ts/src/lower/consts.rs index 7520820ad..e1b2a3912 100644 --- a/ts/src/lower/consts.rs +++ b/ts/src/lower/consts.rs @@ -104,7 +104,7 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { if let Some(std) = Std::of(tcx, adt.did()) { return match (std, variant.index()) { (Std::Option, 0) => Expr::undefined(), - (Std::Option, _) => values.pop().unwrap(), + (Std::Option | Std::Cow, _) => values.pop().unwrap(), (Std::Result, 0) => Expr::rt("Ok", values), (Std::Result, _) => Expr::rt("Err", values), // `start..=end`, not yet stepped past its end. diff --git a/ts/src/lower/fmt.rs b/ts/src/lower/fmt.rs index 2320ed028..3c9cd7e77 100644 --- a/ts/src/lower/fmt.rs +++ b/ts/src/lower/fmt.rs @@ -249,8 +249,8 @@ pub fn std_impl<'tcx>( value.call(vec![f]) } ty::Adt(adt, args) => match (Std::of(tcx, adt.did())?, tr) { - (Std::String, Trait::Display) => Expr::rt("fmtPad", vec![f, value]), - (Std::String, Trait::Debug) => rt("str", vec![value, f]), + (Std::String | Std::Cow, Trait::Display) if library::string(tcx, ty) => Expr::rt("fmtPad", vec![f, value]), + (Std::String | Std::Cow, Trait::Debug) if library::string(tcx, ty) => rt("str", vec![value, f]), (Std::Box, _) => b.fmt_call(tr, args.type_at(0), value, f, span), (Std::Vec, Trait::Debug) => { let item = b.fmt_fn(tr, args.type_at(0), span); diff --git a/ts/src/lower/iter.rs b/ts/src/lower/iter.rs index c6c2078fe..f426416e0 100644 --- a/ts/src/lower/iter.rs +++ b/ts/src/lower/iter.rs @@ -348,11 +348,7 @@ pub fn call<'tcx>( } _ if b.t.needs_copy(*inner) => method("map", b.t.copy_fn(*inner, span).into_iter().collect()), // A JS string is a value already. - _ if b.t.is_copy(*inner) - || matches!(inner.kind(), ty::Adt(adt, _) if Std::of(tcx, adt.did()) == Some(Std::String)) => - { - Some(recv) - } + _ if b.t.is_copy(*inner) || library::string(tcx, *inner) => Some(recv), // Each item through its `Clone`. _ => { let clone = tcx.lang_items().clone_fn()?; diff --git a/ts/src/lower/library.rs b/ts/src/lower/library.rs index 8bacb3fde..2359b6110 100644 --- a/ts/src/lower/library.rs +++ b/ts/src/lower/library.rs @@ -25,6 +25,8 @@ pub enum Std { Vec, /// A JS string. String, + /// A JS string too, for `Cow`, which keeps no variant: either is the text. + Cow, /// Its contents. Box, FromUtf8Error, @@ -114,6 +116,9 @@ impl Std { if tcx.is_lang_item(did, rustc_attr_ir::LangItem::OwnedBox) { return Some(Self::Box); } + if tcx.is_diagnostic_item(sym::Cow, did) { + return Some(Self::Cow); + } for (item, std) in [ (sym::Arc, Self::Arc), (sym::ArcWeak, Self::Weak), @@ -222,6 +227,25 @@ impl Flow { } } +/// Whether a `ty`'s value is a JS string: a `str`, a `String`, or a `Cow`. +pub fn string<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { + match ty.kind() { + ty::Str => true, + ty::Adt(adt, args) => match Std::of(tcx, adt.did()) { + Some(Std::String) => true, + // Its first argument is its lifetime. + Some(Std::Cow) => args.types().next().is_some_and(|t| t.is_str()), + _ => false, + }, + _ => false, + } +} + +/// The refusal of code that tells a `Cow`'s variants apart. +pub fn cow_variant(ty: Ty<'_>) -> String { + format!("a variant of `{ty}`, which is not supported: either is the same JS string") +} + /// The path of a std item within its crate, as `["slice", "iter", "Iter"]`; empty for /// any other crate's. pub fn std_path(tcx: TyCtxt<'_>, did: DefId) -> Vec { @@ -461,7 +485,8 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec let (to, from) = (targ(gargs, 0), targ(gargs, 1)); let mut values = args; let value = values.pop()?; - if to == from { + // One between strings, such as into a `Cow` or out of one, keeps the text. + if to == from || (string(tcx, to) && string(tcx, from.peel_refs())) { return Some(value); } // Each `From` between integers and `char` keeps the value, as `as` then does. @@ -553,7 +578,7 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec ty::Adt(adt, args) if Std::of(tcx, adt.did()) == Some(Std::Vec) && is_u8(args.type_at(0)) => { Expr::rt("byteVecFrom", vec![Expr::rt("byteVecView", vec![value])]) } - ty::Adt(adt, _) if Std::of(tcx, adt.did()) == Some(Std::String) => value, + ty::Adt(..) if string(tcx, ty) => value, ty::Adt(adt, _) if int_range(ty) => { Expr::rt_of(range_of(Std::of(tcx, adt.did())?)?, "clone").call(vec![value]) } @@ -738,6 +763,7 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec ty::Adt(adt, _) => match Std::of(tcx, adt.did()) { Some(Std::Vec) => vec_view(v, ty), Some(Std::String | Std::Box) => v, + Some(Std::Cow) if string(tcx, ty) => v, _ => return None, }, _ => return None, @@ -766,6 +792,14 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec Expr::rt(f, vec![s, pattern(targ(gargs, 0), p)?]) } ("char", "is_ascii_digit") => Expr::rt("charIsAsciiDigit", args), + // A `Cow` is its text, whichever variant holds it. + ("Cow", "into_owned") if targ(gargs, 0).is_str() => args.pop()?, + ("AsRef", "as_ref") if string(tcx, targ(gargs, 0)) && targ(gargs, 1).is_str() => args.pop()?, + ("Cow", "is_borrowed" | "is_owned") => { + let sig = tcx.fn_sig(call.def_id).instantiate(tcx, gargs).skip_norm_wip(); + let cow = tcx.instantiate_bound_regions_with_erased(sig).inputs()[0].peel_refs(); + return Some(b.err(span, cow_variant(cow))); + } ("ToString", "to_string") | ("ToOwned", "to_owned") if matches!(self_ty()?.peel_refs().kind(), ty::Str) => { args.pop()? } @@ -819,7 +853,7 @@ pub fn call<'tcx>(b: &mut Body<'_, '_, 'tcx>, call: &Call<'tcx>, args: Vec let ty = targ(gargs, 0); let value = args.pop()?; match ty.kind() { - ty::Adt(adt, _) if Std::of(tcx, adt.did()) == Some(Std::String) => value, + ty::Adt(..) if string(tcx, ty) => value, _ => { let value = b.fmt_value(fmt::Trait::Display, ty, value, span, out); Expr::rt("fmtToString", vec![value]) @@ -1062,6 +1096,7 @@ pub fn default_value<'tcx>(b: &mut Body<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option Expr::Array(Vec::new()), }, Std::String => Expr::Str(String::new()), + Std::Cow if string(tcx, ty) => Expr::Str(String::new()), _ => return None, }, _ => return None, diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index ae837fc84..1c03a56c8 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -307,6 +307,18 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { out.push(StmtKind::Expr(place.assign(pushed)).at(None)); done(Expr::undefined(), false) } + // A `Cow` is the `String` it would hold, so the `&mut` borrows the same place. + ("Cow", "to_mut") if targ(0).is_some_and(|t| t.is_str()) => { + let place = self.borrowed_place(&args[0].node, span)?; + if let Some(local) = dest.as_local() + && self.defs[local] == 1 + && matches!(self.slots[local], Slot::Var(_)) + { + self.slots[local] = Slot::Alias(Some(place)); + return Some(None); + } + done(place, true) + } ("Option", "take") => { let place = self.borrowed_place(&args[0].node, span)?; done(self.swap_out(place, Expr::undefined(), "taken", out), true) diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index 261f74f4c..e1a1395b9 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -273,6 +273,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { base.member(adt.non_enum_variant().fields[field].name.as_str()) } Some(Std::Context | Std::NonNull | Std::Entry) => base, + Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), Some(Std::ControlFlow) => super::call::control_flow_field(self, base, ty, variant), _ if transparent(self.b.t, ty) => base, None if adt.did().is_local() => { @@ -475,6 +476,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } Some(Std::ControlFlow) => super::call::control_flow_test(self, scrut, ty, index), Some(Std::Entry) => crate::lower::collections::entry_test(*adt, index, scrut.clone()), + Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), Some(Std::Ordering) => scrut .clone() .binary("===", crate::lower::collections::ordering_variant(index)), diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index 24d5900d8..cf64fe591 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -242,6 +242,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } // The value is its discriminant. Some(Std::Ordering) => scrut, + Some(Std::Cow) => self.err(span, crate::lower::library::cow_variant(ty)), None if adt.did().is_local() => { let info = self.b.t.adt(*adt, span); let table = discrs @@ -323,6 +324,8 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { (Std::Option, 0) => Expr::undefined(), (Std::Poll, 1) => Expr::Rt("Pending".into()), (Std::Option | Std::Poll, _) => values.pop().unwrap(), + // Either variant is its text. + (Std::Cow, _) => values.pop().unwrap(), (Std::Result, 0) => Expr::rt("Ok", values), (Std::Result, _) => Expr::rt("Err", values), (Std::FmtError, _) => Expr::New(Box::new(Expr::Rt("FmtError".into())), Vec::new()), diff --git a/ts/src/lower/mod.rs b/ts/src/lower/mod.rs index 51ae507ed..9a7fff390 100644 --- a/ts/src/lower/mod.rs +++ b/ts/src/lower/mod.rs @@ -1014,6 +1014,11 @@ impl<'a, 'tcx> Translator<'a, 'tcx> { _ => Type::Array(Box::new(self.ty(args.type_at(0), span))), }, library::Std::String => Type::Builtin("string"), + library::Std::Cow if library::string(tcx, Ty::new_adt(tcx, adt, args)) => Type::Builtin("string"), + library::Std::Cow => { + self.unrepresented(span, format!("`{}` is not supported yet", Ty::new_adt(tcx, adt, args))); + Type::Builtin("unknown") + } library::Std::Box => self.ty(args.type_at(0), span), library::Std::FromUtf8Error => Type::Rt("FromUtf8Error", vec![]), library::Std::TryFromIntError => Type::Rt("TryFromIntError", vec![]), diff --git a/ts/src/lower/task.rs b/ts/src/lower/task.rs index e00420a46..b4cb1e3c1 100644 --- a/ts/src/lower/task.rs +++ b/ts/src/lower/task.rs @@ -4,7 +4,7 @@ use rustc_middle::ty::{self, Ty}; use super::body::Body; -use super::library::{Call, Std}; +use super::library::{self, Call, Std}; use crate::ts::Expr; /// A call of a standard library function on these types, or its arguments back if it is @@ -31,7 +31,7 @@ pub fn call<'tcx>( && let ty::Adt(_, arc) = arc.expect_ty().kind() && self_std == Some(Std::Arc) && arc.type_at(0).is_str() - && (from.expect_ty().peel_refs().is_str() || std_of(from.expect_ty()) == Some(Std::String)) => + && library::string(tcx, from.expect_ty().peel_refs()) => { Expr::New(Box::new(Expr::Rt("Arc".into())), args) } From 85d206108fe40ca392ba693f2eb3e5fc560594c2 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:22:54 -0700 Subject: [PATCH 3/4] fix(ts): take the path of what to_mut borrows Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- ts/src/lower/mir/call.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index ec6e7b350..6027d20ad 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -313,7 +313,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } // A `Cow` is the `String` it would hold, so the `&mut` borrows the same place. ("Cow", "to_mut") if targ(0).is_some_and(|t| t.is_str()) => { - let place = self.borrowed_place(&args[0].node, span)?; + let (place, _) = self.borrowed_place(&args[0].node, span)?; if let Some(local) = dest.as_local() && self.defs[local] == 1 && matches!(self.slots[local], Slot::Var(_)) From 8b51e7bf91b1b8610597e392ac7a91ff05195575 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:45:46 -0700 Subject: [PATCH 4/4] fix(ts): refuse other Cow constructors, and rebuild what to_mut borrows A `Cow` of other than `str` is refused where it is made, so a local's unchecked type can't erase it. A store through `to_mut`'s reference follows it to the `Cow` it borrows, so a `Cow` in a `Result`'s payload rebuilds the `Result` rather than writing its read-only `value`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- ts/fixtures/lang/expected/cows.ts | 84 +++++++++++++++++++------------ ts/fixtures/lang/src/cows.rs | 16 ++++++ ts/fixtures/reject/census.md | 14 ++++-- ts/fixtures/reject/expected.txt | 1 + ts/fixtures/reject/src/lib.rs | 9 ++++ ts/fixtures/reject/ts.toml | 1 + ts/src/lower/body.rs | 3 +- ts/src/lower/consts.rs | 3 +- ts/src/lower/mir/call.rs | 3 +- ts/src/lower/mir/mod.rs | 4 ++ ts/src/lower/mir/place.rs | 6 +++ ts/src/lower/mir/rvalue.rs | 2 +- 12 files changed, 107 insertions(+), 39 deletions(-) diff --git a/ts/fixtures/lang/expected/cows.ts b/ts/fixtures/lang/expected/cows.ts index e16be4204..450768437 100644 --- a/ts/fixtures/lang/expected/cows.ts +++ b/ts/fixtures/lang/expected/cows.ts @@ -5,6 +5,14 @@ import * as Named from "./cows.Named.ts"; import { put } from "./fmt.ts"; import { text } from "./strs.ts"; +/** `to_mut` of a `Result`'s payload, which the store rebuilds the `Result` around. */ +export function exclaimed(r: rt.Result): rt.Result { + if (r.ok) { + return rt.Ok(r.value + "!"); + } + return r; +} + export function cow(s: string, owned: boolean): string { if (!owned) { return s; @@ -14,6 +22,7 @@ export function cow(s: string, owned: boolean): string { export function cows(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { let shared!: rt.Arc; + let r!: rt.Result; let unwind: number = 0; try { const s: string = text(data); @@ -35,19 +44,19 @@ export function cows(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { put(out, "fallback"); put(out, s); shared = new rt.Arc(s); - unwind = 256; + unwind = 267; put(out, shared.value); const _80: rt.Iter = rt.strSplit(s, "\\"); const part: string = rt.optionUnwrapOr(rt.optionMap(rt.iterNth(_80, 1), (a03: string): string => { return a03; }), "fallback"); - unwind = 255; + unwind = 266; put(out, part); const into: string = cow(first, owned); - unwind = 254; + unwind = 265; put(out, into); const fromStr: string = first; - unwind = 253; + unwind = 264; put(out, fromStr); unwind = 0; rt.drop(shared); @@ -71,21 +80,32 @@ export function cows(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { put(out, _126); } put(out, c2); + if ((kind & 64) === 0) { + r = rt.Ok(cow(first, owned)); + } else { + r = rt.Err(kind); + } + const _140: rt.Result = exclaimed(r); + if (_140.ok) { + put(out, _140.value); + } else { + rt.byteVecPush(out, _140.error); + } } else if (_14 === 2) { const a: string = cow(s, owned); const b: string = cow(first, !owned); const iter2: rt.Iter = rt.iterSlice([a === first, a === first, a === s, first === a, s === a, a === b, a !== b, rt.cmpStr(a, b) < 0, rt.cmpStr(a, b) >= 0, rt.cmpStr(a, b) === 1]); while (true) { - const _179: boolean | rt.Done = iter2.next(); - if (_179 === rt.DONE) { + const _189: boolean | rt.Done = iter2.next(); + if (_189 === rt.DONE) { break; } - rt.byteVecPush(out, _179 ? 1 : 0); + rt.byteVecPush(out, _189 ? 1 : 0); } - const _190: string = a; - const _191: string = b; - const _189: string = rt.ordMax(_190, _191, rt.cmpStr); - rt.byteVecPush(out, _189 === b ? 1 : 0); + const _200: string = a; + const _201: string = b; + const _199: string = rt.ordMax(_200, _201, rt.cmpStr); + rt.byteVecPush(out, _199 === b ? 1 : 0); } else if (_14 === 3) { const n: Named.Named = Named.new(first, kind); const m2: Named.Named = Named.clone$Clone(n); @@ -99,62 +119,62 @@ export function cows(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void { put(out, o.name); [Named.default$Default(), Named.new("", kind)] as [Named.Named, Named.Named]; const arg4 = Named.default$Default(); - const _250: rt.Fmt = (f: rt.Formatter) => Named.fmt$Debug(arg4, f); + const _260: rt.Fmt = (f: rt.Formatter) => Named.fmt$Debug(arg4, f); const arg5 = Named.new("", kind); - const args4: rt.Fmt[] = [_250, (f: rt.Formatter) => Named.fmt$Debug(arg5, f)]; + const args4: rt.Fmt[] = [_260, (f: rt.Formatter) => Named.fmt$Debug(arg5, f)]; put(out, rt.fmtFormat([args4[0], " ", args4[1]])); } else if (_14 === 4) { const counts: rt.BTreeMap = rt.btreeNew(rt.cmpStr) as rt.BTreeMap; const iter3: rt.Iter<[rt.usize, string]> = rt.iterEnumerate(rt.strSplit(s, "/")); while (true) { - const _261: [rt.usize, string] | rt.Done = iter3.next(); - if (_261 === rt.DONE) { + const _271: [rt.usize, string] | rt.Done = iter3.next(); + if (_271 === rt.DONE) { break; } - const _269: string = cow(_261[1], rt.usizeRem(_261[0], 2) === 1 === owned); - const place = rt.entryOrInsertMut(rt.entry(counts, _269), 0); + const _279: string = cow(_271[1], rt.usizeRem(_271[0], 2) === 1 === owned); + const place = rt.entryOrInsertMut(rt.entry(counts, _279), 0); place.v = rt.u8Add(place.v, 1); } const iter4: rt.Iter<[string, rt.u8]> = rt.btreeIter(counts); while (true) { - const _278: [string, rt.u8] | rt.Done = iter4.next(); - if (_278 === rt.DONE) { + const _288: [string, rt.u8] | rt.Done = iter4.next(); + if (_288 === rt.DONE) { break; } - put(out, _278[0]); - rt.byteVecPush(out, _278[1]); + put(out, _288[0]); + rt.byteVecPush(out, _288[1]); } rt.byteVecPush(out, rt.optionUnwrapOr(rt.btreeGet(counts, first), 255)); const names: rt.HashSet = rt.hashNew(rt.hashing(Named.hash$Hash_DefaultHasher, Named.eq$PartialEq)) as rt.HashSet; const iter5: rt.Iter = rt.strSplit(s, "/"); while (true) { - const _298: string | rt.Done = iter5.next(); - if (_298 === rt.DONE) { + const _308: string | rt.Done = iter5.next(); + if (_308 === rt.DONE) { break; } - const _304: Named.Named = Named.new(_298, 0); - rt.hashAdd(names, _304); + const _314: Named.Named = Named.new(_308, 0); + rt.hashAdd(names, _314); } rt.byteVecPush(out, rt.hashLen(names) & 0xff); - const _314: Named.Named = Named.new(first, 0); - rt.byteVecPush(out, rt.hashContains(names, _314) ? 1 : 0); + const _324: Named.Named = Named.new(first, 0); + rt.byteVecPush(out, rt.hashContains(names, _324) ? 1 : 0); } else { [cow(s, owned)] as [string]; const arg = cow(s, owned); - const _327: rt.Fmt = (f: rt.Formatter) => rt.fmtPad(f, arg); + const _337: rt.Fmt = (f: rt.Formatter) => rt.fmtPad(f, arg); const arg2 = cow(s, owned); - const args6: rt.Fmt[] = [_327, (f: rt.Formatter) => rt.fmtStr(arg2, f)]; + const args6: rt.Fmt[] = [_337, (f: rt.Formatter) => rt.fmtStr(arg2, f)]; put(out, rt.fmtFormat(["[", args6[0], "|", rt.fmtSpec({ align: ">", width: 6 }, args6[0]), "|", rt.fmtSpec({ align: "<", width: 5 }, args6[0]), "|", rt.fmtSpec({ align: "^", width: 7 }, args6[0]), "|", rt.fmtSpec({ fill: "*", align: "^", width: 3 }, args6[0]), "|", args6[1], "]"])); const arg3 = ([cow(first, owned)] as [string | undefined])[0]; const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtOption(arg3, f, rt.fmtStr)]; put(out, rt.fmtFormat([args8[0]])); } - } catch (e) { + } catch (e2) { if (unwind === 0) { - throw e; + throw e2; } rt.drop(shared); - throw e; + throw e2; } } diff --git a/ts/fixtures/lang/src/cows.rs b/ts/fixtures/lang/src/cows.rs index 51a940b8a..4632867e6 100644 --- a/ts/fixtures/lang/src/cows.rs +++ b/ts/fixtures/lang/src/cows.rs @@ -43,6 +43,14 @@ impl<'a> Named<'a> { } } +/// `to_mut` of a `Result`'s payload, which the store rebuilds the `Result` around. +fn exclaimed(mut r: Result, u8>) -> Result, u8> { + if let Ok(c) = &mut r { + c.to_mut().push('!'); + } + r +} + fn cow(s: &str, owned: bool) -> Cow<'_, str> { match owned { true => Cow::Owned(s.to_string()), @@ -98,6 +106,14 @@ pub fn cows(kind: u8, data: &[u8], out: &mut Vec) { put(out, c); } put(out, &c.into_owned()); + let r = match kind & 0x40 { + 0 => Ok(cow(first, owned)), + _ => Err(kind), + }; + match exclaimed(r) { + Ok(c) => put(out, &c), + Err(e) => out.push(e), + } } 2 => { // Comparisons with each string type, either way around, and ordering. diff --git a/ts/fixtures/reject/census.md b/ts/fixtures/reject/census.md index a701a7aa3..e5e808788 100644 --- a/ts/fixtures/reject/census.md +++ b/ts/fixtures/reject/census.md @@ -1,7 +1,7 @@ # Census of `reject-fixture` -- Refusals: 80 -- Function instances: 64 +- Refusals: 81 +- Function instances: 65 - Generic functions no instance reached, lowered over their type parameters: 2 ## By construct @@ -44,6 +44,7 @@ | 1 | a zero-sized constant of type `_` | fixtures/reject/src/lib.rs:75:2 | | 1 | arithmetic on `_` | fixtures/reject/src/lib.rs:8:2 | | 1 | comparing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:300:52 | +| 1 | constructing `_` | fixtures/reject/src/lib.rs:406:53 | | 1 | dropping a closure that owns a value that drops, which is not supported yet | fixtures/reject/src/lib.rs:51:1 | | 1 | hashing `_` as a key, which is not supported yet | fixtures/reject/src/lib.rs:300:52 | | 1 | hex `Debug`, as in `{:x?}`, is not supported | fixtures/reject/src/lib.rs:88:3 | @@ -56,9 +57,9 @@ The type or module each refused type or path belongs to. | Count | API | First | | ---: | --- | --- | +| 7 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:388:2 | | 6 | `Option` | fixtures/reject/src/lib.rs:28:15 | | 6 | `f64` | fixtures/reject/src/lib.rs:7:14 | -| 6 | `std::borrow::Cow` | fixtures/reject/src/lib.rs:388:2 | | 6 | `u8` | fixtures/reject/src/lib.rs:65:10 | | 4 | `std::string::String` | fixtures/reject/src/lib.rs:95:16 | | 4 | `std::vec::Vec` | fixtures/reject/src/lib.rs:56:2 | @@ -130,6 +131,7 @@ The type or module each refused type or path belongs to. | 1 | an iterator that owns `_`, which drops, which is not supported yet | `Noisy` | fixtures/reject/src/lib.rs:254:20 | | 1 | arithmetic on `_` | `f64` | fixtures/reject/src/lib.rs:8:2 | | 1 | comparing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:300:52 | +| 1 | constructing `_` | `std::borrow::Cow` | fixtures/reject/src/lib.rs:406:53 | | 1 | constructing `_` from another crate | `std::iter::Map` | fixtures/reject/src/lib.rs:173:23 | | 1 | constructing `_` from another crate | `std::iter::Rev` | fixtures/reject/src/lib.rs:194:14 | | 1 | hashing `_` as a key, which is not supported yet | `std::vec::Vec` | fixtures/reject/src/lib.rs:300:52 | @@ -404,6 +406,12 @@ The type or module each refused type or path belongs to.
+
constructing `_` (1) + +- fixtures/reject/src/lib.rs:406:53: constructing `std::borrow::Cow<'_, std::sync::Arc>` + +
+
dropping a closure that owns a value that drops, which is not supported yet (1) - fixtures/reject/src/lib.rs:51:1: dropping a closure that owns a value that drops, which is not supported yet diff --git a/ts/fixtures/reject/expected.txt b/ts/fixtures/reject/expected.txt index 4fa58de9d..bdcf23f69 100644 --- a/ts/fixtures/reject/expected.txt +++ b/ts/fixtures/reject/expected.txt @@ -67,6 +67,7 @@ a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the a variant of `std::borrow::Cow<'_, str>`, which is not supported: either is the same JS string at fixtures/reject/src/lib.rs:395:2 `std::borrow::Cow<'_, [u8]>` is not supported yet at fixtures/reject/src/lib.rs:399:18 unsupported call to ` as std::ops::Deref>::deref` at fixtures/reject/src/lib.rs:400:2 +constructing `std::borrow::Cow<'_, std::sync::Arc>` at fixtures/reject/src/lib.rs:406:53 `&mut std::string::String`: a JS value of `std::string::String` is a copy, so a reference can't change it at fixtures/reject/src/lib.rs:377:15 replacing the value behind a reference to `std::string::String` at fixtures/reject/src/lib.rs:378:4 unsupported call to `core::str::::split::<&str>` at fixtures/reject/src/lib.rs:383:4 diff --git a/ts/fixtures/reject/src/lib.rs b/ts/fixtures/reject/src/lib.rs index 5e91d5bbc..b90db2b03 100644 --- a/ts/fixtures/reject/src/lib.rs +++ b/ts/fixtures/reject/src/lib.rs @@ -399,3 +399,12 @@ pub fn cow_borrowed(c: &std::borrow::Cow<'_, str>) -> bool { pub fn cow_bytes(c: std::borrow::Cow<'_, [u8]>) -> usize { c.len() } + +/// Made where its type goes unchecked, as a local's, it is refused where it is made. +pub fn cow_made(a: &std::sync::Arc) -> usize { + { + let c: std::borrow::Cow<'_, std::sync::Arc> = std::borrow::Cow::Owned(a.clone()); + drop(c); + } + std::sync::Arc::strong_count(a) +} diff --git a/ts/fixtures/reject/ts.toml b/ts/fixtures/reject/ts.toml index 35e5cbb85..f3a690b06 100644 --- a/ts/fixtures/reject/ts.toml +++ b/ts/fixtures/reject/ts.toml @@ -47,6 +47,7 @@ roots = [ "cow_matched", "cow_borrowed", "cow_bytes", + "cow_made", "pushed", "split_str", "missing", diff --git a/ts/src/lower/body.rs b/ts/src/lower/body.rs index 24e7ee2c5..a3b6e2784 100644 --- a/ts/src/lower/body.rs +++ b/ts/src/lower/body.rs @@ -160,7 +160,8 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { if let Some(std) = library::Std::of(tcx, adt_id) { let mut values = values; return match (std, variant.index()) { - (library::Std::Option, 1) | (library::Std::Poll, 0) | (library::Std::Cow, _) => values.pop().unwrap(), + (library::Std::Option, 1) | (library::Std::Poll, 0) => values.pop().unwrap(), + (library::Std::Cow, _) if library::string(tcx, Ty::new_adt(tcx, adt, gargs)) => values.pop().unwrap(), (library::Std::Result, 0) => Expr::rt("Ok", values), (library::Std::Result, _) => Expr::rt("Err", values), _ => self.err(span, format!("constructing `{}`", tcx.def_path_str(adt_id))), diff --git a/ts/src/lower/consts.rs b/ts/src/lower/consts.rs index e1b2a3912..bea39c1bd 100644 --- a/ts/src/lower/consts.rs +++ b/ts/src/lower/consts.rs @@ -104,7 +104,8 @@ impl<'b, 'a, 'tcx> Body<'b, 'a, 'tcx> { if let Some(std) = Std::of(tcx, adt.did()) { return match (std, variant.index()) { (Std::Option, 0) => Expr::undefined(), - (Std::Option | Std::Cow, _) => values.pop().unwrap(), + (Std::Option, _) => values.pop().unwrap(), + (Std::Cow, _) if crate::lower::library::string(tcx, ty) => values.pop().unwrap(), (Std::Result, 0) => Expr::rt("Ok", values), (Std::Result, _) => Expr::rt("Err", values), // `start..=end`, not yet stepped past its end. diff --git a/ts/src/lower/mir/call.rs b/ts/src/lower/mir/call.rs index 6027d20ad..b001af86f 100644 --- a/ts/src/lower/mir/call.rs +++ b/ts/src/lower/mir/call.rs @@ -313,12 +313,13 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { } // A `Cow` is the `String` it would hold, so the `&mut` borrows the same place. ("Cow", "to_mut") if targ(0).is_some_and(|t| t.is_str()) => { - let (place, _) = self.borrowed_place(&args[0].node, span)?; + let (place, borrowed) = self.borrowed_place(&args[0].node, span)?; if let Some(local) = dest.as_local() && self.defs[local] == 1 && matches!(self.slots[local], Slot::Var(_)) { self.slots[local] = Slot::Alias(Some(place)); + self.reborrows.extend(borrowed.map(|b| (local, b))); return Some(None); } done(place, true) diff --git a/ts/src/lower/mir/mod.rs b/ts/src/lower/mir/mod.rs index 5fe395a9c..a92f27181 100644 --- a/ts/src/lower/mir/mod.rs +++ b/ts/src/lower/mir/mod.rs @@ -202,6 +202,9 @@ pub struct Fx<'m, 'b, 'a, 'tcx> { stepped: FxHashSet, /// The borrows `next` steps them by, and what each borrows. stepped_borrows: FxHashMap, + /// References a call returns to what its `&mut` argument borrows, as `Cow::to_mut`'s: + /// the place each reads and writes, which a store through one rebuilds as a `Ref`'s. + reborrows: FxHashMap>, /// The two variables each holds its fields in, by `step`. stepped_vars: FxHashMap, /// Those moved into another, which shares its variables. @@ -275,6 +278,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { range_flags: FxHashMap::default(), stepped: FxHashSet::default(), stepped_borrows: FxHashMap::default(), + reborrows: FxHashMap::default(), stepped_vars: FxHashMap::default(), stepped_into: FxHashMap::default(), noops: FxHashSet::default(), diff --git a/ts/src/lower/mir/place.rs b/ts/src/lower/mir/place.rs index 5673bb954..a93521c52 100644 --- a/ts/src/lower/mir/place.rs +++ b/ts/src/lower/mir/place.rs @@ -412,6 +412,12 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { at = borrowed.project_deeper(rest, tcx); continue; } + if let [ProjectionElem::Deref, rest @ ..] = at.projection.as_slice() + && let Some(&borrowed) = self.reborrows.get(&at.local) + { + at = borrowed.project_deeper(rest, tcx); + continue; + } let [.., ProjectionElem::Downcast(_, variant), ProjectionElem::Field(..)] = at.projection.as_slice() else { break; }; diff --git a/ts/src/lower/mir/rvalue.rs b/ts/src/lower/mir/rvalue.rs index cf64fe591..cb4da9959 100644 --- a/ts/src/lower/mir/rvalue.rs +++ b/ts/src/lower/mir/rvalue.rs @@ -325,7 +325,7 @@ impl<'m, 'b, 'a, 'tcx> Fx<'m, 'b, 'a, 'tcx> { (Std::Poll, 1) => Expr::Rt("Pending".into()), (Std::Option | Std::Poll, _) => values.pop().unwrap(), // Either variant is its text. - (Std::Cow, _) => values.pop().unwrap(), + (Std::Cow, _) if crate::lower::library::string(tcx, ty) => values.pop().unwrap(), (Std::Result, 0) => Expr::rt("Ok", values), (Std::Result, _) => Expr::rt("Err", values), (Std::FmtError, _) => Expr::New(Box::new(Expr::Rt("FmtError".into())), Vec::new()),