Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Jan 29, 2021
1 parent d5cac19 commit c9c1200
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/librustdoc/html/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ impl<'a> fmt::Display for Escape<'a> {
let Escape(s) = *self;
let pile_o_bits = s;
let mut last = 0;
for (i, ch) in s.bytes().enumerate() {
let s = match ch as char {
for (i, ch) in s.char_indices() {
let s = match ch {
'>' => "&gt;",
'<' => "&lt;",
'&' => "&amp;",
Expand All @@ -27,6 +27,8 @@ impl<'a> fmt::Display for Escape<'a> {
};
fmt.write_str(&pile_o_bits[last..i])?;
fmt.write_str(s)?;
// NOTE: we only expect single byte characters here - which is fine as long as we
// only match single byte characters
last = i + 1;
}

Expand Down
15 changes: 8 additions & 7 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ crate struct StylePath {

thread_local!(crate static CURRENT_DEPTH: Cell<usize> = Cell::new(0));

// FIXME: make this work
crate const INITIAL_IDS: [&'static str; 15] = [
"main",
"search",
Expand Down Expand Up @@ -4101,7 +4100,7 @@ fn item_typedef(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::T
}

fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) {
w.write_str("<pre class=\"rust foreigntype\">extern {");
w.write_str("<pre class=\"rust foreigntype\">extern {\n");
render_attributes(w, it, false);
write!(
w,
Expand Down Expand Up @@ -4264,8 +4263,8 @@ fn get_methods(
fn small_url_encode(s: String) -> String {
let mut st = String::new();
let mut last_match = 0;
for (idx, c) in s.bytes().enumerate() {
let escaped = match c as char {
for (idx, c) in s.char_indices() {
let escaped = match c {
'<' => "%3C",
'>' => "%3E",
' ' => "%20",
Expand All @@ -4283,6 +4282,8 @@ fn small_url_encode(s: String) -> String {

st += &s[last_match..idx];
st += escaped;
// NOTE: we only expect single byte characters here - which is fine as long as we
// only match single byte characters
last_match = idx + 1;
}

Expand Down Expand Up @@ -4834,12 +4835,12 @@ fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean
w.push_str("<pre class=\"rust derive\">");
write!(w, "#[derive({})]", name);
if !m.helpers.is_empty() {
w.push_str("\n{");
w.push_str(" // Attributes available to this derive:");
w.push_str("\n{\n");
w.push_str(" // Attributes available to this derive:\n");
for attr in &m.helpers {
writeln!(w, " #[{}]", attr);
}
w.push_str("}");
w.push_str("}\n");
}
w.push_str("</pre>");
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustdoc/html/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ impl SourceCollector<'_, '_> {
};

// Remove the utf-8 BOM if any
let contents =
if contents.starts_with('\u{feff}') { &contents[3..] } else { &contents[..] };
let contents = if contents.starts_with('\u{feff}') { &contents[3..] } else { &contents };

// Create the intermediate directories
let mut cur = self.dst.clone();
Expand Down

0 comments on commit c9c1200

Please sign in to comment.