A data race that doesn’t compile

By GrowthMax Agency Published June 26, 2026 • 4 min read

Rust’s Type System vs. Data Races

Rust’s type system has long been touted as a solution to the problem of data races in concurrent programming. But can it really refuse to build code that would race? The answer is yes, but not without some creative problem-solving. I set out to prove this in my Redux-flavored Rust library, ruxe, by building a parallel reducer pipeline that would refuse to compile if two reducers touched the same slice of state.

The key insight here is that Rust’s type system can encode the property of disjointness directly. Disjointness means that no two reducers ever touch the same slice of state. This is necessary and sufficient for safe parallel execution. If it holds, parallel is sound. If it doesn’t, parallel races.

The challenge is that Rust’s type system doesn’t have a built-in way to express type inequality. No H != T. No way to write “this trait is implemented if that other one is not implemented”. But what if we reformulate the problem? Instead of asking “are there duplicates?”, we ask “is there a perfect matching?” between slices and reducers. This falls out of Rust’s trait resolution naturally.

Heterogeneous Lists and Recursive Trait Impl

The solution involves using a heterogeneous list (HList) to represent the state’s slice list and the reducer list. An HList is a linked list where each cell can hold a value of a different type. The shape of an HList is recursively defined, allowing the compiler to walk it at compile time.

The Sculptor pattern, borrowed from the frunk crate, is used to extract elements from the HList by their type. This pattern is adapted to match on an associated type instead of a concrete type, allowing us to find the reducer for each slice in the reducer list.

The recursive trait impl for “find the reducer for target slice T” has two impls, which are disambiguated using positional witnesses (Peano numerals at the type level). This ensures that the trait resolver enforces the disjointness guarantee without needing explicit checks.

Winners, Losers, and Disrupted Parties

The winners here are the developers who get to write concurrent code without worrying about data races. The losers are the ones who have to deal with the complexity of the type system. But the real disrupted party is the status quo of concurrent programming. This approach has the potential to change the way we think about parallelism and safety.

The impact of this development is not limited to Rust or even systems programming. The idea of using type systems to encode safety properties can be applied to other languages and domains. This is a signal to watch next: how will other languages respond to the challenge of providing similar guarantees?

The Skeptical Case

One could argue that this approach is too complex, that the type system is too cumbersome to use in practice. And it’s true, the learning curve is steep. But the benefits are worth it. The alternative is to rely on discipline and testing, which is not a reliable way to ensure safety in concurrent code.

Historically, similar attempts to provide safety guarantees through type systems have failed due to complexity and usability issues. But Rust’s type system is different. It’s designed to be expressive and safe, and it has the potential to change the game.

The Signal to Watch Next

The next verifiable event to watch is the adoption of this approach in other languages and domains. Will we see a wave of new languages and libraries that provide similar safety guarantees? Will the industry start to prioritize safety and correctness over performance and ease of use?

Only time will tell, but one thing is certain: the bar for safety and correctness in concurrent programming has been raised. The signal to watch next is how the industry responds to this new challenge.

Pick one tactic from this post and apply it today. Which one will you start with?

By Daniel Cross, Digital Growth Strategist at TrendFlashy

Ready to launch your own asset?

Check out our guide on Building a Profitable Online Business.

Related Articles