Skip to content

Commit a9baa4a

Browse files
committed
Use Session::diagnostic in more places.
1 parent e97e75a commit a9baa4a

File tree

21 files changed

+51
-66
lines changed

21 files changed

+51
-66
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a> PostExpansionVisitor<'a> {
102102
}
103103
Err(abi::AbiDisabled::Unrecognized) => {
104104
if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) {
105-
self.sess.parse_sess.span_diagnostic.span_delayed_bug(
105+
self.sess.diagnostic().span_delayed_bug(
106106
span,
107107
format!(
108108
"unrecognized ABI not caught in lowering: {}",
@@ -627,7 +627,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
627627
if all_stable {
628628
err.sugg = Some(attr.span);
629629
}
630-
sess.parse_sess.span_diagnostic.emit_err(err);
630+
sess.diagnostic().emit_err(err);
631631
}
632632
}
633633
}

compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
945945
assert!(attr.has_name(sym::repr), "expected `#[repr(..)]`, found: {attr:?}");
946946
use ReprAttr::*;
947947
let mut acc = Vec::new();
948-
let diagnostic = &sess.parse_sess.span_diagnostic;
948+
let diagnostic = sess.diagnostic();
949949

950950
if let Some(items) = attr.meta_item_list() {
951951
for item in items {

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11351135
});
11361136
} else {
11371137
issued_spans.var_subdiag(
1138-
Some(&self.infcx.tcx.sess.parse_sess.span_diagnostic),
1138+
Some(self.infcx.tcx.sess.diagnostic()),
11391139
&mut err,
11401140
Some(issued_borrow.kind),
11411141
|kind, var_span| {
@@ -1152,7 +1152,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11521152
);
11531153

11541154
borrow_spans.var_subdiag(
1155-
Some(&self.infcx.tcx.sess.parse_sess.span_diagnostic),
1155+
Some(self.infcx.tcx.sess.diagnostic()),
11561156
&mut err,
11571157
Some(gen_borrow_kind),
11581158
|kind, var_span| {

compiler/rustc_borrowck/src/diagnostics/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
124124
let did = did.expect_local();
125125
if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) {
126126
diag.eager_subdiagnostic(
127-
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
127+
self.infcx.tcx.sess.diagnostic(),
128128
OnClosureNote::InvokedTwice {
129129
place_name: &ty::place_to_string_for_capture(
130130
self.infcx.tcx,
@@ -146,7 +146,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
146146
let did = did.expect_local();
147147
if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) {
148148
diag.eager_subdiagnostic(
149-
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
149+
self.infcx.tcx.sess.diagnostic(),
150150
OnClosureNote::MovedTwice {
151151
place_name: &ty::place_to_string_for_capture(self.infcx.tcx, hir_place),
152152
span: *span,
@@ -1119,7 +1119,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11191119
&& self.infcx.can_eq(self.param_env, ty, self_ty)
11201120
{
11211121
err.eager_subdiagnostic(
1122-
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
1122+
self.infcx.tcx.sess.diagnostic(),
11231123
CaptureReasonSuggest::FreshReborrow {
11241124
span: move_span.shrink_to_hi(),
11251125
},

compiler/rustc_builtin_macros/src/alloc_error_handler.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ pub fn expand(
3131
{
3232
(item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
3333
} else {
34-
ecx.sess
35-
.parse_sess
36-
.span_diagnostic
37-
.emit_err(errors::AllocErrorMustBeFn { span: item.span() });
34+
ecx.sess.diagnostic().emit_err(errors::AllocErrorMustBeFn { span: item.span() });
3835
return vec![orig_item];
3936
};
4037

compiler/rustc_builtin_macros/src/global_allocator.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ pub fn expand(
3434
{
3535
(item, true, ecx.with_def_site_ctxt(ty.span))
3636
} else {
37-
ecx.sess
38-
.parse_sess
39-
.span_diagnostic
40-
.emit_err(errors::AllocMustStatics { span: item.span() });
37+
ecx.sess.diagnostic().emit_err(errors::AllocMustStatics { span: item.span() });
4138
return vec![orig_item];
4239
};
4340

compiler/rustc_builtin_macros/src/test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ pub fn expand_test_or_bench(
389389
}
390390

391391
fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) {
392-
let diag = &cx.sess.parse_sess.span_diagnostic;
392+
let diag = cx.sess.diagnostic();
393393
let msg = "the `#[test]` attribute may only be used on a non-associated function";
394394
let mut err = match item.map(|i| &i.kind) {
395395
// These were a warning before #92959 and need to continue being that to avoid breaking
@@ -466,7 +466,7 @@ fn should_ignore_message(i: &ast::Item) -> Option<Symbol> {
466466
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
467467
match attr::find_by_name(&i.attrs, sym::should_panic) {
468468
Some(attr) => {
469-
let sd = &cx.sess.parse_sess.span_diagnostic;
469+
let sd = cx.sess.diagnostic();
470470

471471
match attr.meta_item_list() {
472472
// Handle #[should_panic(expected = "foo")]
@@ -535,7 +535,7 @@ fn check_test_signature(
535535
f: &ast::Fn,
536536
) -> Result<(), ErrorGuaranteed> {
537537
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
538-
let sd = &cx.sess.parse_sess.span_diagnostic;
538+
let sd = cx.sess.diagnostic();
539539

540540
if let ast::Unsafe::Yes(span) = f.sig.header.unsafety {
541541
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
@@ -579,7 +579,7 @@ fn check_bench_signature(
579579
// N.B., inadequate check, but we're running
580580
// well before resolve, can't get too deep.
581581
if f.sig.decl.inputs.len() != 1 {
582-
return Err(cx.sess.parse_sess.span_diagnostic.emit_err(errors::BenchSig { span: i.span }));
582+
return Err(cx.sess.diagnostic().emit_err(errors::BenchSig { span: i.span }));
583583
}
584584
Ok(())
585585
}

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub fn link_binary<'a>(
143143
}
144144
}
145145
if sess.opts.json_artifact_notifications {
146-
sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename, "link");
146+
sess.diagnostic().emit_artifact_notification(&out_filename, "link");
147147
}
148148

149149
if sess.prof.enabled() {

compiler/rustc_const_eval/src/const_eval/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ where
148148
let mut err = tcx.sess.create_err(err);
149149

150150
let msg = error.diagnostic_message();
151-
error.add_args(&tcx.sess.parse_sess.span_diagnostic, &mut err);
151+
error.add_args(tcx.sess.diagnostic(), &mut err);
152152

153153
// Use *our* span to label the interp error
154154
err.span_label(our_span, msg);

compiler/rustc_const_eval/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ pub trait ReportErrorExt {
437437
{
438438
ty::tls::with(move |tcx| {
439439
let mut builder = tcx.sess.struct_allow(DiagnosticMessage::Str(String::new().into()));
440-
let handler = &tcx.sess.parse_sess.span_diagnostic;
440+
let handler = tcx.sess.diagnostic();
441441
let message = self.diagnostic_message();
442442
self.add_args(handler, &mut builder);
443443
let s = handler.eagerly_translate_to_string(message, builder.args());

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
470470
backtrace.print_backtrace();
471471
// FIXME(fee1-dead), HACK: we want to use the error as title therefore we can just extract the
472472
// label and arguments from the InterpError.
473-
let handler = &self.tcx.sess.parse_sess.span_diagnostic;
473+
let handler = self.tcx.sess.diagnostic();
474474
#[allow(rustc::untranslatable_diagnostic)]
475475
let mut diag = self.tcx.sess.struct_allow("");
476476
let msg = e.diagnostic_message();

compiler/rustc_expand/src/base.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ impl<'a> ExtCtxt<'a> {
11191119
sp: S,
11201120
msg: impl Into<DiagnosticMessage>,
11211121
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
1122-
self.sess.parse_sess.span_diagnostic.struct_span_err(sp, msg)
1122+
self.sess.diagnostic().struct_span_err(sp, msg)
11231123
}
11241124

11251125
#[track_caller]
@@ -1143,15 +1143,15 @@ impl<'a> ExtCtxt<'a> {
11431143
#[rustc_lint_diagnostics]
11441144
#[track_caller]
11451145
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
1146-
self.sess.parse_sess.span_diagnostic.span_err(sp, msg);
1146+
self.sess.diagnostic().span_err(sp, msg);
11471147
}
11481148
#[rustc_lint_diagnostics]
11491149
#[track_caller]
11501150
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
1151-
self.sess.parse_sess.span_diagnostic.span_warn(sp, msg);
1151+
self.sess.diagnostic().span_warn(sp, msg);
11521152
}
11531153
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<String>) -> ! {
1154-
self.sess.parse_sess.span_diagnostic.span_bug(sp, msg);
1154+
self.sess.diagnostic().span_bug(sp, msg);
11551155
}
11561156
pub fn trace_macros_diag(&mut self) {
11571157
for (span, notes) in self.expansions.iter() {
@@ -1165,7 +1165,7 @@ impl<'a> ExtCtxt<'a> {
11651165
self.expansions.clear();
11661166
}
11671167
pub fn bug(&self, msg: &'static str) -> ! {
1168-
self.sess.parse_sess.span_diagnostic.bug(msg);
1168+
self.sess.diagnostic().bug(msg);
11691169
}
11701170
pub fn trace_macros(&self) -> bool {
11711171
self.ecfg.trace_mac
@@ -1286,9 +1286,8 @@ pub fn expr_to_string(
12861286

12871287
/// Non-fatally assert that `tts` is empty. Note that this function
12881288
/// returns even when `tts` is non-empty, macros that *need* to stop
1289-
/// compilation should call
1290-
/// `cx.parse_sess.span_diagnostic.abort_if_errors()` (this should be
1291-
/// done as rarely as possible).
1289+
/// compilation should call `cx.diagnostic().abort_if_errors()`
1290+
/// (this should be done as rarely as possible).
12921291
pub fn check_zero_tts(cx: &ExtCtxt<'_>, span: Span, tts: TokenStream, name: &str) {
12931292
if !tts.is_empty() {
12941293
cx.emit_err(errors::TakesNoArguments { span, name });

compiler/rustc_expand/src/mbe/macro_rules.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,14 @@ pub fn compile_declarative_macro(
475475

476476
let s = parse_failure_msg(&token);
477477
let sp = token.span.substitute_dummy(def.span);
478-
let mut err = sess.parse_sess.span_diagnostic.struct_span_err(sp, s);
478+
let mut err = sess.diagnostic().struct_span_err(sp, s);
479479
err.span_label(sp, msg);
480480
annotate_doc_comment(&mut err, sess.source_map(), sp);
481481
err.emit();
482482
return dummy_syn_ext();
483483
}
484484
Error(sp, msg) => {
485-
sess.parse_sess
486-
.span_diagnostic
487-
.struct_span_err(sp.substitute_dummy(def.span), msg)
488-
.emit();
485+
sess.diagnostic().struct_span_err(sp.substitute_dummy(def.span), msg).emit();
489486
return dummy_syn_ext();
490487
}
491488
ErrorReported(_) => {
@@ -514,10 +511,10 @@ pub fn compile_declarative_macro(
514511
valid &= check_lhs_nt_follows(&sess.parse_sess, def, &tt);
515512
return tt;
516513
}
517-
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs")
514+
sess.diagnostic().span_bug(def.span, "wrong-structured lhs")
518515
})
519516
.collect::<Vec<mbe::TokenTree>>(),
520-
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs"),
517+
_ => sess.diagnostic().span_bug(def.span, "wrong-structured lhs"),
521518
};
522519

523520
let rhses = match &argument_map[&MacroRulesNormalizedIdent::new(rhs_nm)] {
@@ -536,10 +533,10 @@ pub fn compile_declarative_macro(
536533
.pop()
537534
.unwrap();
538535
}
539-
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured rhs")
536+
sess.diagnostic().span_bug(def.span, "wrong-structured rhs")
540537
})
541538
.collect::<Vec<mbe::TokenTree>>(),
542-
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured rhs"),
539+
_ => sess.diagnostic().span_bug(def.span, "wrong-structured rhs"),
543540
};
544541

545542
for rhs in &rhses {
@@ -595,7 +592,7 @@ pub fn compile_declarative_macro(
595592
mbe::TokenTree::Delimited(_, delimited) => {
596593
mbe::macro_parser::compute_locs(&delimited.tts)
597594
}
598-
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "malformed macro lhs"),
595+
_ => sess.diagnostic().span_bug(def.span, "malformed macro lhs"),
599596
}
600597
})
601598
.collect()

compiler/rustc_expand/src/proc_macro.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl MultiItemModifier for DeriveProcMacro {
156156
}
157157
};
158158

159-
let error_count_before = ecx.sess.parse_sess.span_diagnostic.err_count();
159+
let error_count_before = ecx.sess.diagnostic().err_count();
160160
let mut parser =
161161
rustc_parse::stream_to_parser(&ecx.sess.parse_sess, stream, Some("proc-macro derive"));
162162
let mut items = vec![];
@@ -179,7 +179,7 @@ impl MultiItemModifier for DeriveProcMacro {
179179
}
180180

181181
// fail if there have been errors emitted
182-
if ecx.sess.parse_sess.span_diagnostic.err_count() > error_count_before {
182+
if ecx.sess.diagnostic().err_count() > error_count_before {
183183
ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span });
184184
}
185185

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl<'tcx> InferCtxt<'tcx> {
374374
multi_suggestions,
375375
bad_label,
376376
}
377-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
377+
.into_diagnostic(self.tcx.sess.diagnostic()),
378378
TypeAnnotationNeeded::E0283 => AmbiguousImpl {
379379
span,
380380
source_kind,
@@ -384,7 +384,7 @@ impl<'tcx> InferCtxt<'tcx> {
384384
multi_suggestions,
385385
bad_label,
386386
}
387-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
387+
.into_diagnostic(self.tcx.sess.diagnostic()),
388388
TypeAnnotationNeeded::E0284 => AmbiguousReturn {
389389
span,
390390
source_kind,
@@ -394,7 +394,7 @@ impl<'tcx> InferCtxt<'tcx> {
394394
multi_suggestions,
395395
bad_label,
396396
}
397-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
397+
.into_diagnostic(self.tcx.sess.diagnostic()),
398398
}
399399
}
400400
}
@@ -581,7 +581,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
581581
multi_suggestions,
582582
bad_label: None,
583583
}
584-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
584+
.into_diagnostic(self.tcx.sess.diagnostic()),
585585
TypeAnnotationNeeded::E0283 => AmbiguousImpl {
586586
span,
587587
source_kind,
@@ -591,7 +591,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
591591
multi_suggestions,
592592
bad_label: None,
593593
}
594-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
594+
.into_diagnostic(self.tcx.sess.diagnostic()),
595595
TypeAnnotationNeeded::E0284 => AmbiguousReturn {
596596
span,
597597
source_kind,
@@ -601,7 +601,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
601601
multi_suggestions,
602602
bad_label: None,
603603
}
604-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
604+
.into_diagnostic(self.tcx.sess.diagnostic()),
605605
}
606606
}
607607
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
140140
span,
141141
notes: reference_valid.into_iter().chain(content_valid).collect(),
142142
}
143-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
143+
.into_diagnostic(self.tcx.sess.diagnostic())
144144
}
145145
infer::RelateObjectBound(span) => {
146146
let object_valid = note_and_explain::RegionExplanation::new(
@@ -161,7 +161,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
161161
span,
162162
notes: object_valid.into_iter().chain(pointer_valid).collect(),
163163
}
164-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
164+
.into_diagnostic(self.tcx.sess.diagnostic())
165165
}
166166
infer::RelateParamBound(span, ty, opt_span) => {
167167
let prefix = match *sub {
@@ -177,7 +177,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
177177
self.tcx, sub, opt_span, prefix, suffix,
178178
);
179179
FulfillReqLifetime { span, ty: self.resolve_vars_if_possible(ty), note }
180-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
180+
.into_diagnostic(self.tcx.sess.diagnostic())
181181
}
182182
infer::RelateRegionParamBound(span) => {
183183
let param_instantiated = note_and_explain::RegionExplanation::new(
@@ -198,7 +198,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
198198
span,
199199
notes: param_instantiated.into_iter().chain(param_must_outlive).collect(),
200200
}
201-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
201+
.into_diagnostic(self.tcx.sess.diagnostic())
202202
}
203203
infer::ReferenceOutlivesReferent(ty, span) => {
204204
let pointer_valid = note_and_explain::RegionExplanation::new(
@@ -220,7 +220,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
220220
ty: self.resolve_vars_if_possible(ty),
221221
notes: pointer_valid.into_iter().chain(data_valid).collect(),
222222
}
223-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
223+
.into_diagnostic(self.tcx.sess.diagnostic())
224224
}
225225
infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => {
226226
let mut err = self.report_extra_impl_obligation(
@@ -281,7 +281,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
281281
span,
282282
notes: instantiated.into_iter().chain(must_outlive).collect(),
283283
}
284-
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
284+
.into_diagnostic(self.tcx.sess.diagnostic())
285285
}
286286
};
287287
if sub.is_error() || sup.is_error() {

0 commit comments

Comments
 (0)