Skip to content

Commit ed61aaa

Browse files
committed
Auto merge of #48454 - frewsxcv:frewsxcv-backport, r=QuietMisdreavus
[beta] Backport "Fix rustdoc test ICE" #48382
2 parents e48c8cf + fe4ef51 commit ed61aaa

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
@@ -1027,18 +1027,21 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector, position: Sp
10271027
break 'main;
10281028
}
10291029
}
1030-
let offset = offset.unwrap_or(0);
1031-
let lines = test_s.lines().map(|l| map_line(l).for_code());
1032-
let text = lines.collect::<Vec<&str>>().join("\n");
1033-
nb_lines += doc[prev_offset..offset].lines().count();
1034-
let line = tests.get_line() + (nb_lines - 1);
1035-
let filename = tests.get_filename();
1036-
tests.add_test(text.to_owned(),
1037-
block_info.should_panic, block_info.no_run,
1038-
block_info.ignore, block_info.test_harness,
1039-
block_info.compile_fail, block_info.error_codes,
1040-
line, filename, block_info.allow_fail);
1041-
prev_offset = offset;
1030+
if let Some(offset) = offset {
1031+
let lines = test_s.lines().map(|l| map_line(l).for_code());
1032+
let text = lines.collect::<Vec<&str>>().join("\n");
1033+
nb_lines += doc[prev_offset..offset].lines().count();
1034+
let line = tests.get_line() + (nb_lines - 1);
1035+
let filename = tests.get_filename();
1036+
tests.add_test(text.to_owned(),
1037+
block_info.should_panic, block_info.no_run,
1038+
block_info.ignore, block_info.test_harness,
1039+
block_info.compile_fail, block_info.error_codes,
1040+
line, filename, block_info.allow_fail);
1041+
prev_offset = offset;
1042+
} else {
1043+
break;
1044+
}
10421045
}
10431046
Event::Start(Tag::Header(level)) => {
10441047
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)