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 448b19b
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 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, 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, string);
}
}
}
Expand All @@ -191,6 +189,7 @@ impl RenderTypeId {
// zig-zag notation
let value: u32 = (id << 1) | (if sign { 1 } else { 0 });
// encode
// Documented in https://doc.rust-lang.org/nightly/rustc-dev-guide/rustdoc-internals/search.html
let mut shift: u32 = 28;
let mut mask: u32 = 0xF0_00_00_00;
while shift < 32 {
Expand Down

0 comments on commit 448b19b

Please sign in to comment.