Use `Session::diagnostic` in more places.

This commit is contained in:
Nicholas Nethercote 2023-12-01 13:35:19 +11:00
parent 6e9573936f
commit a179a53565
21 changed files with 51 additions and 66 deletions

View File

@ -102,7 +102,7 @@ impl<'a> PostExpansionVisitor<'a> {
}
Err(abi::AbiDisabled::Unrecognized) => {
if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) {
self.sess.parse_sess.span_diagnostic.span_delayed_bug(
self.sess.diagnostic().span_delayed_bug(
span,
format!(
"unrecognized ABI not caught in lowering: {}",
@ -628,7 +628,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
if all_stable {
err.sugg = Some(attr.span);
}
sess.parse_sess.span_diagnostic.emit_err(err);
sess.diagnostic().emit_err(err);
}
}
}

View File

@ -945,7 +945,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
assert!(attr.has_name(sym::repr), "expected `#[repr(..)]`, found: {attr:?}");
use ReprAttr::*;
let mut acc = Vec::new();
let diagnostic = &sess.parse_sess.span_diagnostic;
let diagnostic = sess.diagnostic();
if let Some(items) = attr.meta_item_list() {
for item in items {

View File

@ -1135,7 +1135,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
});
} else {
issued_spans.var_subdiag(
Some(&self.infcx.tcx.sess.parse_sess.span_diagnostic),
Some(self.infcx.tcx.sess.diagnostic()),
&mut err,
Some(issued_borrow.kind),
|kind, var_span| {
@ -1152,7 +1152,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
borrow_spans.var_subdiag(
Some(&self.infcx.tcx.sess.parse_sess.span_diagnostic),
Some(self.infcx.tcx.sess.diagnostic()),
&mut err,
Some(gen_borrow_kind),
|kind, var_span| {

View File

@ -124,7 +124,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let did = did.expect_local();
if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) {
diag.eager_subdiagnostic(
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
self.infcx.tcx.sess.diagnostic(),
OnClosureNote::InvokedTwice {
place_name: &ty::place_to_string_for_capture(
self.infcx.tcx,
@ -146,7 +146,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let did = did.expect_local();
if let Some((span, hir_place)) = self.infcx.tcx.closure_kind_origin(did) {
diag.eager_subdiagnostic(
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
self.infcx.tcx.sess.diagnostic(),
OnClosureNote::MovedTwice {
place_name: &ty::place_to_string_for_capture(self.infcx.tcx, hir_place),
span: *span,
@ -1119,7 +1119,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&& self.infcx.can_eq(self.param_env, ty, self_ty)
{
err.eager_subdiagnostic(
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
self.infcx.tcx.sess.diagnostic(),
CaptureReasonSuggest::FreshReborrow {
span: move_span.shrink_to_hi(),
},

View File

@ -31,10 +31,7 @@ pub fn expand(
{
(item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
} else {
ecx.sess
.parse_sess
.span_diagnostic
.emit_err(errors::AllocErrorMustBeFn { span: item.span() });
ecx.sess.diagnostic().emit_err(errors::AllocErrorMustBeFn { span: item.span() });
return vec![orig_item];
};

View File

@ -34,10 +34,7 @@ pub fn expand(
{
(item, true, ecx.with_def_site_ctxt(ty.span))
} else {
ecx.sess
.parse_sess
.span_diagnostic
.emit_err(errors::AllocMustStatics { span: item.span() });
ecx.sess.diagnostic().emit_err(errors::AllocMustStatics { span: item.span() });
return vec![orig_item];
};

View File

@ -389,7 +389,7 @@ pub fn expand_test_or_bench(
}
fn not_testable_error(cx: &ExtCtxt<'_>, attr_sp: Span, item: Option<&ast::Item>) {
let diag = &cx.sess.parse_sess.span_diagnostic;
let diag = cx.sess.diagnostic();
let msg = "the `#[test]` attribute may only be used on a non-associated function";
let mut err = match item.map(|i| &i.kind) {
// 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> {
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
match attr::find_by_name(&i.attrs, sym::should_panic) {
Some(attr) => {
let sd = &cx.sess.parse_sess.span_diagnostic;
let sd = cx.sess.diagnostic();
match attr.meta_item_list() {
// Handle #[should_panic(expected = "foo")]
@ -535,7 +535,7 @@ fn check_test_signature(
f: &ast::Fn,
) -> Result<(), ErrorGuaranteed> {
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
let sd = &cx.sess.parse_sess.span_diagnostic;
let sd = cx.sess.diagnostic();
if let ast::Unsafe::Yes(span) = f.sig.header.unsafety {
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
@ -579,7 +579,7 @@ fn check_bench_signature(
// N.B., inadequate check, but we're running
// well before resolve, can't get too deep.
if f.sig.decl.inputs.len() != 1 {
return Err(cx.sess.parse_sess.span_diagnostic.emit_err(errors::BenchSig { span: i.span }));
return Err(cx.sess.diagnostic().emit_err(errors::BenchSig { span: i.span }));
}
Ok(())
}

View File

@ -143,7 +143,7 @@ pub fn link_binary<'a>(
}
}
if sess.opts.json_artifact_notifications {
sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename, "link");
sess.diagnostic().emit_artifact_notification(&out_filename, "link");
}
if sess.prof.enabled() {

View File

@ -148,7 +148,7 @@ where
let mut err = tcx.sess.create_err(err);
let msg = error.diagnostic_message();
error.add_args(&tcx.sess.parse_sess.span_diagnostic, &mut err);
error.add_args(tcx.sess.diagnostic(), &mut err);
// Use *our* span to label the interp error
err.span_label(our_span, msg);

View File

@ -437,7 +437,7 @@ pub trait ReportErrorExt {
{
ty::tls::with(move |tcx| {
let mut builder = tcx.sess.struct_allow(DiagnosticMessage::Str(String::new().into()));
let handler = &tcx.sess.parse_sess.span_diagnostic;
let handler = tcx.sess.diagnostic();
let message = self.diagnostic_message();
self.add_args(handler, &mut builder);
let s = handler.eagerly_translate_to_string(message, builder.args());

View File

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

View File

@ -1119,7 +1119,7 @@ impl<'a> ExtCtxt<'a> {
sp: S,
msg: impl Into<DiagnosticMessage>,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
self.sess.parse_sess.span_diagnostic.struct_span_err(sp, msg)
self.sess.diagnostic().struct_span_err(sp, msg)
}
#[track_caller]
@ -1143,15 +1143,15 @@ impl<'a> ExtCtxt<'a> {
#[rustc_lint_diagnostics]
#[track_caller]
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
self.sess.parse_sess.span_diagnostic.span_err(sp, msg);
self.sess.diagnostic().span_err(sp, msg);
}
#[rustc_lint_diagnostics]
#[track_caller]
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
self.sess.parse_sess.span_diagnostic.span_warn(sp, msg);
self.sess.diagnostic().span_warn(sp, msg);
}
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<String>) -> ! {
self.sess.parse_sess.span_diagnostic.span_bug(sp, msg);
self.sess.diagnostic().span_bug(sp, msg);
}
pub fn trace_macros_diag(&mut self) {
for (span, notes) in self.expansions.iter() {
@ -1165,7 +1165,7 @@ impl<'a> ExtCtxt<'a> {
self.expansions.clear();
}
pub fn bug(&self, msg: &'static str) -> ! {
self.sess.parse_sess.span_diagnostic.bug(msg);
self.sess.diagnostic().bug(msg);
}
pub fn trace_macros(&self) -> bool {
self.ecfg.trace_mac
@ -1286,9 +1286,8 @@ pub fn expr_to_string(
/// Non-fatally assert that `tts` is empty. Note that this function
/// returns even when `tts` is non-empty, macros that *need* to stop
/// compilation should call
/// `cx.parse_sess.span_diagnostic.abort_if_errors()` (this should be
/// done as rarely as possible).
/// compilation should call `cx.diagnostic().abort_if_errors()`
/// (this should be done as rarely as possible).
pub fn check_zero_tts(cx: &ExtCtxt<'_>, span: Span, tts: TokenStream, name: &str) {
if !tts.is_empty() {
cx.emit_err(errors::TakesNoArguments { span, name });

View File

@ -475,17 +475,14 @@ pub fn compile_declarative_macro(
let s = parse_failure_msg(&token);
let sp = token.span.substitute_dummy(def.span);
let mut err = sess.parse_sess.span_diagnostic.struct_span_err(sp, s);
let mut err = sess.diagnostic().struct_span_err(sp, s);
err.span_label(sp, msg);
annotate_doc_comment(&mut err, sess.source_map(), sp);
err.emit();
return dummy_syn_ext();
}
Error(sp, msg) => {
sess.parse_sess
.span_diagnostic
.struct_span_err(sp.substitute_dummy(def.span), msg)
.emit();
sess.diagnostic().struct_span_err(sp.substitute_dummy(def.span), msg).emit();
return dummy_syn_ext();
}
ErrorReported(_) => {
@ -514,10 +511,10 @@ pub fn compile_declarative_macro(
valid &= check_lhs_nt_follows(&sess.parse_sess, def, &tt);
return tt;
}
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs")
sess.diagnostic().span_bug(def.span, "wrong-structured lhs")
})
.collect::<Vec<mbe::TokenTree>>(),
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured lhs"),
_ => sess.diagnostic().span_bug(def.span, "wrong-structured lhs"),
};
let rhses = match &argument_map[&MacroRulesNormalizedIdent::new(rhs_nm)] {
@ -536,10 +533,10 @@ pub fn compile_declarative_macro(
.pop()
.unwrap();
}
sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured rhs")
sess.diagnostic().span_bug(def.span, "wrong-structured rhs")
})
.collect::<Vec<mbe::TokenTree>>(),
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "wrong-structured rhs"),
_ => sess.diagnostic().span_bug(def.span, "wrong-structured rhs"),
};
for rhs in &rhses {
@ -595,7 +592,7 @@ pub fn compile_declarative_macro(
mbe::TokenTree::Delimited(_, delimited) => {
mbe::macro_parser::compute_locs(&delimited.tts)
}
_ => sess.parse_sess.span_diagnostic.span_bug(def.span, "malformed macro lhs"),
_ => sess.diagnostic().span_bug(def.span, "malformed macro lhs"),
}
})
.collect()

View File

@ -156,7 +156,7 @@ impl MultiItemModifier for DeriveProcMacro {
}
};
let error_count_before = ecx.sess.parse_sess.span_diagnostic.err_count();
let error_count_before = ecx.sess.diagnostic().err_count();
let mut parser =
rustc_parse::stream_to_parser(&ecx.sess.parse_sess, stream, Some("proc-macro derive"));
let mut items = vec![];
@ -179,7 +179,7 @@ impl MultiItemModifier for DeriveProcMacro {
}
// fail if there have been errors emitted
if ecx.sess.parse_sess.span_diagnostic.err_count() > error_count_before {
if ecx.sess.diagnostic().err_count() > error_count_before {
ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span });
}

View File

@ -374,7 +374,7 @@ impl<'tcx> InferCtxt<'tcx> {
multi_suggestions,
bad_label,
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
.into_diagnostic(self.tcx.sess.diagnostic()),
TypeAnnotationNeeded::E0283 => AmbiguousImpl {
span,
source_kind,
@ -384,7 +384,7 @@ impl<'tcx> InferCtxt<'tcx> {
multi_suggestions,
bad_label,
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
.into_diagnostic(self.tcx.sess.diagnostic()),
TypeAnnotationNeeded::E0284 => AmbiguousReturn {
span,
source_kind,
@ -394,7 +394,7 @@ impl<'tcx> InferCtxt<'tcx> {
multi_suggestions,
bad_label,
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
.into_diagnostic(self.tcx.sess.diagnostic()),
}
}
}
@ -581,7 +581,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
multi_suggestions,
bad_label: None,
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
.into_diagnostic(self.tcx.sess.diagnostic()),
TypeAnnotationNeeded::E0283 => AmbiguousImpl {
span,
source_kind,
@ -591,7 +591,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
multi_suggestions,
bad_label: None,
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
.into_diagnostic(self.tcx.sess.diagnostic()),
TypeAnnotationNeeded::E0284 => AmbiguousReturn {
span,
source_kind,
@ -601,7 +601,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
multi_suggestions,
bad_label: None,
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic),
.into_diagnostic(self.tcx.sess.diagnostic()),
}
}
}

View File

@ -140,7 +140,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span,
notes: reference_valid.into_iter().chain(content_valid).collect(),
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
.into_diagnostic(self.tcx.sess.diagnostic())
}
infer::RelateObjectBound(span) => {
let object_valid = note_and_explain::RegionExplanation::new(
@ -161,7 +161,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span,
notes: object_valid.into_iter().chain(pointer_valid).collect(),
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
.into_diagnostic(self.tcx.sess.diagnostic())
}
infer::RelateParamBound(span, ty, opt_span) => {
let prefix = match *sub {
@ -177,7 +177,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
self.tcx, sub, opt_span, prefix, suffix,
);
FulfillReqLifetime { span, ty: self.resolve_vars_if_possible(ty), note }
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
.into_diagnostic(self.tcx.sess.diagnostic())
}
infer::RelateRegionParamBound(span) => {
let param_instantiated = note_and_explain::RegionExplanation::new(
@ -198,7 +198,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span,
notes: param_instantiated.into_iter().chain(param_must_outlive).collect(),
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
.into_diagnostic(self.tcx.sess.diagnostic())
}
infer::ReferenceOutlivesReferent(ty, span) => {
let pointer_valid = note_and_explain::RegionExplanation::new(
@ -220,7 +220,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ty: self.resolve_vars_if_possible(ty),
notes: pointer_valid.into_iter().chain(data_valid).collect(),
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
.into_diagnostic(self.tcx.sess.diagnostic())
}
infer::CompareImplItemObligation { span, impl_item_def_id, trait_item_def_id } => {
let mut err = self.report_extra_impl_obligation(
@ -281,7 +281,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span,
notes: instantiated.into_iter().chain(must_outlive).collect(),
}
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
.into_diagnostic(self.tcx.sess.diagnostic())
}
};
if sub.is_error() || sup.is_error() {

View File

@ -519,9 +519,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
match result {
Ok(_) => {
if sess.opts.json_artifact_notifications {
sess.parse_sess
.span_diagnostic
.emit_artifact_notification(deps_filename, "dep-info");
sess.diagnostic().emit_artifact_notification(deps_filename, "dep-info");
}
}
Err(error) => {

View File

@ -267,7 +267,7 @@ impl CStore {
let unused_externs =
self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::<Vec<_>>();
let unused_externs = unused_externs.iter().map(String::as_str).collect::<Vec<&str>>();
tcx.sess.parse_sess.span_diagnostic.emit_unused_externs(
tcx.sess.diagnostic().emit_unused_externs(
level,
json_unused_externs.is_loud(),
&unused_externs,

View File

@ -91,10 +91,7 @@ pub fn encode_and_write_metadata(tcx: TyCtxt<'_>) -> (EncodedMetadata, bool) {
}
};
if tcx.sess.opts.json_artifact_notifications {
tcx.sess
.parse_sess
.span_diagnostic
.emit_artifact_notification(out_filename.as_path(), "metadata");
tcx.sess.diagnostic().emit_artifact_notification(out_filename.as_path(), "metadata");
}
(filename, None)
} else {

View File

@ -605,7 +605,7 @@ pub(crate) fn report_cycle<'a>(
note_span: (),
};
cycle_diag.into_diagnostic(&sess.parse_sess.span_diagnostic)
cycle_diag.into_diagnostic(sess.diagnostic())
}
pub fn print_query_stack<Qcx: QueryContext>(

View File

@ -302,7 +302,7 @@ impl Session {
if diags.is_empty() {
return;
}
self.parse_sess.span_diagnostic.emit_future_breakage_report(diags);
self.diagnostic().emit_future_breakage_report(diags);
}
/// Returns true if the crate is a testing one.