Skip to content

Commit 095f5e7

Browse files
committed
Auto merge of #31902 - mitaa:rdoc-shorter, r=alexcrichton
fixes #31899 r? @alexcrichton
2 parents 54fdae3 + 0b3bc9b commit 095f5e7

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

src/librustdoc/html/markdown.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
250250
let text = lines.collect::<Vec<&str>>().join("\n");
251251
if rendered { return }
252252
PLAYGROUND_KRATE.with(|krate| {
253-
let mut s = String::new();
253+
// insert newline to clearly separate it from the
254+
// previous block so we can shorten the html output
255+
let mut s = String::from("\n");
254256
krate.borrow().as_ref().map(|krate| {
255257
let test = origtext.lines().map(|l| {
256258
stripped_filtered_line(l).unwrap_or(l)

src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1657,8 +1657,8 @@ fn shorter<'a>(s: Option<&'a str>) -> String {
16571657

16581658
#[inline]
16591659
fn plain_summary_line(s: Option<&str>) -> String {
1660-
let md = markdown::plain_summary_line(s.unwrap_or(""));
1661-
shorter(Some(&md)).replace("\n", " ")
1660+
let line = shorter(s).replace("\n", " ");
1661+
markdown::plain_summary_line(&line[..])
16621662
}
16631663

16641664
fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {

src/test/rustdoc/issue-31899.rs

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2016 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+
12+
// @has issue_31899/index.html
13+
// @has - 'Make this line a bit longer.'
14+
// @!has - 'rust rust-example-rendered'
15+
// @!has - 'use ndarray::arr2'
16+
// @!has - 'prohibited'
17+
18+
/// A tuple or fixed size array that can be used to index an array.
19+
/// Make this line a bit longer.
20+
///
21+
/// ```
22+
/// use ndarray::arr2;
23+
///
24+
/// let mut a = arr2(&[[0, 1], [0, 0]]);
25+
/// a[[1, 1]] = 1;
26+
/// assert_eq!(a[[0, 1]], 1);
27+
/// assert_eq!(a[[1, 1]], 1);
28+
/// ```
29+
///
30+
/// **Note** the blanket implementation that's not visible in rustdoc:
31+
/// `impl<D> NdIndex for D where D: Dimension { ... }`
32+
pub fn bar() {}
33+
34+
/// Some line
35+
///
36+
/// # prohibited
37+
pub fn foo() {}
38+
39+
/// Some line
40+
///
41+
/// 1. prohibited
42+
/// 2. bar
43+
pub fn baz() {}
44+
45+
/// Some line
46+
///
47+
/// - prohibited
48+
/// - bar
49+
pub fn qux() {}
50+
51+
/// Some line
52+
///
53+
/// * prohibited
54+
/// * bar
55+
pub fn quz() {}
56+
57+
/// Some line
58+
///
59+
/// > prohibited
60+
/// > bar
61+
pub fn qur() {}
62+
63+
/// Some line
64+
///
65+
/// prohibited
66+
/// =====
67+
///
68+
/// Second
69+
/// ------
70+
pub fn qut() {}

0 commit comments

Comments
 (0)