Remove more Session methods that duplicate DiagCtxt methods.

This commit is contained in:
Nicholas Nethercote 2023-12-21 16:26:09 +11:00
parent 8af3d8dcab
commit 8a9db25459
36 changed files with 62 additions and 74 deletions

View File

@ -529,7 +529,7 @@ enum ArgRef<'a> {
// Only check for unused named argument names if there are no other errors to avoid causing
// too much noise in output errors, such as when a named argument is entirely unused.
if invalid_refs.is_empty() && ecx.sess.err_count() == 0 {
if invalid_refs.is_empty() && ecx.dcx().err_count() == 0 {
for &(index, span, used_as) in &numeric_refences_to_named_arg {
let (position_sp_to_replace, position_sp_for_msg) = match used_as {
Placeholder(pspan) => (span, pspan),

View File

@ -108,7 +108,7 @@ pub(crate) fn join(
self.concurrency_limiter.finished();
sess.abort_if_errors();
sess.dcx().abort_if_errors();
(
CodegenResults {

View File

@ -151,7 +151,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
tcx.dcx().fatal("Inline asm is not supported in JIT mode");
}
tcx.sess.abort_if_errors();
tcx.dcx().abort_if_errors();
jit_module.finalize_definitions().unwrap();
unsafe { cx.unwind_context.register_jit(&jit_module) };
@ -338,7 +338,7 @@ fn dep_symbol_lookup_fn(
.collect::<Box<[_]>>(),
);
sess.abort_if_errors();
sess.dcx().abort_if_errors();
Box::new(move |sym_name| {
for dylib in &*imported_dylibs {

View File

@ -204,7 +204,7 @@ fn codegen_crate(
metadata: EncodedMetadata,
need_metadata_module: bool,
) -> Box<dyn Any> {
tcx.sess.abort_if_errors();
tcx.dcx().abort_if_errors();
let config = self.config.borrow().clone().unwrap();
match config.codegen_mode {
CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module),

View File

@ -716,7 +716,7 @@ fn read_input(&self, path: &Path) -> std::io::Result<&[u8]> {
Ok(()) => {}
Err(e) => {
sess.dcx().emit_err(errors::ThorinErrorWrapper(e));
sess.abort_if_errors();
sess.dcx().abort_if_errors();
}
}
}
@ -765,7 +765,7 @@ fn link_natively<'a>(
}
// May have not found libraries in the right formats.
sess.abort_if_errors();
sess.dcx().abort_if_errors();
// Invoke the system linker
info!("{:?}", &cmd);
@ -970,7 +970,7 @@ fn is_illegal_instruction(_status: &ExitStatus) -> bool {
}
}
sess.abort_if_errors();
sess.dcx().abort_if_errors();
}
info!("linker stderr:\n{}", escape_string(&prog.stderr));
info!("linker stdout:\n{}", escape_string(&prog.stdout));
@ -993,7 +993,7 @@ fn is_illegal_instruction(_status: &ExitStatus) -> bool {
sess.dcx().emit_note(errors::CheckInstalledVisualStudio);
sess.dcx().emit_note(errors::InsufficientVSCodeProduct);
}
sess.abort_if_errors();
sess.dcx().abort_if_errors();
}
}

View File

@ -1883,7 +1883,7 @@ pub fn check(&self, sess: &Session, blocking: bool) {
err.emit();
}
Ok(SharedEmitterMessage::AbortIfErrors) => {
sess.abort_if_errors();
sess.dcx().abort_if_errors();
}
Ok(SharedEmitterMessage::Fatal(msg)) => {
sess.dcx().fatal(msg);
@ -1939,7 +1939,7 @@ pub fn join(self, sess: &Session) -> (CodegenResults, FxIndexMap<WorkProductId,
let compiled_modules = sess.time("join_worker_thread", || match self.coordinator.join() {
Ok(Ok(compiled_modules)) => compiled_modules,
Ok(Err(())) => {
sess.abort_if_errors();
sess.dcx().abort_if_errors();
panic!("expected abort due to worker thread errors")
}
Err(_) => {
@ -1947,7 +1947,7 @@ pub fn join(self, sess: &Session) -> (CodegenResults, FxIndexMap<WorkProductId,
}
});
sess.abort_if_errors();
sess.dcx().abort_if_errors();
let work_products =
copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess, &compiled_modules);

View File

@ -448,8 +448,9 @@ fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
let Some(llfn) = cx.declare_c_main(llfty) else {
// FIXME: We should be smart and show a better diagnostic here.
let span = cx.tcx().def_span(rust_main_def_id);
cx.sess().dcx().emit_err(errors::MultipleMainFunctions { span });
cx.sess().abort_if_errors();
let dcx = cx.tcx().dcx();
dcx.emit_err(errors::MultipleMainFunctions { span });
dcx.abort_if_errors();
bug!();
};
@ -752,7 +753,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
// This will unwind if there are errors, which triggers our `AbortCodegenOnDrop`
// guard. Unfortunately, just skipping the `submit_codegened_module_to_llvm` makes
// compilation hang on post-monomorphization errors.
tcx.sess.abort_if_errors();
tcx.dcx().abort_if_errors();
submit_codegened_module_to_llvm(
&backend,

View File

@ -279,7 +279,7 @@ pub fn check_body(&mut self) {
self.tcx.dcx().emit_diagnostic(error);
}
} else {
assert!(self.tcx.sess.has_errors().is_some());
assert!(self.tcx.dcx().has_errors().is_some());
}
}

View File

@ -150,7 +150,7 @@ pub(super) fn install() {}
pub fn abort_on_err<T>(result: Result<T, ErrorGuaranteed>, sess: &Session) -> T {
match result {
Err(..) => {
sess.abort_if_errors();
sess.dcx().abort_if_errors();
panic!("error reported but abort_if_errors didn't abort???");
}
Ok(x) => x,

View File

@ -1284,7 +1284,7 @@ pub(super) fn check_type_params_are_used<'tcx>(
if ty.references_error() {
// If there is already another error, do not emit
// an error for not using a type parameter.
assert!(tcx.sess.has_errors().is_some());
assert!(tcx.dcx().has_errors().is_some());
return;
}

View File

@ -115,7 +115,7 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
let errors = wfcx.select_all_or_error();
if !errors.is_empty() {
let err = infcx.err_ctxt().report_fulfillment_errors(errors);
if tcx.sess.err_count() > 0 {
if tcx.dcx().err_count() > 0 {
return Err(err);
} else {
// HACK(oli-obk): tests/ui/specialization/min_specialization/specialize_on_type_error.rs

View File

@ -234,7 +234,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
tcx.ensure().check_unused_traits(());
if let Some(reported) = tcx.sess.has_errors() { Err(reported) } else { Ok(()) }
if let Some(reported) = tcx.dcx().has_errors() { Err(reported) } else { Ok(()) }
}
/// A quasi-deprecated helper used in rustdoc and clippy to get

View File

@ -690,7 +690,7 @@ fn check_expr_break(
// else an error would have been flagged by the
// `loops` pass for using break with an expression
// where you are not supposed to.
assert!(expr_opt.is_none() || self.tcx.sess.has_errors().is_some());
assert!(expr_opt.is_none() || self.dcx().has_errors().is_some());
}
// If we encountered a `break`, then (no surprise) it may be possible to break from the

View File

@ -576,7 +576,7 @@ fn walk_struct_expr<'hir>(
// struct; however, when EUV is run during typeck, it
// may not. This will generate an error earlier in typeck,
// so we can just ignore it.
if self.tcx().sess.has_errors().is_none() {
if self.tcx().dcx().has_errors().is_none() {
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
}
}

View File

@ -119,7 +119,7 @@ pub fn new(
FnCtxt {
body_id,
param_env,
err_count_on_creation: inh.tcx.sess.err_count(),
err_count_on_creation: inh.tcx.dcx().err_count(),
ret_coercion: None,
ret_coercion_span: Cell::new(None),
resume_yield_tys: None,
@ -188,7 +188,7 @@ pub fn err_ctxt(&'a self) -> TypeErrCtxt<'a, 'tcx> {
}
pub fn errors_reported_since_creation(&self) -> bool {
self.tcx.sess.err_count() > self.err_count_on_creation
self.dcx().err_count() > self.err_count_on_creation
}
pub fn next_root_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {

View File

@ -753,7 +753,7 @@ fn new(
}
fn report_error(&self, p: impl Into<ty::GenericArg<'tcx>>) -> ErrorGuaranteed {
match self.fcx.tcx.sess.has_errors() {
match self.fcx.dcx().has_errors() {
Some(e) => e,
None => self
.fcx

View File

@ -312,7 +312,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
let incr_comp_session_dir: PathBuf = sess.incr_comp_session_dir().clone();
if let Some(_) = sess.has_errors_or_span_delayed_bugs() {
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
// If there have been any errors during compilation, we don't want to
// publish this session directory. Rather, we'll just delete it.

View File

@ -32,7 +32,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
return;
}
// This is going to be deleted in finalize_session_directory, so let's not create it
if let Some(_) = sess.has_errors_or_span_delayed_bugs() {
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
return;
}
@ -87,7 +87,7 @@ pub fn save_work_product_index(
return;
}
// This is going to be deleted in finalize_session_directory, so let's not create it
if let Some(_) = sess.has_errors_or_span_delayed_bugs() {
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
return;
}

View File

@ -133,7 +133,7 @@ pub struct TypeErrCtxt<'a, 'tcx> {
impl Drop for TypeErrCtxt<'_, '_> {
fn drop(&mut self) {
if let Some(_) = self.infcx.tcx.sess.has_errors_or_span_delayed_bugs() {
if let Some(_) = self.dcx().has_errors_or_span_delayed_bugs() {
// ok, emitted an error.
} else {
self.infcx

View File

@ -704,7 +704,7 @@ pub fn build(&mut self) -> InferCtxt<'tcx> {
reported_trait_errors: Default::default(),
reported_closure_mismatch: Default::default(),
tainted_by_errors: Cell::new(None),
err_count_on_creation: tcx.sess.err_count(),
err_count_on_creation: tcx.dcx().err_count(),
universe: Cell::new(ty::UniverseIndex::ROOT),
intercrate,
next_trait_solver,
@ -1262,7 +1262,7 @@ pub fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
debug!(
"is_tainted_by_errors(err_count={}, err_count_on_creation={}, \
tainted_by_errors={})",
self.tcx.sess.err_count(),
self.dcx().err_count(),
self.err_count_on_creation,
self.tainted_by_errors.get().is_some()
);
@ -1271,9 +1271,9 @@ pub fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
return Some(e);
}
if self.tcx.sess.err_count() > self.err_count_on_creation {
if self.dcx().err_count() > self.err_count_on_creation {
// errors reported since this infcx was made
let e = self.tcx.sess.has_errors().unwrap();
let e = self.dcx().has_errors().unwrap();
self.set_tainted_by_errors(e);
return Some(e);
}

View File

@ -216,7 +216,7 @@ fn configure_and_expand(
// 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();
sess.dcx().abort_if_errors();
unreachable!();
}
@ -776,7 +776,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
// lot of annoying errors in the ui tests (basically,
// lint warnings and so on -- kindck used to do this abort, but
// kindck is gone now). -nmatsakis
if let Some(reported) = sess.has_errors() {
if let Some(reported) = sess.dcx().has_errors() {
return Err(reported);
}
@ -937,8 +937,9 @@ pub fn start_codegen<'tcx>(
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
tcx.dcx().emit_err(errors::CantEmitMIR { error });
tcx.sess.abort_if_errors();
let dcx = tcx.dcx();
dcx.emit_err(errors::CantEmitMIR { error });
dcx.abort_if_errors();
}
}

View File

@ -925,7 +925,7 @@ fn inject_dependency_if(
// don't perform this validation if the session has errors, as one of
// those errors may indicate a circular dependency which could cause
// this to stack overflow.
if self.sess.has_errors().is_some() {
if self.dcx().has_errors().is_some() {
return;
}

View File

@ -55,7 +55,7 @@ fn references_error(&self) -> bool {
}
fn error_reported(&self) -> Result<(), ErrorGuaranteed> {
if self.references_error() {
if let Some(reported) = ty::tls::with(|tcx| tcx.sess.is_compilation_going_to_fail()) {
if let Some(reported) = ty::tls::with(|tcx| tcx.dcx().is_compilation_going_to_fail()) {
Err(reported)
} else {
bug!("expect tcx.sess.is_compilation_going_to_fail return `Some`");

View File

@ -51,7 +51,7 @@ fn from_cycle_error(tcx: TyCtxt<'tcx>, stack: &[QueryInfo], guar: ErrorGuarantee
{
sig.decl.inputs.len() + sig.decl.implicit_self.has_implicit_self() as usize
} else {
tcx.sess.abort_if_errors();
tcx.dcx().abort_if_errors();
unreachable!()
};

View File

@ -1110,7 +1110,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
let (items, usage_map) = collector::collect_crate_mono_items(tcx, collection_mode);
tcx.sess.abort_if_errors();
tcx.dcx().abort_if_errors();
let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || {
sync::join(

View File

@ -2579,7 +2579,7 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs());
}
if check_attr_visitor.abort.get() {
tcx.sess.abort_if_errors()
tcx.dcx().abort_if_errors()
}
}

View File

@ -818,7 +818,7 @@ fn try_mark_parent_green<Qcx: QueryContext<Deps = D>>(
None => {}
}
if let None = qcx.dep_context().sess().has_errors_or_span_delayed_bugs() {
if let None = qcx.dep_context().sess().dcx().has_errors_or_span_delayed_bugs() {
panic!("try_mark_previous_green() - Forcing the DepNode should have set its color")
}

View File

@ -126,7 +126,7 @@ fn handle_cycle_error<Q, Qcx>(
}
Fatal => {
error.emit();
qcx.dep_context().sess().abort_if_errors();
qcx.dep_context().sess().dcx().abort_if_errors();
unreachable!()
}
DelayBug => {

View File

@ -9,7 +9,7 @@ pub trait Value<Tcx: DepContext>: Sized {
impl<Tcx: DepContext, T> Value<Tcx> for T {
default fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo], _guar: ErrorGuaranteed) -> T {
tcx.sess().abort_if_errors();
tcx.sess().dcx().abort_if_errors();
// Ideally we would use `bug!` here. But bug! is only defined in rustc_middle, and it's
// non-trivial to define it earlier.
panic!(

View File

@ -115,7 +115,7 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
}
if err_count > 0 {
sess.abort_if_errors();
sess.dcx().abort_if_errors();
}
}

View File

@ -279,7 +279,7 @@ fn check_miri_unleashed_features(&self) {
});
// If we should err, make sure we did.
if must_err && self.has_errors().is_none() {
if must_err && self.dcx().has_errors().is_none() {
// We have skipped a feature gate, and not run into other errors... reject.
self.dcx().emit_err(errors::NotCircumventFeature);
}
@ -323,22 +323,7 @@ pub fn create_feature_err<'a>(
add_feature_diagnostics(&mut err, &self.parse_sess, feature);
err
}
#[inline]
pub fn err_count(&self) -> usize {
self.dcx().err_count()
}
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
self.dcx().has_errors()
}
pub fn has_errors_or_span_delayed_bugs(&self) -> Option<ErrorGuaranteed> {
self.dcx().has_errors_or_span_delayed_bugs()
}
pub fn is_compilation_going_to_fail(&self) -> Option<ErrorGuaranteed> {
self.dcx().is_compilation_going_to_fail()
}
pub fn abort_if_errors(&self) {
self.dcx().abort_if_errors();
}
pub fn compile_status(&self) -> Result<(), ErrorGuaranteed> {
if let Some(reported) = self.dcx().has_errors_or_lint_errors() {
let _ = self.dcx().emit_stashed_diagnostics();
@ -347,14 +332,15 @@ pub fn compile_status(&self) -> Result<(), ErrorGuaranteed> {
Ok(())
}
}
// FIXME(matthewjasper) Remove this method, it should never be needed.
pub fn track_errors<F, T>(&self, f: F) -> Result<T, ErrorGuaranteed>
where
F: FnOnce() -> T,
{
let old_count = self.err_count();
let old_count = self.dcx().err_count();
let result = f();
if self.err_count() == old_count {
if self.dcx().err_count() == old_count {
Ok(result)
} else {
Err(self.dcx().span_delayed_bug(

View File

@ -251,7 +251,7 @@ fn report_overflow_error<T>(
mutate(&mut err);
err.emit();
self.tcx.sess.abort_if_errors();
self.dcx().abort_if_errors();
// FIXME: this should be something like `build_overflow_error_fatal`, which returns
// `DiagnosticBuilder<', !>`. Then we don't even need anything after that `emit()`.
unreachable!(
@ -443,7 +443,7 @@ fn report_selection_error(
// FIXME(effects)
let predicate_is_const = false;
if self.tcx.sess.has_errors().is_some()
if self.dcx().has_errors().is_some()
&& trait_predicate.references_error()
{
return;
@ -2606,7 +2606,7 @@ fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>) {
// Same hacky approach as above to avoid deluging user
// with error messages.
if arg.references_error()
|| self.tcx.sess.has_errors().is_some()
|| self.dcx().has_errors().is_some()
|| self.tainted_by_errors().is_some()
{
return;
@ -2623,7 +2623,7 @@ fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>) {
ty::PredicateKind::Subtype(data) => {
if data.references_error()
|| self.tcx.sess.has_errors().is_some()
|| self.dcx().has_errors().is_some()
|| self.tainted_by_errors().is_some()
{
// no need to overload user in such cases
@ -2702,7 +2702,7 @@ fn maybe_report_ambiguity(&self, obligation: &PredicateObligation<'tcx>) {
}
}
_ => {
if self.tcx.sess.has_errors().is_some() || self.tainted_by_errors().is_some() {
if self.dcx().has_errors().is_some() || self.tainted_by_errors().is_some() {
return;
}
let mut err = struct_span_err!(

View File

@ -326,7 +326,7 @@ pub(crate) fn run_global_ctxt(
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_item_types(module))
});
tcx.sess.abort_if_errors();
tcx.dcx().abort_if_errors();
tcx.sess.time("missing_docs", || rustc_lint::check_crate(tcx));
tcx.sess.time("check_mod_attrs", || {
tcx.hir().for_each_module(|module| tcx.ensure().check_mod_attrs(module))

View File

@ -690,7 +690,7 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>(
tcx: TyCtxt<'tcx>,
) -> MainResult {
match formats::run_format::<T>(krate, renderopts, cache, tcx) {
Ok(_) => tcx.sess.has_errors().map_or(Ok(()), Err),
Ok(_) => tcx.dcx().has_errors().map_or(Ok(()), Err),
Err(e) => {
let mut msg =
tcx.dcx().struct_err(format!("couldn't generate documentation: {}", e.error));

View File

@ -110,7 +110,7 @@ fn after_analysis<'tcx>(
i32::try_from(return_code).expect("Return value was too large!"),
);
}
tcx.sess.abort_if_errors();
tcx.dcx().abort_if_errors();
});
Compilation::Stop

View File

@ -61,7 +61,7 @@ fn after_analysis<'tcx>(
compiler: &Compiler,
queries: &'tcx Queries<'tcx>,
) -> Compilation {
compiler.sess.abort_if_errors();
compiler.sess.dcx().abort_if_errors();
queries.global_ctxt().unwrap().enter(|tcx| {
// Collect definition ids of MIR bodies.
let hir = tcx.hir();