From dd5850b8faf04e1b98542cf0813920385a6cc4db Mon Sep 17 00:00:00 2001 From: Jhonny Bill Mena Date: Mon, 5 Sep 2022 17:26:57 -0400 Subject: [PATCH] UPDATE - accept start_point and snippet instead of SourceMap --- compiler/rustc_attr/src/builtin.rs | 2 +- compiler/rustc_attr/src/session_diagnostics.rs | 10 +++++----- compiler/rustc_typeck/src/astconv/errors.rs | 2 +- compiler/rustc_typeck/src/errors.rs | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_attr/src/builtin.rs b/compiler/rustc_attr/src/builtin.rs index 2c3fc4d9fe6..e1404ab15ef 100644 --- a/compiler/rustc_attr/src/builtin.rs +++ b/compiler/rustc_attr/src/builtin.rs @@ -67,7 +67,7 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) { span, reason, is_bytestr, - source_map: sess.source_map(), + start_point_span: sess.source_map().start_point(span), }); } } diff --git a/compiler/rustc_attr/src/session_diagnostics.rs b/compiler/rustc_attr/src/session_diagnostics.rs index b8942e51306..085175d4bed 100644 --- a/compiler/rustc_attr/src/session_diagnostics.rs +++ b/compiler/rustc_attr/src/session_diagnostics.rs @@ -6,7 +6,7 @@ use rustc_errors::{ }; use rustc_macros::SessionDiagnostic; use rustc_session::SessionDiagnostic; -use rustc_span::{source_map::SourceMap, Span, Symbol}; +use rustc_span::{Span, Symbol}; use crate::UnsupportedLiteralReason; @@ -202,14 +202,14 @@ pub(crate) struct InvalidReprHintNoValue { } // Error code: E0565 -pub(crate) struct UnsupportedLiteral<'a> { +pub(crate) struct UnsupportedLiteral { pub span: Span, pub reason: UnsupportedLiteralReason, pub is_bytestr: bool, - pub source_map: &'a SourceMap, + pub start_point_span: Span, } -impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral<'a> { +impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let mut diag = handler.struct_span_err_with_code( self.span, @@ -227,7 +227,7 @@ impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral<'a> { ); if self.is_bytestr { diag.span_suggestion( - self.source_map.start_point(self.span), + self.start_point_span, fluent::attr::unsupported_literal_suggestion, "", Applicability::MaybeIncorrect, diff --git a/compiler/rustc_typeck/src/astconv/errors.rs b/compiler/rustc_typeck/src/astconv/errors.rs index 1262dd7dcc7..a9152bdc597 100644 --- a/compiler/rustc_typeck/src/astconv/errors.rs +++ b/compiler/rustc_typeck/src/astconv/errors.rs @@ -29,7 +29,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.tcx().sess.emit_err(MissingTypeParams { span, def_span: self.tcx().def_span(def_id), - source_map: self.tcx().sess.source_map(), + span_snippet: self.tcx().sess.source_map().span_to_snippet(span).ok(), missing_type_params, empty_generic_args, }); diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index ae6f8d2a51c..d280fa5156b 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -3,7 +3,7 @@ use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic}; use rustc_middle::ty::Ty; use rustc_session::SessionDiagnostic; -use rustc_span::{source_map::SourceMap, symbol::Ident, Span, Symbol}; +use rustc_span::{symbol::Ident, Span, Symbol}; #[derive(SessionDiagnostic)] #[diag(typeck::field_multiply_specified_in_initializer, code = "E0062")] @@ -241,16 +241,16 @@ pub struct UnconstrainedOpaqueType { pub name: Symbol, } -pub struct MissingTypeParams<'a> { +pub struct MissingTypeParams { pub span: Span, pub def_span: Span, + pub span_snippet: Option, pub missing_type_params: Vec, pub empty_generic_args: bool, - pub source_map: &'a SourceMap, } // Manual implementation of `SessionDiagnostic` to be able to call `span_to_snippet`. -impl<'a> SessionDiagnostic<'a> for MissingTypeParams<'a> { +impl<'a> SessionDiagnostic<'a> for MissingTypeParams { fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> { let mut err = handler.struct_span_err_with_code( self.span, @@ -270,8 +270,8 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams<'a> { err.span_label(self.def_span, rustc_errors::fluent::typeck::label); let mut suggested = false; - if let (Ok(snippet), true) = ( - self.source_map.span_to_snippet(self.span), + if let (Some(snippet), true) = ( + self.span_snippet, // Don't suggest setting the type params if there are some already: the order is // tricky to get right and the user will already know what the syntax is. self.empty_generic_args,