1
Fork 0

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

@ -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 });
}