Motivation
Consider this sample code:
pub struct Tar<T = fs::File>
where
T: Read + Write + Seek,
{
handle: T,
}
impl Tar {
// some impls
}
Oops, I forgot to write impl<T: Read + Write + Seek>
in the impl block.
I am in the middle of generalizing Tar
to Tar<T>
, and I am going to release a version where I forgot to generalize it for some methods!
Proposed change
Have some kind of syntax that indicates the invisibility scope of the default parameter.
So for a certain scope, you cannot use the default type.
I don't know a good syntax for this though.
struct Tar<T = pub(crate) fs::File>
? That looks very confusing,
and pretty much means the opposite.
Or struct Tar<T = priv(crate) fs::File>
(since the priv
keyword is already reserved)?
That looks even more weird.
Alternative methods
@malaire on Discord suggested making this a clippy lint instead. But this lint shall be marked on the type parameter instead of for the whole crate. For example, it's very reasonable to want to declare this:
pub type Result<T, E = MyError> = std::result::Result<T, E>;
It would be bad to have warns for using Result<T>
only.
However, there doesn't seem to be a way for marking types for clippy's use only.
I am not sure where it is feasible to implement this on clippy.