UPDATE - into_diagnostic to take a Handler instead of a 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 this is the best way to address this gap
This commit is contained in:
parent
a2cdcb3fea
commit
321e60bf34
14 changed files with 85 additions and 57 deletions
|
@ -1,9 +1,11 @@
|
|||
use std::num::IntErrorKind;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_errors::{error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||
use rustc_errors::{
|
||||
error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler,
|
||||
};
|
||||
use rustc_macros::SessionDiagnostic;
|
||||
use rustc_session::{parse::ParseSess, SessionDiagnostic};
|
||||
use rustc_session::SessionDiagnostic;
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
use crate::UnsupportedLiteralReason;
|
||||
|
@ -49,9 +51,9 @@ pub(crate) struct UnknownMetaItem<'a> {
|
|||
|
||||
// Manual implementation to be able to format `expected` items correctly.
|
||||
impl<'a> SessionDiagnostic<'a> for UnknownMetaItem<'_> {
|
||||
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
let expected = self.expected.iter().map(|name| format!("`{}`", name)).collect::<Vec<_>>();
|
||||
let mut diag = sess.span_diagnostic.struct_span_err_with_code(
|
||||
let mut diag = handler.struct_span_err_with_code(
|
||||
self.span,
|
||||
fluent::attr::unknown_meta_item,
|
||||
error_code!(E0541),
|
||||
|
@ -207,8 +209,8 @@ pub(crate) struct UnsupportedLiteral {
|
|||
}
|
||||
|
||||
impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral {
|
||||
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
let mut diag = sess.span_diagnostic.struct_span_err_with_code(
|
||||
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
let mut diag = handler.struct_span_err_with_code(
|
||||
self.span,
|
||||
match self.reason {
|
||||
UnsupportedLiteralReason::Generic => fluent::attr::unsupported_literal_generic,
|
||||
|
@ -223,8 +225,10 @@ impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral {
|
|||
error_code!(E0565),
|
||||
);
|
||||
if self.is_bytestr {
|
||||
let start_point = handler.span_start_point_from_emitter(self.span).unwrap_or(self.span);
|
||||
|
||||
diag.span_suggestion(
|
||||
sess.source_map().start_point(self.span),
|
||||
start_point,
|
||||
fluent::attr::unsupported_literal_suggestion,
|
||||
"",
|
||||
Applicability::MaybeIncorrect,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue