External Publication
Visit Post

[Pre-pre RFC] Allow exclusion of trait methods for (certain) unsatisfiable where bounds

Rust Internals [Unofficial] April 9, 2026
Source

Take these 2 traits:

trait Bar {}
trait Foo {
    fn func(self) -> Self
    where Self: Bar;
    ..other items..
}

Right now, there is no way to implement Foo for a type that doesn't implement Bar without refining fn func to not have the bound, defeating its entire purpose. There are sometimes some work arounds, like you could do this:

struct SomeType<T> {...}
/// # Safety
/// just don't
unsafe trait NoImpl {}
impl<T: NoImpl > Bar for SomeType<T> {}
impl Foo for SomeType {
     fn func(self) -> Self
     where Self: Bar {
         unimplemented!();
     }
     ..other items..
}

(or implementing it for an empty enum/!) but this requires a generic and Bar not to be something like Send or Sync which can often defeat the whole purpose, especially when using traits a impl blocks on foreign types. This also makes it appear that there may be some way to access fn func on SomeType even when its entirely inaccessible. Removing the requirement to include the function would fix this problem. Done universally, this would cause a issue where new trait impl are now breaking changes, so instead it needs to have the following restraint: The trait in the where bound that is unsatisfiable must be defined in the same crate and doesn't have any auto-impl that could be satisfied for the type by the type gaining new foreign trait impls. Simply having the type being local isn't enough because if the trait got a new auto-impl or loosened the restrictions on its auto-impl, it would be a breaking change.

Discussion in the ATmosphere

Loading comments...