Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Try incoherent traits on stable Rust today with Context-Generic Programming

In March, three blog posts sparked a conversation about traits and coherence in Rust. Nadrieril's Elaborating Rust Traits to Explicit Trait Proofs and What If Traits Carried Values introduced the concept of trait implementations as values, while Boxy's An Incoherent Rust explored what Rust would look like with incoherent traits that can opt out of coherence rules.

These discussions gained traction and became a goal for the Rust project. Nadrieril and Niko Matsakis are working on the question of when trait implementations may depend on themselves. Context-Generic Programming (CGP) extends Rust with pluggable trait implementations that can be chosen at compile time based on context. It currently runs on stable Rust.

This post explains how CGP relates to the discussion on incoherent traits, which parts of the Incoherent Rust proposal it can express, and where its context type works similarly to dictionaries in dictionary-passing style. However, CGP falls short in certain aspects.

The post begins with a background and introduction to CGP, followed by desugaring several features of Incoherent Rust into CGP code. It compares CGP's context type with the dictionaries used in dictionary-passing style and states the limitations of expressing Incoherent Rust using CGP. Later sections discuss the capabilities of CGP's providers and contexts beyond the current designs, suggestions for Incoherent Rust, and how other languages handle similar trade-offs.

The discussion surrounding incoherent traits and coherence rules in Rust can be summarized as follows:

1. Nadrieril's post on explicit trait proofs presents traits as structs of methods, with trait bounds acting as values passed along.

2. Boxy's post explores the idea of incoherent traits, which can opt out of Rust's coherence rules, using the example of ecosystem evolution, such as serde for HashMap and associated types.

3. The incoherent traits discussion has led to three separate lines of exploration:

a. The types team's experiment aims to compute each trait proof once during type checking instead of solving the same bounds repeatedly during other phases of the compiler.

b. Nadrieril's vision for a formal specification translates Rust into an interpreter (PolyMiniRust) where every trait proof is explicit.

c. Feature posts demonstrate what explicit proofs would enable, such as incoherent traits and traits carrying values.

These three lines of exploration do not necessarily need to go together, as the compiler might compute proofs once without exposing incoherent traits, and an incoherent traits feature could be designed before the compiler supports it.

Rewritten by urgent.news; may contain errors — check the original.

Source: contextgeneric.dev

Read the original at contextgeneric.dev →

Report a problem with this story

More in Tech

Wine's native runtime update leaves Rosetta 2 behind

Wine has been updated with support for ARM64 macOS, with the native app now able to run Windows games on Apple Silicon Macs faster, and better. Wine lets gamers play Windows games on Mac Games have high demands of the hardware that it runs on, and Wine does its best to cope.

Kernel posts $143 mln net loss in July-Sep 2026

Agribusiness holding Kernel ended the first quarter of fiscal 2027 (FY2027, which began on July 1, 2026) with a net loss of $143 million, compared with a net profit of $95 million in the same quarter of FY2026, according to the company's report published on the Warsaw Stock Exchange late Friday.

More from Monday, 30 November 2026 →