11925: internal: Add and use `HirFormatter::write_{str,char}` r=Veykril a=lnicola

Saves slightly over 3 KB of `text`, but comparing the total with that from two weeks ago in #11776, this is a losing battle (we're 951 KB larger).

```
   text	   data	    bss	    dec	    hex	filename
24693512	1542704	   4424	26240640	1906680	rust-analyzer-baseline
24690216	1542112	   4424	26236752	1905750	rust-analyzer-pr
```


Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
bors[bot] 2022-04-07 14:38:46 +00:00 committed by GitHub
commit 12f803d1e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 55 deletions

View file

@ -172,6 +172,16 @@ impl<'a> HirFormatter<'a> {
self.fmt.write_str(&self.buf).map_err(HirDisplayError::from)
}
pub fn write_str(&mut self, s: &str) -> Result<(), HirDisplayError> {
self.fmt.write_str(s)?;
Ok(())
}
pub fn write_char(&mut self, c: char) -> Result<(), HirDisplayError> {
self.fmt.write_char(c)?;
Ok(())
}
pub fn should_truncate(&self) -> bool {
match self.max_size {
Some(max_size) => self.curr_size >= max_size,