diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-03 14:44:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-03 14:44:21 +0100 |
| commit | 13e284033e34609f5f911d3df989eddec4af3f1b (patch) | |
| tree | 846a319db7993f26e2ee2647b93f86d181bb94d5 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | df921190f3e8236892094a0f45aa5cc77e10f3d2 (diff) | |
| parent | 5960f7a617647f5204e924304b40592ab4f9f51d (diff) | |
| download | rust-13e284033e34609f5f911d3df989eddec4af3f1b.tar.gz rust-13e284033e34609f5f911d3df989eddec4af3f1b.zip | |
Rollup merge of #92444 - dtolnay:coremethods, r=joshtriplett
Consolidate Result's and Option's methods into fewer impl blocks
`Result`'s and `Option`'s methods have historically been separated up into `impl` blocks based on their trait bounds, with the bounds specified on type parameters of the impl block. I find this unhelpful because closely related methods, like `unwrap_or` and `unwrap_or_default`, end up disproportionately far apart in source code and rustdocs:
<pre>
impl<T> Option<T> {
pub fn unwrap_or(self, default: T) -> T {
...
}
<img alt="one eternity later" src="https://user-images.githubusercontent.com/1940490/147780325-ad4e01a4-c971-436e-bdf4-e755f2d35f15.jpg" width="750">
}
impl<T: Default> Option<T> {
pub fn unwrap_or_default(self) -> T {
...
}
}
</pre>
I'd prefer for method to be in as few impl blocks as possible, with the most logical grouping within each impl block. Any bounds needed can be written as `where` clauses on the method instead:
```rust
impl<T> Option<T> {
pub fn unwrap_or(self, default: T) -> T {
...
}
pub fn unwrap_or_default(self) -> T
where
T: Default,
{
...
}
}
```
*Warning: the end-to-end diff of this PR is computed confusingly by git / rendered confusingly by GitHub; it's practically impossible to review that way. I've broken the PR into commits that move small groups of methods for which git behaves better — these each should be easily individually reviewable.*
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
