diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2024-05-31 16:56:04 -0700 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-06-07 17:48:47 +0200 |
| commit | 790b7e9cbfb6aa591520856b018402d62eceb690 (patch) | |
| tree | 94b4e3e2e3c3cdeef7ef26ca64d9a2caa87a0790 /src/librustdoc/html | |
| parent | 46d2aa5a8f8d09d4789d2af01a6acdb3ba9e41a4 (diff) | |
rustdoc: Remove `DoctestVisitor::get_line`
This was used to get the line number of the first line from the current docstring, which was then used together with an offset within the docstring. It's simpler to just pass the offset to the visitor and have it do the math because it's clearer and this calculation only needs to be done in one place (the Rust doctest visitor).
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index c8973679132..17aa0ecf23d 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -710,6 +710,28 @@ impl<'a, I: Iterator<Item = SpannedEvent<'a>>> Iterator for Footnotes<'a, I> { } } +/// A newtype that represents a relative line number in Markdown. +/// +/// In other words, this represents an offset from the first line of Markdown +/// in a doc comment or other source. If the first Markdown line appears on line 32, +/// and the `MdRelLine` is 3, then the absolute line for this one is 35. I.e., it's +/// a zero-based offset. +pub(crate) struct MdRelLine { + offset: usize, +} + +impl MdRelLine { + /// See struct docs. + pub(crate) const fn new(offset: usize) -> Self { + Self { offset } + } + + /// See struct docs. + pub(crate) const fn offset(self) -> usize { + self.offset + } +} + pub(crate) fn find_testable_code<T: doctest::DoctestVisitor>( doc: &str, tests: &mut T, @@ -772,7 +794,7 @@ pub(crate) fn find_codes<T: doctest::DoctestVisitor>( if nb_lines != 0 && !&doc[prev_offset..offset.start].ends_with('\n') { nb_lines -= 1; } - let line = tests.get_line() + nb_lines + 1; + let line = MdRelLine::new(nb_lines); tests.visit_test(text, block_info, line); prev_offset = offset.start; } |
