Skip to content

Commit c118d37

Browse files
Rollup merge of rust-lang#48382 - GuillaumeGomez:fix-rustdoc-test-panic, r=estebank
Fix rustdoc test ICE Fixes rust-lang#48377. r? @QuietMisdreavus
2 parents d9f5eeb + 5cbf9ae commit c118d37

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/librustdoc/html/markdown.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -471,18 +471,21 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
471471
break 'main;
472472
}
473473
}
474-
let offset = offset.unwrap_or(0);
475-
let lines = test_s.lines().map(|l| map_line(l).for_code());
476-
let text = lines.collect::<Vec<&str>>().join("\n");
477-
nb_lines += doc[prev_offset..offset].lines().count();
478-
let line = tests.get_line() + (nb_lines - 1);
479-
let filename = tests.get_filename();
480-
tests.add_test(text.to_owned(),
481-
block_info.should_panic, block_info.no_run,
482-
block_info.ignore, block_info.test_harness,
483-
block_info.compile_fail, block_info.error_codes,
484-
line, filename, block_info.allow_fail);
485-
prev_offset = offset;
474+
if let Some(offset) = offset {
475+
let lines = test_s.lines().map(|l| map_line(l).for_code());
476+
let text = lines.collect::<Vec<&str>>().join("\n");
477+
nb_lines += doc[prev_offset..offset].lines().count();
478+
let line = tests.get_line() + (nb_lines - 1);
479+
let filename = tests.get_filename();
480+
tests.add_test(text.to_owned(),
481+
block_info.should_panic, block_info.no_run,
482+
block_info.ignore, block_info.test_harness,
483+
block_info.compile_fail, block_info.error_codes,
484+
line, filename, block_info.allow_fail);
485+
prev_offset = offset;
486+
} else {
487+
break;
488+
}
486489
}
487490
Event::Start(Tag::Header(level)) => {
488491
register_header = Some(level as u32);

src/test/rustdoc/issue-48377.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
// compile-flags:--test
12+
13+
//! This is a doc comment
14+
//!
15+
//! ```rust
16+
//! fn main() {}
17+
//! ```
18+
//!
19+
//! With a trailing code fence
20+
//! ```
21+
22+
/// Some foo function
23+
pub fn foo() {}

0 commit comments

Comments
 (0)