diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-11-20 14:15:59 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-11-21 08:42:01 +1100 |
| commit | 525e1919f730e921f8cc6f917c064c7d083c7048 (patch) | |
| tree | df974eafcc85b5452d9237cc58b1111ae40f4c14 /compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | |
| parent | 91164957ec18aa65aa00412f703f2270e47779c1 (diff) | |
| download | rust-525e1919f730e921f8cc6f917c064c7d083c7048.tar.gz rust-525e1919f730e921f8cc6f917c064c7d083c7048.zip | |
Rewrite `show_md_content_with_pager`.
I think the control flow in this function is complicated and confusing, largely due to the use of two booleans `print_formatted` and `fallback_to_println` that are set in multiple places and then used to guide proceedings. As well as hurting readability, this leads to at least one bug: if the `write_termcolor_buf` call fails and the pager also fails, the function will try to print color output to stdout, but that output will be empty because `write_termcolor_buf` failed. I.e. the `if fallback_to_println` body fails to check `print_formatted`. This commit rewrites the function to be neater and more Rust-y, e.g. by putting the result of `write_termcolor_buf` into an `Option` so it can only be used on success, and by using `?` more. It also changes terminology a little, using "pretty" to mean "formatted and colorized". The result is a little shorter, more readable, and less buggy.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
