fix(doctest): detect extern crate items in statement doctests

This partially reverts #91026, because rustdoc needs to detect the extern statements,
even when they appear inside implicit `main()`. It does not entirely revert it,
so the old bug is still fixed, by duplicating some of the logic from `parse_mod`
instead of trying to use it directly.

Fixes #91134
This commit is contained in:
Michael Howell 2021-11-22 19:47:58 -07:00
parent 214ad2f5b5
commit bff1645bdb
5 changed files with 38 additions and 8 deletions

View file

@ -0,0 +1,3 @@
// no-prefer-dynamic
#![crate_type = "lib"]
pub fn empty() {}

View file

@ -0,0 +1,14 @@
// compile-flags: --test --crate-name=empty_fn --extern=empty_fn --test-args=--test-threads=1
// aux-build:empty-fn.rs
// check-pass
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
// edition:2021
/// <https://github.com/rust-lang/rust/issues/91134>
///
/// ```
/// extern crate empty_fn;
/// empty_fn::empty();
/// ```
pub struct Something;

View file

@ -0,0 +1,6 @@
running 1 test
test $DIR/issue-91134.rs - something (line 10) ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME