Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer is not usable as a trait object #18530

Closed
lifthrasiir opened this issue Nov 2, 2014 · 5 comments
Closed

Buffer is not usable as a trait object #18530

lifthrasiir opened this issue Nov 2, 2014 · 5 comments
Labels
A-trait-system Area: Trait system

Comments

@lifthrasiir
Copy link
Contributor

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.

@sfackler sfackler added A-trait-system Area: Trait system A-libs labels Nov 2, 2014
@alexcrichton
Copy link
Member

cc @aturon

@aturon
Copy link
Member

aturon commented Nov 2, 2014

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
Copy link
Contributor

taralx commented Nov 7, 2014

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

@lifthrasiir
Copy link
Contributor Author

@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
Copy link
Member

aturon commented Nov 16, 2014

This has now been addressed.

@aturon aturon closed this as completed Nov 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

5 participants