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

Remove io::io_error #10449

Closed
wants to merge 1 commit into from

Conversation

alexcrichton
Copy link
Member

This commit removes all usage of conditions from the runtime and I/O
implementation. The new idea is to return IoResult which is a typedef on
Result<T, IoError>. The error portion of this may wish to change in the future,
but for now it's a good step forward to remove conditions.

Some notable changes:

  • the if_ok!/seq! macros -- right now these are only defined in libstd, but they're definitely in the wrong spot and may belong in the core-macro injection as well.
  • Removed ByteIterator - no way to propagate I/O errors any more
  • The fmt traits must now return IoResult<()> - need to propagate errors
  • All I/O errors in json encoding/decode are now ignored
  • All I/O errors in rustdoc are now ignored
  • The signature of print/println has changed - need to propagate the error
  • The signature of read_bytes() has changed - need to return partially-read data

This is not quite ready for merging just yet. I'd like to get some feedback on this before cleaning this up for a true merge. I don't like how errors are default not-fatal any more, but the code isn't really that much less readable in my opinion. There's also not a lot of heavy I/O code except for rustdoc which just ignores all errors, so this perhaps isn't the best showcase of conversion.

I'm mainly soliciting for feedback about this. I think that this is the right way to go in general (moving away from conditions), but if there are any reservations about the specifics we should probably discuss them now.

@bill-myers
Copy link
Contributor

It might be sensible to implement Drop on either Result, IoError or a variant of Result that calls fail! in the error case, and a language change so that destructuring it is possible and skips dropping.

This way, errors would continue to be fatal by default.

Regarding ByteIterator, why not just store the result of the last operation (i.e. the one that returned EOF or another error) and adding a "finish" method that would take the ByteIterator by value and get the contained IoError?

Maybe one could even extend foreach so that the value of the foreach statement is the return value of the finish method (provided the iterator implements the appropriate trait), but not sure about this.

@alexcrichton
Copy link
Member Author

I was thinking of how to do something like that, but I couldn't really come up with a convenient structure which behaved like that. I'd love to have one, but I don't seem to be able to come up with an implementation :(

@glaebhoerl
Copy link
Contributor

I assume making I/O errors fail!() and using try() to handle them is still out of the question for performance reasons?

This commit removes all usage of conditions from the runtime and I/O
implementation. The new idea is to return IoResult which is a typedef on
Result<T, IoError>. The error portion of this may wish to change in the future,
but for now it's a good step forward to remove conditions.

Some notable changes:

* the if_ok!/seq! macros
* Removed ByteIterator
* The fmt traits must now return IoResult<()>
* All I/O errors in json encoding/decode are now ignored
* All I/O errors in rustdoc are now ignored
* The signature of print/println has changed
* The signature of read_bytes() has changed
@alexcrichton
Copy link
Member Author

This isn't making as much progress as I would like, and I believe that this requires more thought than I'm giving it. Closing for now.

@alexcrichton alexcrichton deleted the remove-io-error branch February 1, 2014 00:26
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 6, 2023
…tr-casts-parens, r=Jarcho

Wrap `transmutes_expressible_as_ptr_casts` suggestions in parentheses

changelog: [`transmutes_expressible_as_ptr_casts`]: Fix suggestion missing wrapping parentheses

Fixes rust-lang#10449

r? `@Jarcho`

Is this the best way to go about this? `unused_parens` will catch the unnecessary ones but emitting them in the first place isn't ideal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants