Skip to content

Commit 37e2f4f

Browse files
committed
Make configure_and_expand "infalllible" by just aborting the compilation if it fails instead of bubbling out an error
1 parent 63c8d00 commit 37e2f4f

10 files changed

+33
-37
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_borrowck as mir_borrowck;
99
use rustc_codegen_ssa::traits::CodegenBackend;
1010
use rustc_data_structures::parallel;
1111
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
12-
use rustc_errors::{ErrorGuaranteed, PResult};
12+
use rustc_errors::PResult;
1313
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
1414
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
1515
use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintStore};
@@ -176,7 +176,7 @@ pub fn configure_and_expand(
176176
tcx: TyCtxt<'_>,
177177
mut krate: ast::Crate,
178178
resolver: &mut Resolver<'_, '_>,
179-
) -> Result<ast::Crate> {
179+
) -> ast::Crate {
180180
let sess = tcx.sess;
181181
let lint_store = unerased_lint_store(tcx);
182182
let crate_name = tcx.crate_name(LOCAL_CRATE);
@@ -250,20 +250,19 @@ pub fn configure_and_expand(
250250
ecx.check_unused_macros();
251251
});
252252

253-
let recursion_limit_hit = ecx.reduced_recursion_limit.is_some();
253+
// If we hit a recursion limit, exit early to avoid later passes getting overwhelmed
254+
// with a large AST
255+
if ecx.reduced_recursion_limit.is_some() {
256+
sess.abort_if_errors();
257+
unreachable!();
258+
}
254259

255260
if cfg!(windows) {
256261
env::set_var("PATH", &old_path);
257262
}
258263

259-
if recursion_limit_hit {
260-
// If we hit a recursion limit, exit early to avoid later passes getting overwhelmed
261-
// with a large AST
262-
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
263-
} else {
264-
Ok(krate)
265-
}
266-
})?;
264+
krate
265+
});
267266

268267
sess.time("maybe_building_test_harness", || {
269268
rustc_builtin_macros::test_harness::inject(sess, resolver, &mut krate)
@@ -366,7 +365,7 @@ pub fn configure_and_expand(
366365
)
367366
});
368367

369-
Ok(krate)
368+
krate
370369
}
371370

372371
// Returns all the paths that correspond to generated files.

compiler/rustc_interface/src/queries.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'tcx> Queries<'tcx> {
227227
self.codegen_backend().metadata_loader(),
228228
&arenas,
229229
);
230-
let krate = passes::configure_and_expand(tcx, krate, &mut resolver)?;
230+
let krate = passes::configure_and_expand(tcx, krate, &mut resolver);
231231

232232
// Make sure we don't mutate the cstore from here on.
233233
tcx.untracked().cstore.leak();
@@ -245,8 +245,7 @@ impl<'tcx> Queries<'tcx> {
245245
);
246246
feed.resolutions(tcx.arena.alloc(untracked_resolutions));
247247
feed.features_query(tcx.sess.features_untracked());
248-
Ok(())
249-
})?;
248+
});
250249
Ok(qcx)
251250
})
252251
}

tests/rustdoc-ui/bounded-hr-lifetime.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ error: lifetime bounds cannot be used in this context
44
LL | for<'a: 'b + 'c> &'a (): std::fmt::Debug,
55
| ^^ ^^
66

7-
error: Compilation failed, aborting rustdoc
8-
9-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
108

tests/rustdoc-ui/feature-gate-doc_cfg_hide.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ LL | #![doc(cfg_hide(test))]
77
= note: see issue #43781 <https://github.com/rust-lang/rust/issues/43781> for more information
88
= help: add `#![feature(doc_cfg_hide)]` to the crate attributes to enable
99

10-
error: Compilation failed, aborting rustdoc
11-
12-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
1311

1412
For more information about this error, try `rustc --explain E0658`.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#![deny(unknown_lints)]
22
//~^ NOTE defined here
3-
43
#![allow(rustdoc::missing_doc_code_examples)]
54
//~^ ERROR unknown lint
65
//~| ERROR unknown lint
6+
//~| ERROR unknown lint
7+
//~| NOTE lint is unstable
78
//~| NOTE lint is unstable
89
//~| NOTE lint is unstable
910
//~| NOTE see issue
1011
//~| NOTE see issue
12+
//~| NOTE see issue

tests/rustdoc-ui/feature-gate-rustdoc_missing_doc_code_examples.stderr

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unknown lint: `rustdoc::missing_doc_code_examples`
2-
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:4:1
2+
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:3:1
33
|
44
LL | #![allow(rustdoc::missing_doc_code_examples)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -14,7 +14,7 @@ LL | #![deny(unknown_lints)]
1414
| ^^^^^^^^^^^^^
1515

1616
error: unknown lint: `rustdoc::missing_doc_code_examples`
17-
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:4:1
17+
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:3:1
1818
|
1919
LL | #![allow(rustdoc::missing_doc_code_examples)]
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -23,7 +23,15 @@ LL | #![allow(rustdoc::missing_doc_code_examples)]
2323
= note: see issue #101730 <https://github.com/rust-lang/rust/issues/101730> for more information
2424
= help: add `#![feature(rustdoc_missing_doc_code_examples)]` to the crate attributes to enable
2525

26-
error: Compilation failed, aborting rustdoc
26+
error: unknown lint: `rustdoc::missing_doc_code_examples`
27+
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:3:1
28+
|
29+
LL | #![allow(rustdoc::missing_doc_code_examples)]
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= note: the `rustdoc::missing_doc_code_examples` lint is unstable
33+
= note: see issue #101730 <https://github.com/rust-lang/rust/issues/101730> for more information
34+
= help: add `#![feature(rustdoc_missing_doc_code_examples)]` to the crate attributes to enable
2735

2836
error: aborting due to 3 previous errors
2937

tests/rustdoc-ui/impl-fn-nesting.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ error[E0412]: cannot find type `UnknownType` in this scope
5858
LL | pub fn doubly_nested(c: UnknownType) {
5959
| ^^^^^^^^^^^ not found in this scope
6060

61-
error: Compilation failed, aborting rustdoc
62-
63-
error: aborting due to 11 previous errors
61+
error: aborting due to 10 previous errors
6462

6563
Some errors have detailed explanations: E0405, E0412.
6664
For more information about an error, try `rustc --explain E0405`.

tests/rustdoc-ui/intra-doc/unresolved-import-recovery.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | use unresolved_crate::module::Name;
66
|
77
= help: consider adding `extern crate unresolved_crate` to use the `unresolved_crate` crate
88

9-
error: Compilation failed, aborting rustdoc
10-
11-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1210

1311
For more information about this error, try `rustc --explain E0433`.

tests/rustdoc-ui/issue-61732.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ LL | pub(in crate::r#mod) fn main() {}
66
|
77
= help: consider adding `extern crate r#mod` to use the `r#mod` crate
88

9-
error: Compilation failed, aborting rustdoc
10-
11-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1210

1311
For more information about this error, try `rustc --explain E0433`.

tests/rustdoc-ui/unknown-renamed-lints.stderr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,5 @@ error: unknown lint: `rustdoc::intra_doc_link_resolution_failure`
5858
LL | #![deny(rustdoc::intra_doc_link_resolution_failure)]
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060

61-
error: Compilation failed, aborting rustdoc
62-
63-
error: aborting due to 9 previous errors
61+
error: aborting due to 8 previous errors
6462

0 commit comments

Comments
 (0)