Skip to content

Commit 3030cbe

Browse files
Remove short doc where it starts with a codeblock
1 parent 653da4f commit 3030cbe

File tree

4 files changed

+78
-35
lines changed

4 files changed

+78
-35
lines changed

src/librustdoc/html/markdown.rs

+28-22
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ impl<'a, I: Iterator<Item = Event<'a>>> SummaryLine<'a, I> {
399399
fn check_if_allowed_tag(t: &Tag) -> bool {
400400
match *t {
401401
Tag::Paragraph
402-
| Tag::CodeBlock(_)
403402
| Tag::Item
404403
| Tag::Emphasis
405404
| Tag::Strong
@@ -420,29 +419,36 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
420419
if !self.started {
421420
self.started = true;
422421
}
423-
let event = self.inner.next();
424-
let mut is_start = true;
425-
let is_allowed_tag = match event {
426-
Some(Event::Start(ref c)) => {
427-
self.depth += 1;
428-
check_if_allowed_tag(c)
429-
}
430-
Some(Event::End(ref c)) => {
431-
self.depth -= 1;
432-
is_start = false;
433-
check_if_allowed_tag(c)
434-
}
435-
_ => true,
436-
};
437-
if is_allowed_tag == false {
438-
if is_start {
439-
Some(Event::Start(Tag::Paragraph))
422+
while let Some(event) = self.inner.next() {
423+
let mut is_start = true;
424+
let is_allowed_tag = match event {
425+
Event::Start(Tag::CodeBlock(_)) | Event::End(Tag::CodeBlock(_)) => {
426+
return None;
427+
}
428+
Event::Start(ref c) => {
429+
self.depth += 1;
430+
check_if_allowed_tag(c)
431+
}
432+
Event::End(ref c) => {
433+
self.depth -= 1;
434+
is_start = false;
435+
check_if_allowed_tag(c)
436+
}
437+
_ => {
438+
true
439+
}
440+
};
441+
return if is_allowed_tag == false {
442+
if is_start {
443+
Some(Event::Start(Tag::Paragraph))
444+
} else {
445+
Some(Event::End(Tag::Paragraph))
446+
}
440447
} else {
441-
Some(Event::End(Tag::Paragraph))
442-
}
443-
} else {
444-
event
448+
Some(event)
449+
};
445450
}
451+
None
446452
}
447453
}
448454

src/librustdoc/html/render.rs

+25-10
Original file line numberDiff line numberDiff line change
@@ -2584,24 +2584,39 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
25842584
_ => "",
25852585
};
25862586

2587+
let stab = myitem.stability_class();
2588+
let add = if stab.is_some() {
2589+
" "
2590+
} else {
2591+
""
2592+
};
2593+
25872594
let doc_value = myitem.doc_value().unwrap_or("");
2588-
write!(w, "
2589-
<tr class='{stab} module-item'>
2590-
<td><a class=\"{class}\" href=\"{href}\"
2591-
title='{title_type} {title}'>{name}</a>{unsafety_flag}</td>
2592-
<td class='docblock-short'>
2593-
{stab_docs} {docs}
2594-
</td>
2595+
write!(w, "\
2596+
<tr class='{stab}{add}module-item'>\
2597+
<td><a class=\"{class}\" href=\"{href}\" \
2598+
title='{title}'>{name}</a>{unsafety_flag}</td>\
2599+
<td class='docblock-short'>{stab_docs}{docs}\
2600+
</td>\
25952601
</tr>",
25962602
name = *myitem.name.as_ref().unwrap(),
25972603
stab_docs = stab_docs,
25982604
docs = MarkdownSummaryLine(doc_value, &myitem.links()),
25992605
class = myitem.type_(),
2600-
stab = myitem.stability_class().unwrap_or(String::new()),
2606+
add = add,
2607+
stab = stab.unwrap_or_else(|| String::new()),
26012608
unsafety_flag = unsafety_flag,
26022609
href = item_path(myitem.type_(), myitem.name.as_ref().unwrap()),
2603-
title_type = myitem.type_(),
2604-
title = full_path(cx, myitem))?;
2610+
title = [full_path(cx, myitem), myitem.type_().to_string()]
2611+
.iter()
2612+
.filter_map(|s| if !s.is_empty() {
2613+
Some(s.as_str())
2614+
} else {
2615+
None
2616+
})
2617+
.collect::<Vec<_>>()
2618+
.join(" "),
2619+
)?;
26052620
}
26062621
}
26072622
}

src/test/rustdoc/doc-cfg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub struct Portable;
2020
// @has doc_cfg/unix_only/index.html \
2121
// '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
2222
// 'This is supported on Unix only.'
23-
// @matches - '//*[@class=" module-item"]//*[@class="stab portability"]' '\AUnix\Z'
24-
// @matches - '//*[@class=" module-item"]//*[@class="stab portability"]' '\AUnix and ARM\Z'
23+
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AUnix\Z'
24+
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\AUnix and ARM\Z'
2525
// @count - '//*[@class="stab portability"]' 3
2626
#[doc(cfg(unix))]
2727
pub mod unix_only {
@@ -52,7 +52,7 @@ pub mod unix_only {
5252

5353
// the portability header is different on the module view versus the full view
5454
// @has doc_cfg/index.html
55-
// @matches - '//*[@class=" module-item"]//*[@class="stab portability"]' '\Aavx\Z'
55+
// @matches - '//*[@class="module-item"]//*[@class="stab portability"]' '\Aavx\Z'
5656

5757
// @has doc_cfg/fn.uses_target_feature.html
5858
// @has - '//*[@id="main"]/*[@class="stability"]/*[@class="stab portability"]' \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
// @has foo/index.html '//*[@class="module-item"]//td[@class="docblock-short"]' ""
14+
// @!has foo/index.html '//*[@id="module-item"]//td[@class="docblock-short"]' "Some text."
15+
// @!has foo/index.html '//*[@id="module-item"]//td[@class="docblock-short"]' "let x = 12;"
16+
17+
/// ```
18+
/// let x = 12;
19+
/// ```
20+
///
21+
/// Some text.
22+
pub fn foo() {}

0 commit comments

Comments
 (0)