about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-03 12:17:19 +0000
committerbors <bors@rust-lang.org>2022-07-03 12:17:19 +0000
commitb04bfb4aea99436a62f6a98056e805eb9b0629cc (patch)
treeeef697fac1f57d2430ef72c8261c02311e549d91 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parentf99f9e48ed77a99747c6d07b42fdfe500f1a7de0 (diff)
parentcf483a130cdfa1e72678fd98c74b11fedb3ae8dd (diff)
downloadrust-b04bfb4aea99436a62f6a98056e805eb9b0629cc.tar.gz
rust-b04bfb4aea99436a62f6a98056e805eb9b0629cc.zip
Auto merge of #97437 - jyn514:impl-asrawfd-arc, r=dtolnay
`impl<T: AsRawFd> AsRawFd for {Arc,Box}<T>`

This allows implementing traits that require a raw FD on Arc and Box.

Previously, you'd have to add the function to the trait itself:

```rust
trait MyTrait {
    fn as_raw_fd(&self) -> RawFd;
}

impl<T: MyTrait> MyTrait for Arc<T> {
    fn as_raw_fd(&self) -> RawFd {
        (**self).as_raw_fd()
    }
}
```

In particular, this leads to lots of "multiple applicable items in scope" errors because you have to disambiguate `MyTrait::as_raw_fd` from `AsRawFd::as_raw_fd` at each call site. In generic contexts, when passing the type to a function that takes `impl AsRawFd` it's also sometimes required to use `T: MyTrait + AsRawFd`, which wouldn't be necessary if I could write `MyTrait: AsRawFd`.

After this PR, the code can be simpler:
```rust
trait MyTrait: AsRawFd {}

impl<T: MyTrait> MyTrait for Arc<T> {}
```
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions