Summary
Change the definition of Into trait such that it does not require Self: Sized.
pub trait Into<T> {
/// Performs the conversion.
fn into(self) -> T;
}
Motivation
As we don’t have #[feature(unsized_locals)] before, we don’t want to allow dyn Into<T> because it will be useless.
Once we allow object safe methods to receive self by value, the reason above disappears.
Enabling dyn Into<T> on the other hand, enables a lot of new abstractions to appear, and it can be seen as Rust’s standard representation of lazy evaluations. For example, we can image the short circuit boolean operation being defined as
trait And<Rhs=Self> {
type Output;
fn and(self, rhs: dyn Into<Rhs>) -> Self::Output;
}
impl And for bool {
type Output = bool;
fn and(self, rhs: dyn Into<bool>) -> bool {
if self { return true } else { rhs.into() }
}
}
(The above is not implied in this RFC, only demonstrates future improvement possibilities).
(However, many other traits in std::ops can be relaxed like this, I am not sure shall I included them as well.)
(Add/Div/... were already relaxed…)