Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ice with rustdoc scrape_examples #90567

Closed
mejrs opened this issue Nov 4, 2021 · 2 comments · Fixed by #90583
Closed

Ice with rustdoc scrape_examples #90567

mejrs opened this issue Nov 4, 2021 · 2 comments · Fixed by #90583
Labels
A-rustdoc-scrape-examples Area: The (unstable) rustdoc scrape-examples feature described in RFC 3123 C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@mejrs
Copy link
Contributor

mejrs commented Nov 4, 2021

When running

cargo +nightly doc -Z unstable-options -Z rustdoc-scrape-examples=examples

on the ice branch of https://github.com/mejrs/pyo3/tree/ice , I get the following error:

~/pyo3$ cargo +nightly doc -Z unstable-options -Z rustdoc-scrape-examples=examples
   Compiling pyo3 v0.14.5 (/home/bruno/pyo3)
thread 'rustc' panicked at 'assertion failed: enclosing_item_span.contains(expr_span)', src/librustdoc/scrape_examples.rs:93:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

error: Unrecognized option: 'scrape-examples-output-path'

error: could not document `pyo3`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2018 --crate-type bin --crate-name word_count examples/word-count/src/lib.rs -o /home/bruno/pyo3/target/doc --cfg 'feature="auto-initialize"' --cfg 'feature="default"' --cfg 'feature="extension-module"' --cfg 'feature="indoc"' --cfg 'feature="macros"' --cfg 'feature="paste"' --cfg 'feature="pyo3-macros"' --cfg 'feature="unindent"' --error-format=json --json=diagnostic-rendered-ansi -C metadata=4cd6a3c2c10c880b -Zunstable-options --scrape-examples-output-path /home/bruno/pyo3/target/debug/deps/pyo3-87828202807095e6.examples --scrape-examples-target-crate pyo3-macros --scrape-examples-target-crate pyo3-macros-backend --scrape-examples-target-crate pyo3-build-config --scrape-examples-target-crate pyo3-benchmarks --scrape-examples-target-crate pyo3 --scrape-examples-target-crate pyo3-pytests --scrape-examples-target-crate maturin-starter --scrape-examples-target-crate setuptools-rust-starter --scrape-examples-target-crate word-count -L dependency=/home/bruno/pyo3/target/debug/deps --extern assert_approx_eq=/home/bruno/pyo3/target/debug/deps/libassert_approx_eq-73f29b3f801eac6d.rmeta --extern bitflags=/home/bruno/pyo3/target/debug/deps/libbitflags-c30f35abb0b74f97.rmeta --extern cfg_if=/home/bruno/pyo3/target/debug/deps/libcfg_if-88879d2dc0fa106c.rmeta --extern criterion=/home/bruno/pyo3/target/debug/deps/libcriterion-a1abf6832c975b25.rmeta --extern half=/home/bruno/pyo3/target/debug/deps/libhalf-b6e268e7a94f2f0e.rmeta --extern indoc=/home/bruno/pyo3/target/debug/deps/libindoc-7a3b6554d729eba7.rmeta --extern libc=/home/bruno/pyo3/target/debug/deps/liblibc-56b7c085aca1bd82.rmeta --extern parking_lot=/home/bruno/pyo3/target/debug/deps/libparking_lot-28e0a32b822985ad.rmeta --extern paste=/home/bruno/pyo3/target/debug/deps/libpaste-50cadf247695eb32.rmeta --extern proptest=/home/bruno/pyo3/target/debug/deps/libproptest-011787d4a2170b22.rmeta --extern pyo3=/home/bruno/pyo3/target/debug/deps/libpyo3-fd794029b70a5af7.rmeta --extern pyo3=/home/bruno/pyo3/target/debug/deps/libpyo3-fd794029b70a5af7.rmeta --extern pyo3_macros=/home/bruno/pyo3/target/debug/deps/libpyo3_macros-74b16cc6327df15f.so --extern rayon=/home/bruno/pyo3/target/debug/deps/librayon-6402c0587be315bb.rmeta --extern rustversion=/home/bruno/pyo3/target/debug/deps/librustversion-69c11d077ef44fc2.so --extern serde_json=/home/bruno/pyo3/target/debug/deps/libserde_json-28ebb15e8db233fc.rmeta --extern trybuild=/home/bruno/pyo3/target/debug/deps/libtrybuild-5db6156090fb714a.rmeta --extern unindent=/home/bruno/pyo3/target/debug/deps/libunindent-a67f785cc7bb6fd1.rmeta --crate-version 0.14.5 --cfg Py_3_6 --cfg Py_3_7 --cfg Py_3_8 --cfg 'py_sys_config="WITH_THREAD"' --cfg track_caller --cfg min_const_generics --cfg addr_of` (exit status: 1)

(this is quite a big library and I couldn't figure out a minimal example in the time I had)

@mejrs mejrs added the C-bug Category: This is a bug. label Nov 4, 2021
@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Nov 4, 2021
@GuillaumeGomez
Copy link
Member

cc @willcrichton

@willcrichton
Copy link
Contributor

@mejrs can you do two things for me:

  1. Run $(rustup which --toolchain nightly rustdoc) -V and confirm your nightly is at least 2021-11-03
  2. rm -rf target and re-run the cargo doc command, see if it still fails

@camelid camelid added A-rustdoc-scrape-examples Area: The (unstable) rustdoc scrape-examples feature described in RFC 3123 requires-nightly This issue requires a nightly compiler in some way. labels Nov 4, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 4, 2021
…n514

Fix ICE when rustdoc is scraping examples inside of a proc macro

This PR provides a clearer semantics for how --scrape-examples interacts with macros. If an expression's span AND it's enclosing item's span both are not `from_expansion`, then the example will be scraped. The added test case `rustdoc-scrape-examples-macros` shows a variety of situations.

* A macro-rules macro that takes a function call as input: good
* A macro-rules macro that generates a function call as output: bad
* A proc-macro that generates a function call as output: bad
* An attribute macro that generates a function call as output: bad
* An attribute macro that takes a function call as input: good, if the proc macro is designed to propagate the input spans

I ran this updated rustdoc on pyo3 and confirmed that it successfully scrapes examples from inside a proc macro, eg

<img width="1013" alt="Screen Shot 2021-11-04 at 1 11 28 PM" src="https://user-images.githubusercontent.com/663326/140412691-81a3bb6b-a448-4a1b-a293-f7a795553634.png">

(cc `@mejrs)`

Additionally, this PR fixes an ordering bug in the highlighting logic.

Fixes rust-lang#90567.

r? `@jyn514`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 4, 2021
…n514

Fix ICE when rustdoc is scraping examples inside of a proc macro

This PR provides a clearer semantics for how --scrape-examples interacts with macros. If an expression's span AND it's enclosing item's span both are not `from_expansion`, then the example will be scraped. The added test case `rustdoc-scrape-examples-macros` shows a variety of situations.

* A macro-rules macro that takes a function call as input: good
* A macro-rules macro that generates a function call as output: bad
* A proc-macro that generates a function call as output: bad
* An attribute macro that generates a function call as output: bad
* An attribute macro that takes a function call as input: good, if the proc macro is designed to propagate the input spans

I ran this updated rustdoc on pyo3 and confirmed that it successfully scrapes examples from inside a proc macro, eg

<img width="1013" alt="Screen Shot 2021-11-04 at 1 11 28 PM" src="https://user-images.githubusercontent.com/663326/140412691-81a3bb6b-a448-4a1b-a293-f7a795553634.png">

(cc `@mejrs)`

Additionally, this PR fixes an ordering bug in the highlighting logic.

Fixes rust-lang#90567.

r? `@jyn514`
@bors bors closed this as completed in 0d1754e Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-scrape-examples Area: The (unstable) rustdoc scrape-examples feature described in RFC 3123 C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants