Skip to content

Commit 0573949

Browse files
committed
Fixup some nits from #44238
1 parent 088216f commit 0573949

File tree

1 file changed

+22
-80
lines changed

1 file changed

+22
-80
lines changed

src/librustdoc/html/render.rs

+22-80
Original file line numberDiff line numberDiff line change
@@ -606,12 +606,20 @@ pub fn run(mut krate: clean::Crate,
606606
}
607607

608608
// A short, single-line view of `s`.
609-
fn concise_str(s: &str) -> String {
609+
fn concise_str(mut s: &str) -> String {
610610
if s.contains('\n') {
611-
return format!("{}...", s.lines().next().expect("Impossible! We just found a newline"));
611+
s = s.lines().next().expect("Impossible! We just found a newline");
612612
}
613613
if s.len() > 70 {
614-
return format!("{} ... {}", &s[..50], &s[s.len()-20..]);
614+
let mut lo = 50;
615+
let mut hi = s.len() - 20;
616+
while !s.is_char_boundary(lo) {
617+
lo -= 1;
618+
}
619+
while !s.is_char_boundary(hi) {
620+
hi += 1;
621+
}
622+
return format!("{} ... {}", &s[..lo], &s[hi..]);
615623
}
616624
s.to_owned()
617625
}
@@ -1756,18 +1764,18 @@ fn render_markdown(w: &mut fmt::Formatter,
17561764
// We only emit warnings if the user has opted-in to Pulldown rendering.
17571765
let output = if render_type == RenderType::Pulldown {
17581766
let pulldown_output = format!("{}", Markdown(md_text, RenderType::Pulldown));
1759-
let differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
1760-
let differences = differences.into_iter()
1761-
.filter(|s| {
1762-
match *s {
1763-
html_diff::Difference::NodeText { ref elem_text,
1764-
ref opposite_elem_text,
1765-
.. }
1766-
if match_non_whitespace(elem_text, opposite_elem_text) => false,
1767-
_ => true,
1767+
let mut differences = html_diff::get_differences(&pulldown_output, &hoedown_output);
1768+
differences.retain(|s| {
1769+
match *s {
1770+
html_diff::Difference::NodeText { ref elem_text,
1771+
ref opposite_elem_text,
1772+
.. }
1773+
if elem_text.split_whitespace().eq(opposite_elem_text.split_whitespace()) => {
1774+
false
17681775
}
1769-
})
1770-
.collect::<Vec<_>>();
1776+
_ => true,
1777+
}
1778+
});
17711779

17721780
if !differences.is_empty() {
17731781
scx.markdown_warnings.borrow_mut().push((span, md_text.to_owned(), differences));
@@ -1781,40 +1789,6 @@ fn render_markdown(w: &mut fmt::Formatter,
17811789
write!(w, "<div class='docblock'>{}{}</div>", prefix, output)
17821790
}
17831791

1784-
// Returns true iff s1 and s2 match, ignoring whitespace.
1785-
fn match_non_whitespace(s1: &str, s2: &str) -> bool {
1786-
let s1 = s1.trim();
1787-
let s2 = s2.trim();
1788-
let mut cs1 = s1.chars();
1789-
let mut cs2 = s2.chars();
1790-
while let Some(c1) = cs1.next() {
1791-
if c1.is_whitespace() {
1792-
continue;
1793-
}
1794-
1795-
loop {
1796-
if let Some(c2) = cs2.next() {
1797-
if !c2.is_whitespace() {
1798-
if c1 != c2 {
1799-
return false;
1800-
}
1801-
break;
1802-
}
1803-
} else {
1804-
return false;
1805-
}
1806-
}
1807-
}
1808-
1809-
while let Some(c2) = cs2.next() {
1810-
if !c2.is_whitespace() {
1811-
return false;
1812-
}
1813-
}
1814-
1815-
true
1816-
}
1817-
18181792
fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLink,
18191793
cx: &Context, prefix: &str) -> fmt::Result {
18201794
if let Some(s) = item.doc_value() {
@@ -3729,35 +3703,3 @@ fn test_name_sorting() {
37293703
sorted.sort_by_key(|&s| name_key(s));
37303704
assert_eq!(names, sorted);
37313705
}
3732-
3733-
#[cfg(test)]
3734-
#[test]
3735-
fn test_match_non_whitespace() {
3736-
assert!(match_non_whitespace("", ""));
3737-
assert!(match_non_whitespace(" ", ""));
3738-
assert!(match_non_whitespace("", " "));
3739-
3740-
assert!(match_non_whitespace("a", "a"));
3741-
assert!(match_non_whitespace(" a ", "a"));
3742-
assert!(match_non_whitespace("a", " a"));
3743-
assert!(match_non_whitespace("abc", "abc"));
3744-
assert!(match_non_whitespace("abc", " abc "));
3745-
assert!(match_non_whitespace("abc ", "abc"));
3746-
assert!(match_non_whitespace("abc xyz", "abc xyz"));
3747-
assert!(match_non_whitespace("abc xyz", "abc\nxyz"));
3748-
assert!(match_non_whitespace("abc xyz", "abcxyz"));
3749-
assert!(match_non_whitespace("abcxyz", "abc xyz"));
3750-
assert!(match_non_whitespace("abc xyz ", " abc xyz\n"));
3751-
3752-
assert!(!match_non_whitespace("a", "b"));
3753-
assert!(!match_non_whitespace(" a ", "c"));
3754-
assert!(!match_non_whitespace("a", " aa"));
3755-
assert!(!match_non_whitespace("abc", "ac"));
3756-
assert!(!match_non_whitespace("abc", " adc "));
3757-
assert!(!match_non_whitespace("abc ", "abca"));
3758-
assert!(!match_non_whitespace("abc xyz", "abc xy"));
3759-
assert!(!match_non_whitespace("abc xyz", "bc\nxyz"));
3760-
assert!(!match_non_whitespace("abc xyz", "abc.xyz"));
3761-
assert!(!match_non_whitespace("abcxyz", "abc.xyz"));
3762-
assert!(!match_non_whitespace("abc xyz ", " abc xyz w"));
3763-
}

0 commit comments

Comments
 (0)