forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#136748 - yotamofek:pr/rustdoc-remove-buffer, …
…r=<try> Nuke `Buffer` abstraction from `librustdoc` 💣 In rust-lang#136656 I found out that the `for_html` field in the `Buffer` struct was never read, and pondered if `Buffer` had any utility at all. `@GuillaumeGomez` said he agrees that it can be just removed. So this PR is me removing it. So, r? `@GuillaumeGomez` But... this got *a lot* bigger than I had planned. A lot of functions had a `&mut Buffer` arg, but instead of replacing it with a `buf: impl fmt::Write` arg, I decided to change those functions to return an opaque `impl fmt::Display` instead. If this PR turns out to be contentious I can try to make a PR that just removes the `Buffer` struct and tries to make less invasive changes, but personally I do like some of the cleanups that this PR allows. Let's see what others think! I think it'll be better to review this without whitespace (If this gets positive reactions, I'll need to rebase and maybe try to separate this into logical commits, but not sure if that's very practical) While most of the PR is "cosmetic", I did make some small changes, mostly trying to make some of the formatting lazier, and do less allocations. So a perf run will be nice :) ### Pros and cons of returning `impl fmt::Display` instead of taking a `impl fmt::Write` #### Cons: - Named lifetimes: function signatures got a lot more verbose because the RPIT opaque type needs to be explicitly bound by the lifetimes of the refs in the arguments - Having to use `fmt::from_fn` causes another level of indentation - Immutable closures, can't move out of non-`Copy` items (wasn't much of a problem in practice) #### Pros: - Less arguments, no un-Rusty "out" argument - Nicer composability, allows the returned type to be directly used in format strings ### Interchangeability A function receiving a `impl fmt::Write` can be turned into a function returning a `impl fmt::Display` by using `fmt::from_fn`.
- Loading branch information
Showing
12 changed files
with
2,875 additions
and
2,806 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.