Make configure_and_expand "infalllible" by just aborting the compilation if it fails instead of bubbling out an error

This commit is contained in:
Oli Scherer 2023-02-16 14:03:31 +00:00
parent 63c8d00090
commit 37e2f4f487
10 changed files with 33 additions and 37 deletions

View file

@ -9,7 +9,7 @@ use rustc_borrowck as mir_borrowck;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::parallel;
use rustc_data_structures::sync::{Lrc, OnceCell, WorkerLocal};
use rustc_errors::{ErrorGuaranteed, PResult};
use rustc_errors::PResult;
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
use rustc_lint::{unerased_lint_store, BufferedEarlyLint, EarlyCheckNode, LintStore};
@ -176,7 +176,7 @@ pub fn configure_and_expand(
tcx: TyCtxt<'_>,
mut krate: ast::Crate,
resolver: &mut Resolver<'_, '_>,
) -> Result<ast::Crate> {
) -> ast::Crate {
let sess = tcx.sess;
let lint_store = unerased_lint_store(tcx);
let crate_name = tcx.crate_name(LOCAL_CRATE);
@ -250,20 +250,19 @@ pub fn configure_and_expand(
ecx.check_unused_macros();
});
let recursion_limit_hit = ecx.reduced_recursion_limit.is_some();
// If we hit a recursion limit, exit early to avoid later passes getting overwhelmed
// with a large AST
if ecx.reduced_recursion_limit.is_some() {
sess.abort_if_errors();
unreachable!();
}
if cfg!(windows) {
env::set_var("PATH", &old_path);
}
if recursion_limit_hit {
// If we hit a recursion limit, exit early to avoid later passes getting overwhelmed
// with a large AST
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
} else {
Ok(krate)
}
})?;
krate
});
sess.time("maybe_building_test_harness", || {
rustc_builtin_macros::test_harness::inject(sess, resolver, &mut krate)
@ -366,7 +365,7 @@ pub fn configure_and_expand(
)
});
Ok(krate)
krate
}
// Returns all the paths that correspond to generated files.

View file

@ -227,7 +227,7 @@ impl<'tcx> Queries<'tcx> {
self.codegen_backend().metadata_loader(),
&arenas,
);
let krate = passes::configure_and_expand(tcx, krate, &mut resolver)?;
let krate = passes::configure_and_expand(tcx, krate, &mut resolver);
// Make sure we don't mutate the cstore from here on.
tcx.untracked().cstore.leak();
@ -245,8 +245,7 @@ impl<'tcx> Queries<'tcx> {
);
feed.resolutions(tcx.arena.alloc(untracked_resolutions));
feed.features_query(tcx.sess.features_untracked());
Ok(())
})?;
});
Ok(qcx)
})
}

View file

@ -4,7 +4,5 @@ error: lifetime bounds cannot be used in this context
LL | for<'a: 'b + 'c> &'a (): std::fmt::Debug,
| ^^ ^^
error: Compilation failed, aborting rustdoc
error: aborting due to 2 previous errors
error: aborting due to previous error

View file

@ -7,8 +7,6 @@ LL | #![doc(cfg_hide(test))]
= note: see issue #43781 <https://github.com/rust-lang/rust/issues/43781> for more information
= help: add `#![feature(doc_cfg_hide)]` to the crate attributes to enable
error: Compilation failed, aborting rustdoc
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -1,10 +1,12 @@
#![deny(unknown_lints)]
//~^ NOTE defined here
#![allow(rustdoc::missing_doc_code_examples)]
//~^ ERROR unknown lint
//~| ERROR unknown lint
//~| ERROR unknown lint
//~| NOTE lint is unstable
//~| NOTE lint is unstable
//~| NOTE lint is unstable
//~| NOTE see issue
//~| NOTE see issue
//~| NOTE see issue

View file

@ -1,5 +1,5 @@
error: unknown lint: `rustdoc::missing_doc_code_examples`
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:4:1
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:3:1
|
LL | #![allow(rustdoc::missing_doc_code_examples)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -14,7 +14,7 @@ LL | #![deny(unknown_lints)]
| ^^^^^^^^^^^^^
error: unknown lint: `rustdoc::missing_doc_code_examples`
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:4:1
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:3:1
|
LL | #![allow(rustdoc::missing_doc_code_examples)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -23,7 +23,15 @@ LL | #![allow(rustdoc::missing_doc_code_examples)]
= note: see issue #101730 <https://github.com/rust-lang/rust/issues/101730> for more information
= help: add `#![feature(rustdoc_missing_doc_code_examples)]` to the crate attributes to enable
error: Compilation failed, aborting rustdoc
error: unknown lint: `rustdoc::missing_doc_code_examples`
--> $DIR/feature-gate-rustdoc_missing_doc_code_examples.rs:3:1
|
LL | #![allow(rustdoc::missing_doc_code_examples)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the `rustdoc::missing_doc_code_examples` lint is unstable
= note: see issue #101730 <https://github.com/rust-lang/rust/issues/101730> for more information
= help: add `#![feature(rustdoc_missing_doc_code_examples)]` to the crate attributes to enable
error: aborting due to 3 previous errors

View file

@ -58,9 +58,7 @@ error[E0412]: cannot find type `UnknownType` in this scope
LL | pub fn doubly_nested(c: UnknownType) {
| ^^^^^^^^^^^ not found in this scope
error: Compilation failed, aborting rustdoc
error: aborting due to 11 previous errors
error: aborting due to 10 previous errors
Some errors have detailed explanations: E0405, E0412.
For more information about an error, try `rustc --explain E0405`.

View file

@ -6,8 +6,6 @@ LL | use unresolved_crate::module::Name;
|
= help: consider adding `extern crate unresolved_crate` to use the `unresolved_crate` crate
error: Compilation failed, aborting rustdoc
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.

View file

@ -6,8 +6,6 @@ LL | pub(in crate::r#mod) fn main() {}
|
= help: consider adding `extern crate r#mod` to use the `r#mod` crate
error: Compilation failed, aborting rustdoc
error: aborting due to 2 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.

View file

@ -58,7 +58,5 @@ error: unknown lint: `rustdoc::intra_doc_link_resolution_failure`
LL | #![deny(rustdoc::intra_doc_link_resolution_failure)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Compilation failed, aborting rustdoc
error: aborting due to 9 previous errors
error: aborting due to 8 previous errors