Skip to content

Add io::Error::other #91947

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Dec 17, 2021
Merged

Add io::Error::other #91947

merged 1 commit into from
Dec 17, 2021

Conversation

ibraheemdev
Copy link
Member

@ibraheemdev ibraheemdev commented Dec 15, 2021

This PR adds a small utility constructor, io::Error::other, a shorthand for io::Error::new(io::ErrorKind::Other, err), something I find myself writing often.

For some concrete stats, a quick search on grep.app shows that more than half of the uses of io::Error::new use ErrorKind::Other:

Error::new\((?:std::)?(?:io::)?ErrorKind:: => 3,898 results
Error::new\((?:std::)?(?:io::)?ErrorKind::Other => 2,186 results

@rust-highfive
Copy link
Contributor

r? @joshtriplett

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 15, 2021
@joshtriplett
Copy link
Member

I wonder if we could just add a From impl for an arbitrary Error that does exactly this?

@joshtriplett joshtriplett added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Dec 15, 2021
@ibraheemdev
Copy link
Member Author

Thought of that, but it wouldn't work because io::Error already has a few From impls.

@joshtriplett
Copy link
Member

@ibraheemdev Oh, you're right; we probably can't support a general From for arbitrary Error impls because we already have specific impls that would conflict.

In that case, I think this is a fine shortcut to add and experiment with.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 15, 2021

📌 Commit 85f786c has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 15, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 15, 2021
…riplett

Add `io::Error::other`

This PR adds a small utility constructor, `io::Error::other`, a shorthand for `io::Error::new(io::ErrorKind::Other, err)`, something I find myself writing often.

For some concrete stats, a quick search on [grep.app](https://grep.app) shows that more than half of the uses of `io::Error::new` use `ErrorKind::Other`:
```
Error::new\((?:std::)?(?:io::)?ErrorKind:: => 3,898 results
Error::new\((?:std::)?(?:io::)?ErrorKind::Other => 2,186 results
```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 16, 2021
…riplett

Add `io::Error::other`

This PR adds a small utility constructor, `io::Error::other`, a shorthand for `io::Error::new(io::ErrorKind::Other, err)`, something I find myself writing often.

For some concrete stats, a quick search on [grep.app](https://grep.app) shows that more than half of the uses of `io::Error::new` use `ErrorKind::Other`:
```
Error::new\((?:std::)?(?:io::)?ErrorKind:: => 3,898 results
Error::new\((?:std::)?(?:io::)?ErrorKind::Other => 2,186 results
```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 16, 2021
…riplett

Add `io::Error::other`

This PR adds a small utility constructor, `io::Error::other`, a shorthand for `io::Error::new(io::ErrorKind::Other, err)`, something I find myself writing often.

For some concrete stats, a quick search on [grep.app](https://grep.app) shows that more than half of the uses of `io::Error::new` use `ErrorKind::Other`:
```
Error::new\((?:std::)?(?:io::)?ErrorKind:: => 3,898 results
Error::new\((?:std::)?(?:io::)?ErrorKind::Other => 2,186 results
```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 16, 2021
…riplett

Add `io::Error::other`

This PR adds a small utility constructor, `io::Error::other`, a shorthand for `io::Error::new(io::ErrorKind::Other, err)`, something I find myself writing often.

For some concrete stats, a quick search on [grep.app](https://grep.app) shows that more than half of the uses of `io::Error::new` use `ErrorKind::Other`:
```
Error::new\((?:std::)?(?:io::)?ErrorKind:: => 3,898 results
Error::new\((?:std::)?(?:io::)?ErrorKind::Other => 2,186 results
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 16, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#91172 (Warn when a `#[test]`-like built-in attribute macro is present multiple times.)
 - rust-lang#91796 (Fix since attribute for const_manually_drop feature)
 - rust-lang#91879 (Remove `in_band_lifetimes` from `rustc_borrowck`)
 - rust-lang#91947 (Add `io::Error::other`)
 - rust-lang#91967 (Pull in libdevstat on FreeBSD)
 - rust-lang#91987 (Add module documentation for rustdoc passes)
 - rust-lang#92001 (Fix default_method_body_is_const when used across crates)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b742594 into rust-lang:master Dec 17, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 17, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants