1
Fork 0

Rollup merge of #101434 - JhonnyBillM:replace-session-for-handler-in-into-diagnostic, r=davidtwco

Update `SessionDiagnostic::into_diagnostic` to take `Handler` instead of `ParseSess`

Suggested by the team in [this Zulip Topic](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20SessionDiagnostic.20on.20Handler).

`Handler` already has almost all the capabilities of `ParseSess` when it comes to diagnostic emission, in this migration we only needed to add the ability to access `source_map` from the emitter in order to get a `Snippet` and the `start_point`. Not sure if adding these two methods [`span_to_snippet_from_emitter` and  `span_start_point_from_emitter`] is the best way to address this gap.

P.S. If this goes in the right direction, then we probably may want to move `SessionDiagnostic` to `rustc_errors` and rename it to `DiagnosticHandler` or something similar.

r? `@davidtwco`
r? `@compiler-errors`
This commit is contained in:
Guillaume Gomez 2022-09-06 17:00:26 +02:00 committed by GitHub
commit 4d830b7775
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 86 additions and 75 deletions

View file

@ -47,9 +47,10 @@ pub struct UnusedGenericParams {
impl SessionDiagnostic<'_> for UnusedGenericParams {
fn into_diagnostic(
self,
sess: &'_ rustc_session::parse::ParseSess,
handler: &'_ rustc_errors::Handler,
) -> rustc_errors::DiagnosticBuilder<'_, ErrorGuaranteed> {
let mut diag = sess.struct_err(rustc_errors::fluent::monomorphize::unused_generic_params);
let mut diag =
handler.struct_err(rustc_errors::fluent::monomorphize::unused_generic_params);
diag.set_span(self.span);
for (span, name) in self.param_spans.into_iter().zip(self.param_names) {
// FIXME: I can figure out how to do a label with a fluent string with a fixed message,