Skip to content

Commit dd5850b

Browse files
committed
UPDATE - accept start_point and snippet instead of SourceMap
1 parent 31e9f40 commit dd5850b

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) {
6767
span,
6868
reason,
6969
is_bytestr,
70-
source_map: sess.source_map(),
70+
start_point_span: sess.source_map().start_point(span),
7171
});
7272
}
7373
}

compiler/rustc_attr/src/session_diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::{
66
};
77
use rustc_macros::SessionDiagnostic;
88
use rustc_session::SessionDiagnostic;
9-
use rustc_span::{source_map::SourceMap, Span, Symbol};
9+
use rustc_span::{Span, Symbol};
1010

1111
use crate::UnsupportedLiteralReason;
1212

@@ -202,14 +202,14 @@ pub(crate) struct InvalidReprHintNoValue {
202202
}
203203

204204
// Error code: E0565
205-
pub(crate) struct UnsupportedLiteral<'a> {
205+
pub(crate) struct UnsupportedLiteral {
206206
pub span: Span,
207207
pub reason: UnsupportedLiteralReason,
208208
pub is_bytestr: bool,
209-
pub source_map: &'a SourceMap,
209+
pub start_point_span: Span,
210210
}
211211

212-
impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral<'a> {
212+
impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral {
213213
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
214214
let mut diag = handler.struct_span_err_with_code(
215215
self.span,
@@ -227,7 +227,7 @@ impl<'a> SessionDiagnostic<'a> for UnsupportedLiteral<'a> {
227227
);
228228
if self.is_bytestr {
229229
diag.span_suggestion(
230-
self.source_map.start_point(self.span),
230+
self.start_point_span,
231231
fluent::attr::unsupported_literal_suggestion,
232232
"",
233233
Applicability::MaybeIncorrect,

compiler/rustc_typeck/src/astconv/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2929
self.tcx().sess.emit_err(MissingTypeParams {
3030
span,
3131
def_span: self.tcx().def_span(def_id),
32-
source_map: self.tcx().sess.source_map(),
32+
span_snippet: self.tcx().sess.source_map().span_to_snippet(span).ok(),
3333
missing_type_params,
3434
empty_generic_args,
3535
});

compiler/rustc_typeck/src/errors.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed
33
use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
44
use rustc_middle::ty::Ty;
55
use rustc_session::SessionDiagnostic;
6-
use rustc_span::{source_map::SourceMap, symbol::Ident, Span, Symbol};
6+
use rustc_span::{symbol::Ident, Span, Symbol};
77

88
#[derive(SessionDiagnostic)]
99
#[diag(typeck::field_multiply_specified_in_initializer, code = "E0062")]
@@ -241,16 +241,16 @@ pub struct UnconstrainedOpaqueType {
241241
pub name: Symbol,
242242
}
243243

244-
pub struct MissingTypeParams<'a> {
244+
pub struct MissingTypeParams {
245245
pub span: Span,
246246
pub def_span: Span,
247+
pub span_snippet: Option<String>,
247248
pub missing_type_params: Vec<Symbol>,
248249
pub empty_generic_args: bool,
249-
pub source_map: &'a SourceMap,
250250
}
251251

252252
// Manual implementation of `SessionDiagnostic` to be able to call `span_to_snippet`.
253-
impl<'a> SessionDiagnostic<'a> for MissingTypeParams<'a> {
253+
impl<'a> SessionDiagnostic<'a> for MissingTypeParams {
254254
fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
255255
let mut err = handler.struct_span_err_with_code(
256256
self.span,
@@ -270,8 +270,8 @@ impl<'a> SessionDiagnostic<'a> for MissingTypeParams<'a> {
270270
err.span_label(self.def_span, rustc_errors::fluent::typeck::label);
271271

272272
let mut suggested = false;
273-
if let (Ok(snippet), true) = (
274-
self.source_map.span_to_snippet(self.span),
273+
if let (Some(snippet), true) = (
274+
self.span_snippet,
275275
// Don't suggest setting the type params if there are some already: the order is
276276
// tricky to get right and the user will already know what the syntax is.
277277
self.empty_generic_args,

0 commit comments

Comments
 (0)