rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.13k stars 12.69k forks source link

`Buffer` is not usable as a trait object #18530

Closed lifthrasiir closed 9 years ago

lifthrasiir commented 10 years ago
let mut buf = std::io::BufReader::new(b"asdf");
let _: &mut Buffer = &mut buf; // error

As a side effect of #17704 (and I think @huonw has noted this possibility correctly), std::io::Buffer is no longer usable as a trait object. We need a separate trait and a blacket implementation for it.

alexcrichton commented 10 years ago

cc @aturon

aturon commented 10 years ago

Indeed, this seems to've been missed in the original rollout. As usual, this will actually make the default methods more widely usable.

We need to develop a convention around these extra blanket extension traits.

taralx commented 9 years ago

Is it actually unsafe to use Self in the return type?

lifthrasiir commented 9 years ago

@taralx It wouldn't make sense from the perspective of the caller. The caller cannot see the concrete type that makes the return value up (T<Self> and T<Trait> are quite different). A proxy that converts the return value to the trait object may work, but it is surprising and it still doesn't work for every Self-typed return value (e.g. iterators).

aturon commented 9 years ago

This has now been addressed.