Context-Generic Programming as a way to try Incoherent Rust on stable Rust
The post explains how Context-Generic Programming (CGP)[1] relates to a recent discussion about Incoherent Rust[2], a possible version of Rust in which traits could opt out of Rust's coherence rules. The discussion started in March with three blog posts by Nadrieril and Boxy and has since become a Rust project goal. CGP extends Rust with pluggable trait implementations, chosen for each context at compile time, and it works on stable Rust today.
The author looks at which parts of Incoherent Rust CGP can express now, and where its context type works like the dictionaries of dictionary-passing style[3]. As an example, the post redefines serde's Serialize trait with a #[cgp_component] macro, which generates a provider trait[4] named SerializeImpl, and adds a provider that serializes a value as its Display string.
According to the author, CGP lets a significant subset of Incoherent Rust be tried on stable Rust, but it does not solve the formalization goal and only partly addresses ecosystem evolution for existing traits. The post also names specific challenges that full dictionary-passing style in Rust would need to address. The draft was written in April and revised before publication.
Read the original contextgeneric.devDiscussion
Sources
-
contextgeneric.dev
Trying Incoherent Rust today with Context-Generic Programming

