From 99472c7049783605444ab888a97059d0cce93a12 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 18 Dec 2023 22:21:37 +1100 Subject: Remove `Session` methods that duplicate `DiagCtxt` methods. Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access. --- compiler/rustc_interface/src/passes.rs | 22 +++++++++++----------- compiler/rustc_interface/src/queries.rs | 10 ++++++---- compiler/rustc_interface/src/util.rs | 10 +++++----- 3 files changed, 22 insertions(+), 20 deletions(-) (limited to 'compiler/rustc_interface/src') diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 21beb90d73f..41504a56eef 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -246,15 +246,15 @@ fn configure_and_expand( if crate_types.len() > 1 { if is_executable_crate { - sess.emit_err(errors::MixedBinCrate); + sess.dcx().emit_err(errors::MixedBinCrate); } if is_proc_macro_crate { - sess.emit_err(errors::MixedProcMacroCrate); + sess.dcx().emit_err(errors::MixedProcMacroCrate); } } if is_proc_macro_crate && sess.panic_strategy() == PanicStrategy::Abort { - sess.emit_warning(errors::ProcMacroCratePanicAbort); + sess.dcx().emit_warning(errors::ProcMacroCratePanicAbort); } sess.time("maybe_create_a_macro_crate", || { @@ -314,9 +314,9 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { spans.sort(); if ident == sym::ferris { let first_span = spans[0]; - sess.emit_err(errors::FerrisIdentifier { spans, first_span }); + sess.dcx().emit_err(errors::FerrisIdentifier { spans, first_span }); } else { - sess.emit_err(errors::EmojiIdentifier { spans, ident }); + sess.dcx().emit_err(errors::EmojiIdentifier { spans, ident }); } } }); @@ -530,7 +530,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P } } Err(error) => { - sess.emit_fatal(errors::ErrorWritingDependencies { path: deps_filename, error }); + sess.dcx().emit_fatal(errors::ErrorWritingDependencies { path: deps_filename, error }); } } } @@ -576,10 +576,10 @@ pub(crate) fn write_dep_info(tcx: TyCtxt<'_>) { if let Some(input_path) = sess.io.input.opt_path() { if sess.opts.will_create_output_file() { if output_contains_path(&output_paths, input_path) { - sess.emit_fatal(errors::InputFileWouldBeOverWritten { path: input_path }); + sess.dcx().emit_fatal(errors::InputFileWouldBeOverWritten { path: input_path }); } if let Some(dir_path) = output_conflicts_with_dir(&output_paths) { - sess.emit_fatal(errors::GeneratedFileConflictsWithDirectory { + sess.dcx().emit_fatal(errors::GeneratedFileConflictsWithDirectory { input_path, dir_path, }); @@ -589,7 +589,7 @@ pub(crate) fn write_dep_info(tcx: TyCtxt<'_>) { if let Some(ref dir) = sess.io.temps_dir { if fs::create_dir_all(dir).is_err() { - sess.emit_fatal(errors::TempsDirError); + sess.dcx().emit_fatal(errors::TempsDirError); } } @@ -601,7 +601,7 @@ pub(crate) fn write_dep_info(tcx: TyCtxt<'_>) { if !only_dep_info { if let Some(ref dir) = sess.io.output_dir { if fs::create_dir_all(dir).is_err() { - sess.emit_fatal(errors::OutDirError); + sess.dcx().emit_fatal(errors::OutDirError); } } } @@ -937,7 +937,7 @@ 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.sess.emit_err(errors::CantEmitMIR { error }); + tcx.dcx().emit_err(errors::CantEmitMIR { error }); tcx.sess.abort_if_errors(); } } diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 8a553b95e8e..1ea3db26e21 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -208,12 +208,12 @@ impl<'tcx> Queries<'tcx> { // Bare `#[rustc_error]`. None => { - tcx.sess.emit_fatal(RustcErrorFatal { span: tcx.def_span(def_id) }); + tcx.dcx().emit_fatal(RustcErrorFatal { span: tcx.def_span(def_id) }); } // Some other attribute. Some(_) => { - tcx.sess.emit_warning(RustcErrorUnexpectedAnnotation { + tcx.dcx().emit_warning(RustcErrorUnexpectedAnnotation { span: tcx.def_span(def_id), }); } @@ -292,7 +292,9 @@ impl Linker { &codegen_results, &*self.output_filenames, ) - .map_err(|error| sess.emit_fatal(FailedWritingFile { path: &rlink_file, error }))?; + .map_err(|error| { + sess.dcx().emit_fatal(FailedWritingFile { path: &rlink_file, error }) + })?; return Ok(()); } @@ -330,7 +332,7 @@ impl Compiler { // the global context. _timer = Some(self.sess.timer("free_global_ctxt")); if let Err((path, error)) = queries.finish() { - self.sess.emit_err(errors::FailedWritingFile { path: &path, error }); + self.sess.dcx().emit_err(errors::FailedWritingFile { path: &path, error }); } ret diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index f230c5b172c..92a6445ed09 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -431,7 +431,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec Outpu &sess.opts.output_types, sess.io.output_file == Some(OutFileName::Stdout), ) { - sess.emit_fatal(errors::MultipleOutputTypesToStdout); + sess.dcx().emit_fatal(errors::MultipleOutputTypesToStdout); } let crate_name = sess @@ -507,16 +507,16 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu let unnamed_output_types = sess.opts.output_types.values().filter(|a| a.is_none()).count(); let ofile = if unnamed_output_types > 1 { - sess.emit_warning(errors::MultipleOutputTypesAdaption); + sess.dcx().emit_warning(errors::MultipleOutputTypesAdaption); None } else { if !sess.opts.cg.extra_filename.is_empty() { - sess.emit_warning(errors::IgnoringExtraFilename); + sess.dcx().emit_warning(errors::IgnoringExtraFilename); } Some(out_file.clone()) }; if sess.io.output_dir != None { - sess.emit_warning(errors::IgnoringOutDir); + sess.dcx().emit_warning(errors::IgnoringOutDir); } let out_filestem = -- cgit 1.4.1-3-g733a5 From 8a9db2545919f945ffbb215e4325917e0bfc5b3a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 21 Dec 2023 16:26:09 +1100 Subject: Remove more `Session` methods that duplicate `DiagCtxt` methods. --- compiler/rustc_builtin_macros/src/format.rs | 2 +- compiler/rustc_codegen_cranelift/src/driver/aot.rs | 2 +- compiler/rustc_codegen_cranelift/src/driver/jit.rs | 4 ++-- compiler/rustc_codegen_cranelift/src/lib.rs | 2 +- compiler/rustc_codegen_ssa/src/back/link.rs | 8 ++++---- compiler/rustc_codegen_ssa/src/back/write.rs | 6 +++--- compiler/rustc_codegen_ssa/src/base.rs | 7 ++++--- .../src/transform/check_consts/check.rs | 2 +- compiler/rustc_driver_impl/src/lib.rs | 2 +- compiler/rustc_hir_analysis/src/check/check.rs | 2 +- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 2 +- compiler/rustc_hir_analysis/src/lib.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 2 +- compiler/rustc_hir_typeck/src/expr_use_visitor.rs | 2 +- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 4 ++-- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- compiler/rustc_incremental/src/persist/fs.rs | 2 +- compiler/rustc_incremental/src/persist/save.rs | 4 ++-- .../rustc_infer/src/infer/error_reporting/mod.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 8 ++++---- compiler/rustc_interface/src/passes.rs | 9 ++++---- compiler/rustc_metadata/src/creader.rs | 2 +- compiler/rustc_middle/src/ty/visit.rs | 2 +- compiler/rustc_middle/src/values.rs | 2 +- compiler/rustc_monomorphize/src/partitioning.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_query_system/src/dep_graph/graph.rs | 2 +- compiler/rustc_query_system/src/query/plumbing.rs | 2 +- compiler/rustc_query_system/src/values.rs | 2 +- compiler/rustc_session/src/output.rs | 2 +- compiler/rustc_session/src/session.rs | 24 +++++----------------- .../traits/error_reporting/type_err_ctxt_ext.rs | 10 ++++----- src/librustdoc/core.rs | 2 +- src/librustdoc/lib.rs | 2 +- src/tools/miri/src/bin/miri.rs | 2 +- tests/run-make-fulldeps/obtain-borrowck/driver.rs | 2 +- 36 files changed, 62 insertions(+), 74 deletions(-) (limited to 'compiler/rustc_interface/src') diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index b896e51ddb3..a668db438eb 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -529,7 +529,7 @@ fn make_format_args( // 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), diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index df457b16085..e77b0cd0721 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -108,7 +108,7 @@ impl OngoingCodegen { self.concurrency_limiter.finished(); - sess.abort_if_errors(); + sess.dcx().abort_if_errors(); ( CodegenResults { diff --git a/compiler/rustc_codegen_cranelift/src/driver/jit.rs b/compiler/rustc_codegen_cranelift/src/driver/jit.rs index 63fa89d79bc..7905ec8402d 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/jit.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/jit.rs @@ -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::>(), ); - sess.abort_if_errors(); + sess.dcx().abort_if_errors(); Box::new(move |sym_name| { for dylib in &*imported_dylibs { diff --git a/compiler/rustc_codegen_cranelift/src/lib.rs b/compiler/rustc_codegen_cranelift/src/lib.rs index b9e02587fbc..b482f0dd2f0 100644 --- a/compiler/rustc_codegen_cranelift/src/lib.rs +++ b/compiler/rustc_codegen_cranelift/src/lib.rs @@ -204,7 +204,7 @@ impl CodegenBackend for CraneliftCodegenBackend { metadata: EncodedMetadata, need_metadata_module: bool, ) -> Box { - 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), diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index ae64b8ca588..4ff497f2fdd 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -716,7 +716,7 @@ fn link_dwarf_object<'a>( 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 link_natively<'a>( } } - 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 link_natively<'a>( sess.dcx().emit_note(errors::CheckInstalledVisualStudio); sess.dcx().emit_note(errors::InsufficientVSCodeProduct); } - sess.abort_if_errors(); + sess.dcx().abort_if_errors(); } } diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index f7eda81da29..5a8db7bbf2d 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -1883,7 +1883,7 @@ impl SharedEmitterMain { 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 @@ impl OngoingCodegen { 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 @@ impl OngoingCodegen { } }); - sess.abort_if_errors(); + sess.dcx().abort_if_errors(); let work_products = copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess, &compiled_modules); diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 1367e038492..9d1729c4b54 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -448,8 +448,9 @@ pub fn maybe_create_entry_wrapper<'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( // 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, diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index c524632765a..c1ab62ac0b8 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -279,7 +279,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { self.tcx.dcx().emit_diagnostic(error); } } else { - assert!(self.tcx.sess.has_errors().is_some()); + assert!(self.tcx.dcx().has_errors().is_some()); } } diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 672a5e17af1..ca6b0afc76a 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -150,7 +150,7 @@ pub const DEFAULT_BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/issu pub fn abort_on_err(result: Result, 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, diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 6bef57a3084..d2e96ac74df 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -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; } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index efeb15be761..580d4bd5b02 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -115,7 +115,7 @@ where 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 diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 1d149f5c2e3..81d8982eb15 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -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 diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 06759bf7a5b..267fd00da84 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -690,7 +690,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // 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 diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index b5758925550..e952a7ff9e8 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -576,7 +576,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { // 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"); } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 61f38810356..635284c5f73 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -119,7 +119,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { 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 @@ impl<'a, 'tcx> FnCtxt<'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> { diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 57c8ef46f49..719d85ed3db 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -753,7 +753,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> { } fn report_error(&self, p: impl Into>) -> ErrorGuaranteed { - match self.fcx.tcx.sess.has_errors() { + match self.fcx.dcx().has_errors() { Some(e) => e, None => self .fcx diff --git a/compiler/rustc_incremental/src/persist/fs.rs b/compiler/rustc_incremental/src/persist/fs.rs index f3fc7069e86..2c6ae91786d 100644 --- a/compiler/rustc_incremental/src/persist/fs.rs +++ b/compiler/rustc_incremental/src/persist/fs.rs @@ -312,7 +312,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option) { 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. diff --git a/compiler/rustc_incremental/src/persist/save.rs b/compiler/rustc_incremental/src/persist/save.rs index f09a48a47fb..bdc935a5e3b 100644 --- a/compiler/rustc_incremental/src/persist/save.rs +++ b/compiler/rustc_incremental/src/persist/save.rs @@ -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; } diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index a61e0e12065..0c0292f329e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -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 diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index dccbac1fa31..fa694f09f17 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -704,7 +704,7 @@ impl<'tcx> InferCtxtBuilder<'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 @@ impl<'tcx> InferCtxt<'tcx> { 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 @@ impl<'tcx> InferCtxt<'tcx> { 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); } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 41504a56eef..559874641c3 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -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(); } } diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index b82c875f9ed..a3da8c14f63 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -925,7 +925,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { // 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; } diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index e1ce941256c..1f8978aa863 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -55,7 +55,7 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable> { } 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`"); diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index a85296d886d..b4e45ad5685 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -51,7 +51,7 @@ impl<'tcx> Value> for ty::Binder<'_, ty::FnSig<'_>> { { 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!() }; diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 55090636cb7..08e62840839 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -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( diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index cea4b113bf6..edce99db705 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -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() } } diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index 3556a5ec1d1..9b06823dfba 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -818,7 +818,7 @@ impl DepGraphData { 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") } diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index bcd507ad76c..34f2c01f890 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -126,7 +126,7 @@ where } Fatal => { error.emit(); - qcx.dep_context().sess().abort_if_errors(); + qcx.dep_context().sess().dcx().abort_if_errors(); unreachable!() } DelayBug => { diff --git a/compiler/rustc_query_system/src/values.rs b/compiler/rustc_query_system/src/values.rs index 8848fda9da3..4f1c182cdb8 100644 --- a/compiler/rustc_query_system/src/values.rs +++ b/compiler/rustc_query_system/src/values.rs @@ -9,7 +9,7 @@ pub trait Value: Sized { impl Value 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!( diff --git a/compiler/rustc_session/src/output.rs b/compiler/rustc_session/src/output.rs index bffebd705ba..db976b30404 100644 --- a/compiler/rustc_session/src/output.rs +++ b/compiler/rustc_session/src/output.rs @@ -115,7 +115,7 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option) { } if err_count > 0 { - sess.abort_if_errors(); + sess.dcx().abort_if_errors(); } } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index ec6e8684b29..53dd48ea272 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -279,7 +279,7 @@ impl Session { }); // 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 @@ impl Session { 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 { - self.dcx().has_errors() - } - pub fn has_errors_or_span_delayed_bugs(&self) -> Option { - self.dcx().has_errors_or_span_delayed_bugs() - } - pub fn is_compilation_going_to_fail(&self) -> Option { - 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 @@ impl Session { Ok(()) } } + // FIXME(matthewjasper) Remove this method, it should never be needed. pub fn track_errors(&self, f: F) -> Result 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( diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs index 2c427f51dee..4b84aae70fd 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs @@ -251,7 +251,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { 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 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // 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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, '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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, '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 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, '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!( diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 104afead64d..102a9f40e9b 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -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)) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index d33fdae4918..ad1838c53ad 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -690,7 +690,7 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>( tcx: TyCtxt<'tcx>, ) -> MainResult { match formats::run_format::(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)); diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 1811f245852..ad6a5a669f0 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -110,7 +110,7 @@ impl rustc_driver::Callbacks for MiriCompilerCalls { i32::try_from(return_code).expect("Return value was too large!"), ); } - tcx.sess.abort_if_errors(); + tcx.dcx().abort_if_errors(); }); Compilation::Stop diff --git a/tests/run-make-fulldeps/obtain-borrowck/driver.rs b/tests/run-make-fulldeps/obtain-borrowck/driver.rs index 9cbe9e5900a..2e3bf70e144 100644 --- a/tests/run-make-fulldeps/obtain-borrowck/driver.rs +++ b/tests/run-make-fulldeps/obtain-borrowck/driver.rs @@ -61,7 +61,7 @@ impl rustc_driver::Callbacks for CompilerCalls { 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(); -- cgit 1.4.1-3-g733a5