Skip to content

Commit 66becdc

Browse files
authored
Rollup merge of rust-lang#44329 - nrc:pulldown-warn-fix, r=ollie27
Fixup some nits from rust-lang#44238 r? @ollie27
2 parents cef0eaf + 0573949 commit 66becdc

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() {
@@ -3791,35 +3765,3 @@ fn test_name_sorting() {
37913765
sorted.sort_by_key(|&s| name_key(s));
37923766
assert_eq!(names, sorted);
37933767
}
3794-
3795-
#[cfg(test)]
3796-
#[test]
3797-
fn test_match_non_whitespace() {
3798-
assert!(match_non_whitespace("", ""));
3799-
assert!(match_non_whitespace(" ", ""));
3800-
assert!(match_non_whitespace("", " "));
3801-
3802-
assert!(match_non_whitespace("a", "a"));
3803-
assert!(match_non_whitespace(" a ", "a"));
3804-
assert!(match_non_whitespace("a", " a"));
3805-
assert!(match_non_whitespace("abc", "abc"));
3806-
assert!(match_non_whitespace("abc", " abc "));
3807-
assert!(match_non_whitespace("abc ", "abc"));
3808-
assert!(match_non_whitespace("abc xyz", "abc xyz"));
3809-
assert!(match_non_whitespace("abc xyz", "abc\nxyz"));
3810-
assert!(match_non_whitespace("abc xyz", "abcxyz"));
3811-
assert!(match_non_whitespace("abcxyz", "abc xyz"));
3812-
assert!(match_non_whitespace("abc xyz ", " abc xyz\n"));
3813-
3814-
assert!(!match_non_whitespace("a", "b"));
3815-
assert!(!match_non_whitespace(" a ", "c"));
3816-
assert!(!match_non_whitespace("a", " aa"));
3817-
assert!(!match_non_whitespace("abc", "ac"));
3818-
assert!(!match_non_whitespace("abc", " adc "));
3819-
assert!(!match_non_whitespace("abc ", "abca"));
3820-
assert!(!match_non_whitespace("abc xyz", "abc xy"));
3821-
assert!(!match_non_whitespace("abc xyz", "bc\nxyz"));
3822-
assert!(!match_non_whitespace("abc xyz", "abc.xyz"));
3823-
assert!(!match_non_whitespace("abcxyz", "abc.xyz"));
3824-
assert!(!match_non_whitespace("abc xyz ", " abc xyz w"));
3825-
}

0 commit comments

Comments
 (0)