Skip to content

Commit

Permalink
Clean up serialization code nits
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Jan 4, 2024
1 parent 86b9550 commit 69d86c9
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,16 @@ pub(crate) struct RenderType {

impl RenderType {
pub fn write_to_string(&self, string: &mut String) {
if self.generics.is_some() || self.bindings.is_some() {
string.push('{');
fn write_optional_id(id: Option<RenderTypeId>, string: &mut String) {
// 0 is a sentinel, everything else is one-indexed
match self.id {
match id {
Some(id) => id.write_to_string(string),
None => string.push('`'),
}
}
if self.generics.is_some() || self.bindings.is_some() {
string.push('{');
write_optional_id(self.id, &mut string);
string.push('{');
for generic in &self.generics.as_ref().map(Vec::as_slice).unwrap_or_default()[..] {
generic.write_to_string(string);
Expand All @@ -153,18 +156,13 @@ impl RenderType {
for constraint in &binding.1[..] {
constraint.write_to_string(string);
}
string.push('}');
string.push('}');
string.push_str("}}");
}
string.push('}');
}
string.push('}');
} else {
// 0 is a sentinel, everything else is one-indexed
match self.id {
Some(id) => id.write_to_string(string),
None => string.push('`'),
}
write_optional_id(self.id, &mut string);
}
}
}
Expand Down

0 comments on commit 69d86c9

Please sign in to comment.