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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ generic std gap is planned here even when moq never calls it.
- [The capacity of a BytesMut](/quest/m3/ts-bytes-capacity.md) - `BytesMut::capacity` and what reads it translate with `bytes`' values
- [BufMut's provided writes through a &mut](/quest/m3/ts-buf-mut-forward.md) - `put`, `put_bytes`, `put_uint`, and `put_int` of a `&mut Vec<u8>` or `&mut BytesMut` translate
- [Trait objects](/quest/m3/ts-dyn.md) - `dyn Error`, `dyn Iterator`, `dyn Buf`, and `Arc<dyn Debug>` translate, so a consumer neither rewrites nor binds them
- [A widening try_from typed by its Infallible](/quest/m3/ts-try-from-infallible.md) - an integer `try_from` that can't fail type-checks as `Result<T, Infallible>`
- [Placeholders written to a crate's own fmt::Write](/quest/m3/ts-fmt-calls.md) - `write!` with placeholders into a crate's own writer translates, its `write_str` seeing each call std makes
- [Waiting: type-check in process with tsrs](/quest/m3/ts-tsrs.md) - rust2-ts checks bindings through tsrs instead of `tsc` once it is a stable library
- [An inclusive range folded through an adaptor](/quest/m3/ts-range-fold.md) - a `RangeInclusive` folded through `map`, `filter`, or `rev` ends in core's state, and `by_ref` of one type-checks
Expand All @@ -35,4 +34,5 @@ generic std gap is planned here even when moq never calls it.
- [Peekable::next_if_eq against another type](/quest/m3/ts-next-if-eq-other.md) - `next_if_eq` with an expected value of another type than the item, such as a `&str` of `String` items, translates
- [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form
- [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does
- [A switch whose other variants are uninhabited](/quest/m3/ts-uninhabited-switch.md) - a tuple's `Result<_, Infallible>`s matched or bound by `let` type-checks, its discriminant reads no longer left unused
- [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - an instance whose lowering drops every read of a parameter marks it unused, so `tsc` accepts it
17 changes: 0 additions & 17 deletions quest/m3/ts-try-from-infallible.md

This file was deleted.

24 changes: 24 additions & 0 deletions quest/m3/ts-uninhabited-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# [S] A switch whose other variants are uninhabited

## Goal

[rust2-ts](/ts/README.md) translates a match or `let` that tests a part of a tuple or
other non-path place whose other variants can't exist, such as
`let (Ok(a), Ok(b)) = (wide, wider);` of two `Result<_, Infallible>`s, without leaving the
discriminant it read unused, so `tsc` accepts it, proven by differential tests against
native Rust.

## Plan

Found by the quest that typed an infallible `try_from` by its `Infallible`, on 2026-10-30:
MIR reads each part's discriminant and switches to `unreachable` otherwise; lowering drops
that one-way switch, but the read was already spilled to a `const scrutinee` (the
`Slot::Discr` assignment in `ts/src/lower/mir/mod.rs`), which `noUnusedLocals` refuses.
A single `match` or `let Ok(x) = r` of such a `Result` already type-checks. No consumer
hits it at the pin.

Public API: the translator's output.

## Related

- [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - the same kind of read lowering leaves unused, of a parameter
110 changes: 110 additions & 0 deletions ts/fixtures/lang/expected/core/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,46 @@ export function eq$0pe0qmq(self: rt.Result<rt.i128, rt.ParseIntError>, other: rt
return eq$18sin5z(self.error, (other as { ok: false; error: rt.ParseIntError }).error);
}

export function eq$0pee78b(self: rt.Result<rt.i128, never>, other: rt.Result<rt.i128, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return rt.i128Eq(self.value, (other as { ok: true; value: rt.i128 }).value);
}
return true;
}

export function eq$1mi4cle(self: rt.Result<rt.i16, never>, other: rt.Result<rt.i16, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return self.value === (other as { ok: true; value: rt.i16 }).value;
}
return true;
}

export function eq$1ukayff(self: rt.Result<rt.i32, never>, other: rt.Result<rt.i32, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return self.value === (other as { ok: true; value: rt.i32 }).value;
}
return true;
}

export function eq$1hy1is1(self: rt.Result<rt.i64, never>, other: rt.Result<rt.i64, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return rt.i64Eq(self.value, (other as { ok: true; value: rt.i64 }).value);
}
return true;
}

export function eq$1mpp8xa(self: rt.Result<rt.i8, rt.ParseIntError>, other: rt.Result<rt.i8, rt.ParseIntError>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
Expand All @@ -121,6 +161,26 @@ export function eq$0grmb7g(self: rt.Result<rt.i8, rt.TryFromIntError>, other: rt
return eq$1nf2rde(self.error, (other as { ok: false; error: rt.TryFromIntError }).error);
}

export function eq$1hd8lo9(self: rt.Result<rt.i8, never>, other: rt.Result<rt.i8, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return self.value === (other as { ok: true; value: rt.i8 }).value;
}
return true;
}

export function eq$0w2dfat(self: rt.Result<rt.isize, never>, other: rt.Result<rt.isize, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return self.value === (other as { ok: true; value: rt.isize }).value;
}
return true;
}

export function eq$0rj0czq(self: rt.Result<string, rt.Utf8Error>, other: rt.Result<string, rt.Utf8Error>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
Expand All @@ -131,6 +191,16 @@ export function eq$0rj0czq(self: rt.Result<string, rt.Utf8Error>, other: rt.Resu
return eq$1v93ipo(self.error, (other as { ok: false; error: rt.Utf8Error }).error);
}

export function eq$06vyx9e(self: rt.Result<rt.u128, never>, other: rt.Result<rt.u128, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return rt.u128Eq(self.value, (other as { ok: true; value: rt.u128 }).value);
}
return true;
}

export function eq$08241oi(self: rt.Result<rt.u16, never>, other: rt.Result<rt.u16, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
Expand All @@ -141,6 +211,16 @@ export function eq$08241oi(self: rt.Result<rt.u16, never>, other: rt.Result<rt.u
return true;
}

export function eq$0nbftnc(self: rt.Result<rt.u32, never>, other: rt.Result<rt.u32, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return self.value === (other as { ok: true; value: rt.u32 }).value;
}
return true;
}

export function eq$0bl30vt(self: rt.Result<rt.u64, rt.ParseIntError>, other: rt.Result<rt.u64, rt.ParseIntError>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
Expand All @@ -151,6 +231,16 @@ export function eq$0bl30vt(self: rt.Result<rt.u64, rt.ParseIntError>, other: rt.
return eq$18sin5z(self.error, (other as { ok: false; error: rt.ParseIntError }).error);
}

export function eq$1gq81ib(self: rt.Result<rt.u64, never>, other: rt.Result<rt.u64, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return rt.u64Eq(self.value, (other as { ok: true; value: rt.u64 }).value);
}
return true;
}

export function eq$1fkhuzl(self: rt.Result<rt.u8, rt.IntErrorKind>, other: rt.Result<rt.u8, rt.IntErrorKind>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
Expand All @@ -171,6 +261,16 @@ export function eq$0p1bb4y(self: rt.Result<rt.u8, rt.ParseIntError>, other: rt.R
return eq$18sin5z(self.error, (other as { ok: false; error: rt.ParseIntError }).error);
}

export function eq$12e5exx(self: rt.Result<rt.u8, never>, other: rt.Result<rt.u8, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return self.value === (other as { ok: true; value: rt.u8 }).value;
}
return true;
}

export function eq$03gbayb(self: rt.Result<undefined, rt.FmtError>, other: rt.Result<undefined, rt.FmtError>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
Expand All @@ -181,6 +281,16 @@ export function eq$03gbayb(self: rt.Result<undefined, rt.FmtError>, other: rt.Re
return eq$08q6k9m(self.error, (other as { ok: false; error: rt.FmtError }).error);
}

export function eq$1xhgva4(self: rt.Result<rt.usize, never>, other: rt.Result<rt.usize, never>): boolean {
if (!((self.ok ? 0 : 1) === (other.ok ? 0 : 1))) {
return false;
}
if (self.ok) {
return self.value === (other as { ok: true; value: rt.usize }).value;
}
return true;
}

export function isOkAnd$0jj0nkw(self: rt.Result<rt.u8, rt.u16>, f: (a0: rt.u8) => boolean): boolean {
if (self.ok) {
return f(self.value);
Expand Down
6 changes: 3 additions & 3 deletions ts/fixtures/lang/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { ints, strings, derived, written, counts, rounding, panics, wrapped, wri
import { methods } from "./generics.ts";
import { values, random, bytes as hashes_bytes } from "./hashes.ts";
import { holds } from "./holds.ts";
import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast as ints_cast, convert, parses as ints_parses } from "./ints.ts";
import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast as ints_cast, convert, parses as ints_parses, widenings } from "./ints.ts";
import { adaptors, consumers, reducers, skips, ranked, ranges, options, own, values as iters_values, returned } from "./iters.ts";
import { keys, overrides, bytes as keys_bytes } from "./keys.ts";
import { locals } from "./locals.ts";
Expand Down Expand Up @@ -90,7 +90,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec)
refs(data21, out21);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2121: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => {
counts(data22, out22);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _393: rt.ByteSlice, out23: rt.ByteVec): void => {
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _396: rt.ByteSlice, out23: rt.ByteVec): void => {
rounding(out23);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::skips", skips] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["wrappers::wrappers", wrappers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::edits", edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["utf8::decodes", decodes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::floats", floats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["atomics::atomics", atomics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::overrides", overrides] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::dyns", (_2123: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => {
dyns(data23, out24);
Expand Down Expand Up @@ -180,7 +180,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec)
made(data65, out66);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["arrays::as_slices", (_2166: rt.u8, data66: rt.ByteSlice, out67: rt.ByteVec): void => {
asSlices(data66, out67);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]];
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::widenings", widenings] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]];
}

/** Run one case. */
Expand Down
14 changes: 14 additions & 0 deletions ts/fixtures/lang/expected/ints.Scaled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

/** A type of the crate's own that `From` makes, which `try_from` converts by. */
export interface Scaled {
_0: rt.u32;
}

export function from$From_u8(b: rt.u8): Scaled {
return { _0: rt.u32Mul(b as rt.u32, 1000) };
}

//# sourceMappingURL=ints.Scaled.ts.map
Loading