Skip to content

Commit 8a9db25

Browse files
committed
Remove more Session methods that duplicate DiagCtxt methods.
1 parent 8af3d8d commit 8a9db25

File tree

36 files changed

+62
-74
lines changed

36 files changed

+62
-74
lines changed

compiler/rustc_builtin_macros/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ fn make_format_args(
529529

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

compiler/rustc_codegen_cranelift/src/driver/aot.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl OngoingCodegen {
108108

109109
self.concurrency_limiter.finished();
110110

111-
sess.abort_if_errors();
111+
sess.dcx().abort_if_errors();
112112

113113
(
114114
CodegenResults {

compiler/rustc_codegen_cranelift/src/driver/jit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
151151
tcx.dcx().fatal("Inline asm is not supported in JIT mode");
152152
}
153153

154-
tcx.sess.abort_if_errors();
154+
tcx.dcx().abort_if_errors();
155155

156156
jit_module.finalize_definitions().unwrap();
157157
unsafe { cx.unwind_context.register_jit(&jit_module) };
@@ -338,7 +338,7 @@ fn dep_symbol_lookup_fn(
338338
.collect::<Box<[_]>>(),
339339
);
340340

341-
sess.abort_if_errors();
341+
sess.dcx().abort_if_errors();
342342

343343
Box::new(move |sym_name| {
344344
for dylib in &*imported_dylibs {

compiler/rustc_codegen_cranelift/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
204204
metadata: EncodedMetadata,
205205
need_metadata_module: bool,
206206
) -> Box<dyn Any> {
207-
tcx.sess.abort_if_errors();
207+
tcx.dcx().abort_if_errors();
208208
let config = self.config.borrow().clone().unwrap();
209209
match config.codegen_mode {
210210
CodegenMode::Aot => driver::aot::run_aot(tcx, config, metadata, need_metadata_module),

compiler/rustc_codegen_ssa/src/back/link.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ fn link_dwarf_object<'a>(
716716
Ok(()) => {}
717717
Err(e) => {
718718
sess.dcx().emit_err(errors::ThorinErrorWrapper(e));
719-
sess.abort_if_errors();
719+
sess.dcx().abort_if_errors();
720720
}
721721
}
722722
}
@@ -765,7 +765,7 @@ fn link_natively<'a>(
765765
}
766766

767767
// May have not found libraries in the right formats.
768-
sess.abort_if_errors();
768+
sess.dcx().abort_if_errors();
769769

770770
// Invoke the system linker
771771
info!("{:?}", &cmd);
@@ -970,7 +970,7 @@ fn link_natively<'a>(
970970
}
971971
}
972972

973-
sess.abort_if_errors();
973+
sess.dcx().abort_if_errors();
974974
}
975975
info!("linker stderr:\n{}", escape_string(&prog.stderr));
976976
info!("linker stdout:\n{}", escape_string(&prog.stdout));
@@ -993,7 +993,7 @@ fn link_natively<'a>(
993993
sess.dcx().emit_note(errors::CheckInstalledVisualStudio);
994994
sess.dcx().emit_note(errors::InsufficientVSCodeProduct);
995995
}
996-
sess.abort_if_errors();
996+
sess.dcx().abort_if_errors();
997997
}
998998
}
999999

compiler/rustc_codegen_ssa/src/back/write.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,7 @@ impl SharedEmitterMain {
18831883
err.emit();
18841884
}
18851885
Ok(SharedEmitterMessage::AbortIfErrors) => {
1886-
sess.abort_if_errors();
1886+
sess.dcx().abort_if_errors();
18871887
}
18881888
Ok(SharedEmitterMessage::Fatal(msg)) => {
18891889
sess.dcx().fatal(msg);
@@ -1939,15 +1939,15 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
19391939
let compiled_modules = sess.time("join_worker_thread", || match self.coordinator.join() {
19401940
Ok(Ok(compiled_modules)) => compiled_modules,
19411941
Ok(Err(())) => {
1942-
sess.abort_if_errors();
1942+
sess.dcx().abort_if_errors();
19431943
panic!("expected abort due to worker thread errors")
19441944
}
19451945
Err(_) => {
19461946
bug!("panic during codegen/LLVM phase");
19471947
}
19481948
});
19491949

1950-
sess.abort_if_errors();
1950+
sess.dcx().abort_if_errors();
19511951

19521952
let work_products =
19531953
copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess, &compiled_modules);

compiler/rustc_codegen_ssa/src/base.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,9 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
448448
let Some(llfn) = cx.declare_c_main(llfty) else {
449449
// FIXME: We should be smart and show a better diagnostic here.
450450
let span = cx.tcx().def_span(rust_main_def_id);
451-
cx.sess().dcx().emit_err(errors::MultipleMainFunctions { span });
452-
cx.sess().abort_if_errors();
451+
let dcx = cx.tcx().dcx();
452+
dcx.emit_err(errors::MultipleMainFunctions { span });
453+
dcx.abort_if_errors();
453454
bug!();
454455
};
455456

@@ -752,7 +753,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
752753
// This will unwind if there are errors, which triggers our `AbortCodegenOnDrop`
753754
// guard. Unfortunately, just skipping the `submit_codegened_module_to_llvm` makes
754755
// compilation hang on post-monomorphization errors.
755-
tcx.sess.abort_if_errors();
756+
tcx.dcx().abort_if_errors();
756757

757758
submit_codegened_module_to_llvm(
758759
&backend,

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
279279
self.tcx.dcx().emit_diagnostic(error);
280280
}
281281
} else {
282-
assert!(self.tcx.sess.has_errors().is_some());
282+
assert!(self.tcx.dcx().has_errors().is_some());
283283
}
284284
}
285285

compiler/rustc_driver_impl/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ pub const DEFAULT_BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/issu
150150
pub fn abort_on_err<T>(result: Result<T, ErrorGuaranteed>, sess: &Session) -> T {
151151
match result {
152152
Err(..) => {
153-
sess.abort_if_errors();
153+
sess.dcx().abort_if_errors();
154154
panic!("error reported but abort_if_errors didn't abort???");
155155
}
156156
Ok(x) => x,

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ pub(super) fn check_type_params_are_used<'tcx>(
12841284
if ty.references_error() {
12851285
// If there is already another error, do not emit
12861286
// an error for not using a type parameter.
1287-
assert!(tcx.sess.has_errors().is_some());
1287+
assert!(tcx.dcx().has_errors().is_some());
12881288
return;
12891289
}
12901290

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ where
115115
let errors = wfcx.select_all_or_error();
116116
if !errors.is_empty() {
117117
let err = infcx.err_ctxt().report_fulfillment_errors(errors);
118-
if tcx.sess.err_count() > 0 {
118+
if tcx.dcx().err_count() > 0 {
119119
return Err(err);
120120
} else {
121121
// HACK(oli-obk): tests/ui/specialization/min_specialization/specialize_on_type_error.rs

compiler/rustc_hir_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
234234

235235
tcx.ensure().check_unused_traits(());
236236

237-
if let Some(reported) = tcx.sess.has_errors() { Err(reported) } else { Ok(()) }
237+
if let Some(reported) = tcx.dcx().has_errors() { Err(reported) } else { Ok(()) }
238238
}
239239

240240
/// A quasi-deprecated helper used in rustdoc and clippy to get

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
690690
// else an error would have been flagged by the
691691
// `loops` pass for using break with an expression
692692
// where you are not supposed to.
693-
assert!(expr_opt.is_none() || self.tcx.sess.has_errors().is_some());
693+
assert!(expr_opt.is_none() || self.dcx().has_errors().is_some());
694694
}
695695

696696
// If we encountered a `break`, then (no surprise) it may be possible to break from the

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
576576
// struct; however, when EUV is run during typeck, it
577577
// may not. This will generate an error earlier in typeck,
578578
// so we can just ignore it.
579-
if self.tcx().sess.has_errors().is_none() {
579+
if self.tcx().dcx().has_errors().is_none() {
580580
span_bug!(with_expr.span, "with expression doesn't evaluate to a struct");
581581
}
582582
}

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
119119
FnCtxt {
120120
body_id,
121121
param_env,
122-
err_count_on_creation: inh.tcx.sess.err_count(),
122+
err_count_on_creation: inh.tcx.dcx().err_count(),
123123
ret_coercion: None,
124124
ret_coercion_span: Cell::new(None),
125125
resume_yield_tys: None,
@@ -188,7 +188,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
188188
}
189189

190190
pub fn errors_reported_since_creation(&self) -> bool {
191-
self.tcx.sess.err_count() > self.err_count_on_creation
191+
self.dcx().err_count() > self.err_count_on_creation
192192
}
193193

194194
pub fn next_root_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {

compiler/rustc_hir_typeck/src/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
753753
}
754754

755755
fn report_error(&self, p: impl Into<ty::GenericArg<'tcx>>) -> ErrorGuaranteed {
756-
match self.fcx.tcx.sess.has_errors() {
756+
match self.fcx.dcx().has_errors() {
757757
Some(e) => e,
758758
None => self
759759
.fcx

compiler/rustc_incremental/src/persist/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
312312

313313
let incr_comp_session_dir: PathBuf = sess.incr_comp_session_dir().clone();
314314

315-
if let Some(_) = sess.has_errors_or_span_delayed_bugs() {
315+
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
316316
// If there have been any errors during compilation, we don't want to
317317
// publish this session directory. Rather, we'll just delete it.
318318

compiler/rustc_incremental/src/persist/save.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
3232
return;
3333
}
3434
// This is going to be deleted in finalize_session_directory, so let's not create it
35-
if let Some(_) = sess.has_errors_or_span_delayed_bugs() {
35+
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
3636
return;
3737
}
3838

@@ -87,7 +87,7 @@ pub fn save_work_product_index(
8787
return;
8888
}
8989
// This is going to be deleted in finalize_session_directory, so let's not create it
90-
if let Some(_) = sess.has_errors_or_span_delayed_bugs() {
90+
if let Some(_) = sess.dcx().has_errors_or_span_delayed_bugs() {
9191
return;
9292
}
9393

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub struct TypeErrCtxt<'a, 'tcx> {
133133

134134
impl Drop for TypeErrCtxt<'_, '_> {
135135
fn drop(&mut self) {
136-
if let Some(_) = self.infcx.tcx.sess.has_errors_or_span_delayed_bugs() {
136+
if let Some(_) = self.dcx().has_errors_or_span_delayed_bugs() {
137137
// ok, emitted an error.
138138
} else {
139139
self.infcx

compiler/rustc_infer/src/infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
704704
reported_trait_errors: Default::default(),
705705
reported_closure_mismatch: Default::default(),
706706
tainted_by_errors: Cell::new(None),
707-
err_count_on_creation: tcx.sess.err_count(),
707+
err_count_on_creation: tcx.dcx().err_count(),
708708
universe: Cell::new(ty::UniverseIndex::ROOT),
709709
intercrate,
710710
next_trait_solver,
@@ -1262,7 +1262,7 @@ impl<'tcx> InferCtxt<'tcx> {
12621262
debug!(
12631263
"is_tainted_by_errors(err_count={}, err_count_on_creation={}, \
12641264
tainted_by_errors={})",
1265-
self.tcx.sess.err_count(),
1265+
self.dcx().err_count(),
12661266
self.err_count_on_creation,
12671267
self.tainted_by_errors.get().is_some()
12681268
);
@@ -1271,9 +1271,9 @@ impl<'tcx> InferCtxt<'tcx> {
12711271
return Some(e);
12721272
}
12731273

1274-
if self.tcx.sess.err_count() > self.err_count_on_creation {
1274+
if self.dcx().err_count() > self.err_count_on_creation {
12751275
// errors reported since this infcx was made
1276-
let e = self.tcx.sess.has_errors().unwrap();
1276+
let e = self.dcx().has_errors().unwrap();
12771277
self.set_tainted_by_errors(e);
12781278
return Some(e);
12791279
}

compiler/rustc_interface/src/passes.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn configure_and_expand(
216216
// If we hit a recursion limit, exit early to avoid later passes getting overwhelmed
217217
// with a large AST
218218
if ecx.reduced_recursion_limit.is_some() {
219-
sess.abort_if_errors();
219+
sess.dcx().abort_if_errors();
220220
unreachable!();
221221
}
222222

@@ -776,7 +776,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
776776
// lot of annoying errors in the ui tests (basically,
777777
// lint warnings and so on -- kindck used to do this abort, but
778778
// kindck is gone now). -nmatsakis
779-
if let Some(reported) = sess.has_errors() {
779+
if let Some(reported) = sess.dcx().has_errors() {
780780
return Err(reported);
781781
}
782782

@@ -937,8 +937,9 @@ pub fn start_codegen<'tcx>(
937937

938938
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
939939
if let Err(error) = rustc_mir_transform::dump_mir::emit_mir(tcx) {
940-
tcx.dcx().emit_err(errors::CantEmitMIR { error });
941-
tcx.sess.abort_if_errors();
940+
let dcx = tcx.dcx();
941+
dcx.emit_err(errors::CantEmitMIR { error });
942+
dcx.abort_if_errors();
942943
}
943944
}
944945

compiler/rustc_metadata/src/creader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> {
925925
// don't perform this validation if the session has errors, as one of
926926
// those errors may indicate a circular dependency which could cause
927927
// this to stack overflow.
928-
if self.sess.has_errors().is_some() {
928+
if self.dcx().has_errors().is_some() {
929929
return;
930930
}
931931

compiler/rustc_middle/src/ty/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
5555
}
5656
fn error_reported(&self) -> Result<(), ErrorGuaranteed> {
5757
if self.references_error() {
58-
if let Some(reported) = ty::tls::with(|tcx| tcx.sess.is_compilation_going_to_fail()) {
58+
if let Some(reported) = ty::tls::with(|tcx| tcx.dcx().is_compilation_going_to_fail()) {
5959
Err(reported)
6060
} else {
6161
bug!("expect tcx.sess.is_compilation_going_to_fail return `Some`");

compiler/rustc_middle/src/values.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> Value<TyCtxt<'tcx>> for ty::Binder<'_, ty::FnSig<'_>> {
5151
{
5252
sig.decl.inputs.len() + sig.decl.implicit_self.has_implicit_self() as usize
5353
} else {
54-
tcx.sess.abort_if_errors();
54+
tcx.dcx().abort_if_errors();
5555
unreachable!()
5656
};
5757

compiler/rustc_monomorphize/src/partitioning.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
11101110

11111111
let (items, usage_map) = collector::collect_crate_mono_items(tcx, collection_mode);
11121112

1113-
tcx.sess.abort_if_errors();
1113+
tcx.dcx().abort_if_errors();
11141114

11151115
let (codegen_units, _) = tcx.sess.time("partition_and_assert_distinct_symbols", || {
11161116
sync::join(

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,7 @@ fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
25792579
check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs());
25802580
}
25812581
if check_attr_visitor.abort.get() {
2582-
tcx.sess.abort_if_errors()
2582+
tcx.dcx().abort_if_errors()
25832583
}
25842584
}
25852585

compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ impl<D: Deps> DepGraphData<D> {
818818
None => {}
819819
}
820820

821-
if let None = qcx.dep_context().sess().has_errors_or_span_delayed_bugs() {
821+
if let None = qcx.dep_context().sess().dcx().has_errors_or_span_delayed_bugs() {
822822
panic!("try_mark_previous_green() - Forcing the DepNode should have set its color")
823823
}
824824

compiler/rustc_query_system/src/query/plumbing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ where
126126
}
127127
Fatal => {
128128
error.emit();
129-
qcx.dep_context().sess().abort_if_errors();
129+
qcx.dep_context().sess().dcx().abort_if_errors();
130130
unreachable!()
131131
}
132132
DelayBug => {

compiler/rustc_query_system/src/values.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub trait Value<Tcx: DepContext>: Sized {
99

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

compiler/rustc_session/src/output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn validate_crate_name(sess: &Session, s: Symbol, sp: Option<Span>) {
115115
}
116116

117117
if err_count > 0 {
118-
sess.abort_if_errors();
118+
sess.dcx().abort_if_errors();
119119
}
120120
}
121121

0 commit comments

Comments
 (0)