about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-01-03 14:44:21 +0100
committerGitHub <noreply@github.com>2022-01-03 14:44:21 +0100
commit13e284033e34609f5f911d3df989eddec4af3f1b (patch)
tree846a319db7993f26e2ee2647b93f86d181bb94d5 /compiler/rustc_errors/src
parentdf921190f3e8236892094a0f45aa5cc77e10f3d2 (diff)
parent5960f7a617647f5204e924304b40592ab4f9f51d (diff)
downloadrust-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&lt;T&gt; Option&lt;T&gt; {
    pub fn unwrap_or(self, default: T) -&gt; T {
        ...
    }

    <img alt="one eternity later" src="https://user-images.githubusercontent.com/1940490/147780325-ad4e01a4-c971-436e-bdf4-e755f2d35f15.jpg" width="750">
}

impl&lt;T: Default&gt; Option&lt;T&gt; {
    pub fn unwrap_or_default(self) -&gt; 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 &mdash; these each should be easily individually reviewable.*
Diffstat (limited to 'compiler/rustc_errors/src')
0 files changed, 0 insertions, 0 deletions