-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Trait object coercion without as
#10039
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
Comments
I really want this. I tried to port the visitor code to use objects and it was horribly tedious to insert the manual coercions. I would be happy to work on it once I get some of my current branches cleared off, but also happy to review anyone else's efforts. |
High priority but not 1.0 |
👍 I found this pretty surprising. Just improving the error message would go a long way here. |
I'd like to give my 👍 to this. Running into this was confusing as a first-time Rust user, and the code we ended needing to write up became very obtuse. I'm pretty sure I couldn't have figured it out with nagging people in the IRC channel. It makes code that should be straightforward even more annoying if you want to re-use the coerced object in multiple places by pulling it into a variable: // Where OutputWriter is a struct and OutputStream is a trait it implements
let mut writer = OutputWriter::new(counter.bytecount);
let &mut writer_stream = &mut writer as &mut OutputStream;
do_something_with_writer_stream(writer_stream);
// Calling writer.bytes() moves the original writer out, so
// the compiler complains because there is still a mutable loan outstanding.
writer.bytes(); |
…time, r=dswij Use ubuntu-20.04 instead of ubuntu-latest changelog: none r? `@ghost` I'll create an issue, to undo this change, once the CI passes on `ubuntu-latest` again
When creating a trait object, I shouldn't have to write
&mut obj as &mut Trait
, I should be able to just write&mut obj
and the compiler will coerce it to&mut Trait
.I remember awhile ago that @pcwalton had a patch to do this, but then it fell by the wayside. I was under the impression that we want to get this done, so I'm nominating this for 1.0.
The text was updated successfully, but these errors were encountered: