diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-08 06:47:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-08 06:47:33 +0100 |
| commit | 338979232af8c75fa05d88eeed17292cffc09967 (patch) | |
| tree | 6cdab8d410ac7763ef494150dbdb7d80eb84fcac | |
| parent | 267776aa2ca2f77f454d14887e2c4eea772de6a9 (diff) | |
| parent | 1ab23bda9c44989a7d5b4bab557eb2dab18eb509 (diff) | |
Rollup merge of #93568 - willcrichton:scrape-examples-leading-whitespace, r=CraftSpider
Include all contents of first line of scraped item in Rustdoc This fixes #93528. When scraping examples, it extends the span of the enclosing item to include all characters up to the start of the first line of the span. r? `@camelid`
4 files changed, 20 insertions, 1 deletions
diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index 93292efdcb6..16882cf83d0 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -196,7 +196,8 @@ where return; } - let file = tcx.sess.source_map().lookup_char_pos(span.lo()).file; + let source_map = tcx.sess.source_map(); + let file = source_map.lookup_char_pos(span.lo()).file; let file_path = match file.name.clone() { FileName::Real(real_filename) => real_filename.into_local_path(), _ => None, @@ -217,6 +218,8 @@ where let fn_entries = self.calls.entry(fn_key).or_default(); trace!("Including expr: {:?}", span); + let enclosing_item_span = + source_map.span_extend_to_prev_char(enclosing_item_span, '\n', false); let location = CallLocation::new(span, enclosing_item_span, &file); fn_entries.entry(abs_path).or_insert_with(mk_call_data).locations.push(location); } diff --git a/src/test/run-make/rustdoc-scrape-examples-whitespace/Makefile b/src/test/run-make/rustdoc-scrape-examples-whitespace/Makefile new file mode 100644 index 00000000000..dce8b83eefe --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-whitespace/Makefile @@ -0,0 +1,5 @@ +deps := ex + +-include ../rustdoc-scrape-examples-multiple/scrape.mk + +all: scrape diff --git a/src/test/run-make/rustdoc-scrape-examples-whitespace/examples/ex.rs b/src/test/run-make/rustdoc-scrape-examples-whitespace/examples/ex.rs new file mode 100644 index 00000000000..44ff689dfc8 --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-whitespace/examples/ex.rs @@ -0,0 +1,8 @@ +struct Foo; +impl Foo { + fn bar() { foobar::ok(); } +} + +fn main() { + Foo::bar(); +} diff --git a/src/test/run-make/rustdoc-scrape-examples-whitespace/src/lib.rs b/src/test/run-make/rustdoc-scrape-examples-whitespace/src/lib.rs new file mode 100644 index 00000000000..28c34716c2f --- /dev/null +++ b/src/test/run-make/rustdoc-scrape-examples-whitespace/src/lib.rs @@ -0,0 +1,3 @@ +// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]//code' ' ' + +pub fn ok() {} |
