From 9c978820550994809940fa91436b6fbab9e6db49 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 22 Apr 2017 14:56:36 +0200 Subject: [PATCH] Fix line display --- src/librustdoc/html/markdown.rs | 12 ++++-------- src/librustdoc/test.rs | 8 ++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 0dc7ae2873b71..85a28bbfbc6d0 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -719,7 +719,7 @@ pub fn old_find_testable_code(doc: &str, tests: &mut ::test::Collector, position text: *const hoedown_buffer, lang: *const hoedown_buffer, data: *const hoedown_renderer_data, - _line: libc::size_t) { + line: libc::size_t) { unsafe { if text.is_null() { return } let block_info = if lang.is_null() { @@ -737,22 +737,18 @@ pub fn old_find_testable_code(doc: &str, tests: &mut ::test::Collector, position let lines = text.lines().map(|l| { stripped_filtered_line(l).unwrap_or(l) }); + let text = lines.collect::>().join("\n"); let filename = tests.get_filename(); if tests.render_type == RenderType::Hoedown { - let text = (*text).as_bytes(); - let text = str::from_utf8(text).unwrap(); - let lines = text.lines().map(|l| { - stripped_filtered_line(l).unwrap_or(l) - }); - let text = lines.collect::>().join("\n"); + let line = tests.get_line() + line; tests.add_test(text.to_owned(), block_info.should_panic, block_info.no_run, block_info.ignore, block_info.test_harness, block_info.compile_fail, block_info.error_codes, line, filename); } else { - tests.add_old_test(lines.collect::>().join("\n"), filename); + tests.add_old_test(text, filename); } } } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index a30ec25de60d7..5b9ab304db0a9 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -464,19 +464,19 @@ impl Collector { as_test_harness: bool, compile_fail: bool, error_codes: Vec, line: usize, filename: String) { let name = self.generate_name(line, &filename); + // to be removed when hoedown is removed if self.render_type == RenderType::Pulldown { let name_beg = self.generate_name_beginning(&filename); let mut found = false; - // to be removed when hoedown is removed let test = test.trim().to_owned(); if let Some(entry) = self.old_tests.get_mut(&name_beg) { found = entry.remove_item(&test).is_some(); } if !found { let _ = writeln!(&mut io::stderr(), - "WARNING: {} Code block is not currently run as a test, but will in \ - future versions of rustdoc. Please ensure this code block is a \ - runnable test, or use the `ignore` directive.", + "WARNING: {} Code block is not currently run as a test, but will \ + in future versions of rustdoc. Please ensure this code block is \ + a runnable test, or use the `ignore` directive.", name); return }