Radar · Rust · Archive · Week 3 · Jan 13 – 19, 2025
Supertrait Item Shadowing v2
Worth knowinglanguage
- What changed
- When name resolution encounters an ambiguity between two trait methods, if one trait is a sub‑trait of the other then the method from the sub‑trait is selected instead of reporting an ambiguity error.
- Production impact
- The source does not say.
- Try it
- Write a small program that implements a trait and its supertrait with overlapping method names and observe that the sub‑trait method is chosen.
- Source
- github.com/rust-lang/rfcs/pull/3624
Understand it, then run it
When two traits give a method with the same name, Rust normally tells you “ambiguous” and you have to be explicit. The new rule says that if one of those traits is a sub‑trait of the other, the method from the sub‑trait wins automatically. This means you no longer get an error when you call a method that exists on both a trait and a trait that extends it. The change is a small tweak to name resolution, not a new language feature.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed