Change:
Some types ( and in particular) implement and on . If one of these types are wrapped in an (or ), there is no real reason why one shouldn't be able to call or methods on it. For example, this code should compile: I think this can be implemented pretty straightforwardly by adding the following impls to and : Are there good reasons for why impls like these shouldn't be ?
Closing because generic impls like proposed won't behave correctly, as described in .

Discussion:
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write}; use crate::path::{Path, PathBuf}; use crate::sealed::Sealed; <ins> use crate::sync::Arc; </ins> use crate::sys::fs as fs_imp; use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; use crate::time::SystemTime;

} #[stable(feature = "rust1", since = "1.0.0")] <del> impl Read for File { </del> <ins> impl Read for &File { </ins> fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { self.inner.read(buf) }

} } #[stable(feature = "rust1", since = "1.0.0")] <del> impl Write for File { </del> <ins> impl Write for &File { </ins> fn write(&mut self, buf: &[u8]) -> io::Result<usize> { self.inner.write(buf) }

} } #[stable(feature = "rust1", since = "1.0.0")] <del> impl Seek for File { </del> <ins> impl Seek for &File { </ins> fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { self.inner.seek(pos) } } #[stable(feature = "rust1", since = "1.0.0")] <del> impl Read for &File { </del> <ins> impl Read for File { </ins> fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { <del> self.inner.read(buf) </del> <ins> (&*self).read(buf) } fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { (&*self).read_vectored(bufs) </ins> } fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { <del> self.inner.read_buf(cursor) </del> <ins> (&*self).read_buf(cursor) } #[inline] fn is_read_vectored(&self) -> bool { (&&*self).is_read_vectored() } fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> { (&*self).read_to_end(buf) } fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> { (&*self).read_to_string(buf) } } #[stable(feature = "rust1", since = "1.0.0")] impl Write for File { fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (&*self).write(buf) } fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> { (&*self).write_vectored(bufs) } #[inline] fn is_write_vectored(&self) -> bool { (&&*self).is_write_vectored() } fn flush(&mut self) -> io::Result<()> { (&*self).flush() } } #[stable(feature = "rust1", since = "1.0.0")] impl Seek for File { fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (&*self).seek(pos) </ins> } <ins> } #[stable(feature = "io_traits_arc", since = "CURRENT_RUSTC_VERSION")] impl Read for Arc<File> { fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { (&**self).read(buf) } </ins> fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> { <del> self.inner.read_vectored(bufs) </del> <ins> (&**self).read_vectored(bufs) } fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> { (&**self).read_buf(cursor) </ins> } #[inline] fn is_read_vectored(&self) -> bool { <del> self.inner.is_read_vectored() </del> <ins> (&**self).is_read_vectored() </ins> } <del> // Reserves space in the buffer based on the file size when available. </del> fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> { <del> let size = buffer_capacity_required(self); buf.reserve(size.unwrap_or(0)); io::default_read_to_end(self, buf, size) </del> <ins> (&**self).read_to_end(buf) </ins> } <del> // Reserves space in the buffer based on the file size when available. </del> fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> { <del> let size = buffer_capacity_required(self); buf.reserve(size.unwrap_or(0)); io::default_read_to_string(self, buf, size) </del> <ins> (&**self).read_to_string(buf) </ins> } } <del> #[stable(feature = "rust1", since = "1.0.0")] impl Write for &File { </del> <ins> #[stable(feature = "io_traits_arc", since = "CURRENT_RUSTC_VERSION")] impl Write for Arc<File> { </ins> fn write(&mut self, buf: &[u8]) -> io::Result<usize> { <del> self.inner.write(buf) </del> <ins> (&**self).write(buf) </ins> } fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> { <del> self.inner.write_vectored(bufs) </del> <ins> (&**self).write_vectored(bufs) </ins> } #[inline] fn is_write_vectored(&self) -> bool { <del> self.inner.is_write_vectored() </del> <ins> (&**self).is_write_vectored() </ins> } fn flush(&mut self) -> io::Result<()> { <del> self.inner.flush() </del> <ins> (&**self).flush() </ins> } } <del> #[stable(feature = "rust1", since = "1.0.0")] impl Seek for &File { </del> <ins> #[stable(feature = "io_traits_arc", since = "CURRENT_RUSTC_VERSION")] impl Seek for Arc<File> { </ins> fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { <del> self.inner.seek(pos) </del> <ins> (&**self).seek(pos) </ins> } }