Skip to content

Commit 1fa02dd

Browse files
authored
Rollup merge of #99976 - willcrichton:example-analyzer, r=jyn514
Make Rustdoc exit with correct error code when scraping examples from invalid files This PR fixes a small issue with the new Rustdoc scrape-examples feature. If a file that is being scraped has a type error, then currently that error is printed out, but the rustdoc process exits as if it succeeded. This is a problem for Cargo, which needs to track whether scraping succeeded (see rust-lang/cargo#10343). This PR fixes the issue by checking whether an error is emitted, and aborting if so.
2 parents 8db3d7c + a93feaf commit 1fa02dd

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/librustdoc/scrape_examples.rs

+6
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,12 @@ pub(crate) fn run(
304304
let mut finder = FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates };
305305
tcx.hir().visit_all_item_likes_in_crate(&mut finder);
306306

307+
// The visitor might have found a type error, which we need to
308+
// promote to a fatal error
309+
if tcx.sess.diagnostic().has_errors_or_lint_errors().is_some() {
310+
return Err(String::from("Compilation failed, aborting rustdoc"));
311+
}
312+
307313
// Sort call locations within a given file in document order
308314
for fn_calls in calls.values_mut() {
309315
for file_calls in fn_calls.values_mut() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-fail
2+
// compile-flags: -Z unstable-options --scrape-examples-output-path {{build-base}}/t.calls --scrape-examples-target-crate foobar
3+
4+
pub fn foo() {
5+
INVALID_FUNC();
6+
//~^ ERROR could not resolve path
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0433]: failed to resolve: could not resolve path `INVALID_FUNC`
2+
--> $DIR/scrape-examples-fail-if-type-error.rs:5:3
3+
|
4+
LL | INVALID_FUNC();
5+
| ^^^^^^^^^^^^ could not resolve path `INVALID_FUNC`
6+
|
7+
= note: this error was originally ignored because you are running `rustdoc`
8+
= note: try running again with `rustc` or `cargo check` and you may get a more detailed error
9+
10+
error: Compilation failed, aborting rustdoc
11+
12+
error: aborting due to 2 previous errors
13+
14+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)