Skip to content

Commit 69d86c9

Browse files
committed
Clean up serialization code nits
1 parent 86b9550 commit 69d86c9

File tree

1 file changed

+8
-10
lines changed
  • src/librustdoc/html/render

1 file changed

+8
-10
lines changed

src/librustdoc/html/render/mod.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,16 @@ pub(crate) struct RenderType {
132132

133133
impl RenderType {
134134
pub fn write_to_string(&self, string: &mut String) {
135-
if self.generics.is_some() || self.bindings.is_some() {
136-
string.push('{');
135+
fn write_optional_id(id: Option<RenderTypeId>, string: &mut String) {
137136
// 0 is a sentinel, everything else is one-indexed
138-
match self.id {
137+
match id {
139138
Some(id) => id.write_to_string(string),
140139
None => string.push('`'),
141140
}
141+
}
142+
if self.generics.is_some() || self.bindings.is_some() {
143+
string.push('{');
144+
write_optional_id(self.id, &mut string);
142145
string.push('{');
143146
for generic in &self.generics.as_ref().map(Vec::as_slice).unwrap_or_default()[..] {
144147
generic.write_to_string(string);
@@ -153,18 +156,13 @@ impl RenderType {
153156
for constraint in &binding.1[..] {
154157
constraint.write_to_string(string);
155158
}
156-
string.push('}');
157-
string.push('}');
159+
string.push_str("}}");
158160
}
159161
string.push('}');
160162
}
161163
string.push('}');
162164
} else {
163-
// 0 is a sentinel, everything else is one-indexed
164-
match self.id {
165-
Some(id) => id.write_to_string(string),
166-
None => string.push('`'),
167-
}
165+
write_optional_id(self.id, &mut string);
168166
}
169167
}
170168
}

0 commit comments

Comments
 (0)