Rollup merge of #85833 - willcrichton:example-analyzer, r=jyn514

Scrape code examples from examples/ directory for Rustdoc

Adds support for the functionality described in https://github.com/rust-lang/rfcs/pull/3123

Matching changes to Cargo are here: https://github.com/rust-lang/cargo/pull/9525

Live demo here: https://willcrichton.net/example-analyzer/warp/trait.Filter.html#method.and
This commit is contained in:
Matthias Krüger 2021-10-23 14:58:39 +02:00 committed by GitHub
commit dcf9242795
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 1104 additions and 30 deletions

View file

@ -0,0 +1,5 @@
deps := ex ex2
-include ./scrape.mk
all: scrape

View file

@ -0,0 +1,4 @@
fn main() {
foobar::ok();
foobar::ok();
}

View file

@ -0,0 +1,3 @@
fn main() {
foobar::ok();
}

View file

@ -0,0 +1,20 @@
-include ../../run-make-fulldeps/tools.mk
OUTPUT_DIR := "$(TMPDIR)/rustdoc"
$(TMPDIR)/%.calls: $(TMPDIR)/libfoobar.rmeta
$(RUSTDOC) examples/$*.rs --crate-name $* --crate-type bin --output $(OUTPUT_DIR) \
--extern foobar=$(TMPDIR)/libfoobar.rmeta \
-Z unstable-options \
--scrape-examples-output-path $@ \
--scrape-examples-target-crate foobar
$(TMPDIR)/lib%.rmeta: src/lib.rs
$(RUSTC) src/lib.rs --crate-name $* --crate-type lib --emit=metadata
scrape: $(foreach d,$(deps),$(TMPDIR)/$(d).calls)
$(RUSTDOC) src/lib.rs --crate-name foobar --crate-type lib --output $(OUTPUT_DIR) \
-Z unstable-options \
$(foreach d,$(deps),--with-examples $(TMPDIR)/$(d).calls)
$(HTMLDOCCK) $(OUTPUT_DIR) src/lib.rs

View file

@ -0,0 +1,4 @@
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]//*[@class="prev"]' ''
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' ''
pub fn ok() {}

View file

@ -0,0 +1,5 @@
deps := ex1 ex2
-include ../rustdoc-scrape-examples-multiple/scrape.mk
all: scrape

View file

@ -0,0 +1,9 @@
fn main() {
foobar::ok();
// this is a
// BIG
// item
}

View file

@ -0,0 +1,4 @@
fn main() {
foobar::ok();
// small item
}

View file

@ -0,0 +1,4 @@
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]' 'ex2'
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' 'ex1'
pub fn ok() {}

View file

@ -0,0 +1,5 @@
deps := ex
-include ../rustdoc-scrape-examples-multiple/scrape.mk
all: scrape

View file

@ -0,0 +1,4 @@
fn main() {
foobar::b::foo();
foobar::c::foo();
}

View file

@ -0,0 +1 @@
pub fn foo() {}

View file

@ -0,0 +1,8 @@
// @has foobar/b/fn.foo.html '//*[@class="scraped-example expanded"]' 'ex.rs'
// @has foobar/c/fn.foo.html '//*[@class="scraped-example expanded"]' 'ex.rs'
#[path = "a.rs"]
pub mod b;
#[path = "a.rs"]
pub mod c;

View file

@ -0,0 +1 @@
// compile-flags: -Z unstable-options --scrape-examples-target-crate foobar

View file

@ -0,0 +1,2 @@
error: must use --scrape-examples-output-path and --scrape-examples-target-crate together

View file

@ -0,0 +1 @@
// compile-flags: -Z unstable-options --scrape-examples-output-path ex.calls

View file

@ -0,0 +1,2 @@
error: must use --scrape-examples-output-path and --scrape-examples-target-crate together