Iād love to see some solution to this problem. This kind of feature could go a long way toward simplifying the standard library for newcomers, by allowing us to easily provide a larger number of methods inherently (and shift conventions in that direction).
As you say, thereās some interaction with partial impls ā and indeed, with default methods on traits. Weād probably have to provide some precedence rules. So this precise proposal would make it a bit harder to tell where an item was coming from.
Regarding bounds, itās easy enough to check that the corresponding inherent method is available under whatever constraints the trait impl imposes.
As @nikomatsakis says, though, another option is to drive it from the trait impl side. That has the benefit of greater clarity as to where items are coming from ā it just follows the usual rules for traits. Presumably, if you mark a trait impl as inherent, youāre not allowed to have any overlapping items in other inherent blocks. There also arenāt questions about differences in bounds (although thereās also less flexibility, since the trait bounds effectively become the inherent item bounds).
I havenāt been able to think of a great syntax for an inherent trait impl, though:
// normal trait impl
impl Write for File {
fn write(&mut self, buf: &[u8]) -> Result<usize> { ... }
}
// Possible ways to say "inherent":
// doesn't feel like it should just be an attribute
#[inherent]
impl Write for File { ... }
// `on` vs `for` -- probably too subtle
impl Write on File { ... }
// doesn't match the normal way of writing inherent impls
inherent impl Write for File { ... }
// requires repetition of Self
impl File, Write for File { ... }