about summary refs log tree commit diff
path: root/library/std/src/io/error.rs
AgeCommit message (Collapse)AuthorLines
2021-10-11Rollup merge of #89753 - jkugelman:must-use-from_value-conversions, ↵Guillaume Gomez-0/+1
r=joshtriplett Add #[must_use] to from_value conversions I added two methods to the list myself. Clippy did not flag them because they take `mut` args, but neither modifies their argument. ```rust core::str const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str; std::ffi::CString unsafe fn from_raw(ptr: *mut c_char) -> CString; ``` I put a custom note on `from_raw`: ```rust #[must_use = "call `drop(from_raw(ptr))` if you intend to drop the `CString`"] pub unsafe fn from_raw(ptr: *mut c_char) -> CString { ``` Parent issue: #89692 r? ``@joshtriplett``
2021-10-10Add #[must_use] to conversions that move selfJohn Kugelman-0/+1
2021-10-10Add #[must_use] to from_value conversionsJohn Kugelman-0/+1
2021-08-24Fix tidyIan Jackson-2/+2
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24io::ErrorKind: rationalise ordering in main enumIan Jackson-17/+24
It is useful to keep some coherent structure to this ordering. In particular, Other and Uncategorized should be next to each other, at the end. Also it seems to make sense to treat UnexpectedEof and OutOfMemory specially, since they are not like the other errors (despite OutOfMemory also being generatable by some OS errors). So: * Move Other to the end, just before Uncategorized * Move Unsupported to between Interrupted and UnexpectedEof * Add some comments documenting where to add things Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-08-24io::Error: alphabeticise the match in as_str()Ian Jackson-5/+6
There was no rationale for the previous ordering. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-07-03Auto merge of #79965 - ijackson:moreerrnos, r=joshtriplettbors-21/+139
More ErrorKinds for common errnos From the commit message of the main commit here (as revised): ``` There are a number of IO error situations which it would be very useful for Rust code to be able to recognise without having to resort to OS-specific code. Taking some Unix examples, `ENOTEMPTY` and `EXDEV` have obvious recovery strategies. Recently I was surprised to discover that `ENOSPC` came out as `ErrorKind::Other`. Since I am familiar with Unix I reviwed the list of errno values in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/errno.h.html Here, I add those that most clearly seem to be needed. `@CraftSpider` provided information about Windows, and references, which I have tried to take into account. This has to be insta-stable because we can't sensibly have a different set of ErrorKinds depending on a std feature flag. I have *not* added these to the mapping tables for any operating systems other than Unix and Windows. I hope that it is OK to add them now for Unix and Windows now, and maybe add them to other OS's mapping tables as and when someone on that OS is able to consider the situation. I adopted the general principle that it was usually a bad idea to map two distinct error values to the same Rust error code. I notice that this principle is already violated in the case of `EACCES` and `EPERM`, which both map to `PermissionDenied`. I think this was probably a mistake but it would be quite hard to change now, so I don't propose to do anything about that. However, for Windows, there are sometimes different error codes for identical situations. Eg there are WSA* versions of some error codes as well as ERROR_* ones. Also Windows seems to have a great many more erorr codes. I don't know precisely what best practice would be for Windows. ``` <strike> ``` Errno values I wasn't sure about so *haven't* included: EMFILE ENFILE ENOBUFS ENOLCK: These are all fairly Unix-specific resource exhaustion situations. In practice it seemed not very likely to me that anyone would want to handle these differently to `Other`. ENOMEM ERANGE EDOM EOVERFLOW Normally these don't get exposed to the Rust callers I hope. They don't tend to come out of filesystem APIs. EILSEQ Hopefully Rust libraries open files in binary mode and do the converstion in Rust. So Rust code ought not to be exposed to EILSEQ. EIO The range of things that could cause this is troublesome. I found it difficult to describe. I do think it would be useful to add this at some point, because EIO on a filesystem operation is much more serious than most other errors. ENETDOWN I wasn't sure if this was useful or, indeed, if any modern systems use it. ENOEXEC It is not clear to me how a Rust program could respond to this. It seems rather niche. EPROTO ENETRESET ENODATA ENOMSG ENOPROTOOPT ENOSR ENOSTR ETIME ENOTRECOVERABLE EOWNERDEAD EBADMSG EPROTONOSUPPORT EPROTOTYPE EIDRM These are network or STREAMS related errors which I have never in my own Unix programming found the need to do anything with. I think someone who understands these better should be the one to try to find good Rust names and descriptions for them. ENOTTY ENXIO ENODEV EOPNOTSUPP ESRCH EALREADY ECANCELED ECHILD EINPROGRESS These are very hard to get unless you're already doing something very Unix-specific, in which case the raw_os_error interface is probably more suitable than relying on the Rust ErrorKind mapping. EFAULT EBADF These would seem to be the result of application UB. ``` </strike> <i>(omitted errnos are discussed below, especially in https://github.com/rust-lang/rust/pull/79965#issuecomment-810468334)
2021-06-25Restore original ordering of `ErrorKind::Other`.Mara Bos-8/+9
2021-06-20ErrorKind: Add missing full stopsIan Jackson-3/+3
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-20ErrorKind::FilesystemLoop: Generalise dscriptionIan Jackson-3/+4
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18ErrorKind::NotSeekable: Fix reference to File::open()Ian Jackson-1/+1
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18ErrorKind: Provide many more ErrorKinds, motivated by Unix errnosIan Jackson-0/+116
Rationale for the mappings etc. is extensively discussed in the MR https://github.com/rust-lang/rust/pull/79965 Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-18ErrorKind: Reformat the error string tableIan Jackson-21/+22
* Sort alphabetically. * use ErrorKind::*; Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-06-15Rename ErrorKind::Unknown to Uncategorized.Mara Bos-6/+6
2021-06-15Redefine `ErrorKind::Other` and stop using it in std.Mara Bos-10/+24
2021-05-03Correct stability of ErrorKind::OutOfMemoryKornel-1/+1
2021-05-02Add ErrorKind::OutOfMemoryKornel-0/+6
2021-04-18Bump to 1.53.0CDirkx-1/+1
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2021-04-18Rename `NotSupported` to `Unsupported`Christiaan Dirkx-4/+6
2021-04-18Bump since to 1.52.0CDirkx-1/+1
2021-04-18Add and insta-stabilize `std::io::ErrorKind::NotSupported`Christiaan Dirkx-0/+5
2021-03-27Add #[inline] to io::Error methods.Mara Bos-0/+8
2021-03-21Fix typosMara Bos-2/+2
Co-authored-by: the8472 <the8472@users.noreply.github.com>
2021-03-21Add internal io::Error::new_const tot avoid allocations.Mara Bos-0/+26
2020-08-31std: move "mod tests/benches" to separate filesLzu Tao-57/+3
Also doing fmt inplace as requested.
2020-08-18Move to intra doc links for std::ioAlexis Bourget-30/+35
2020-07-27mv std libs to library/mark-0/+628