]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/errors.rs
Rollup merge of #101828 - aDotInTheVoid:test-101743, r=jsha
[rust.git] / compiler / rustc_typeck / src / errors.rs
index 7b553a46e3b6c103135a8099b31769a5d19968c7..0d2e667458592caf68d1c49212e217ee8be9195d 100644 (file)
@@ -3,7 +3,7 @@
 use rustc_macros::{LintDiagnostic, SessionDiagnostic, SessionSubdiagnostic};
 use rustc_middle::ty::Ty;
 use rustc_session::SessionDiagnostic;
-use rustc_span::{symbol::Ident, Span, Symbol, source_map::SourceMap};
+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<String>,
     pub missing_type_params: Vec<Symbol>,
     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,12 +270,9 @@ fn into_diagnostic(self, handler: &'a Handler) -> DiagnosticBuilder<'a, ErrorGua
         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),
-            // 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,
-        ) {
+        // 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.
+        if let Some(snippet) = self.span_snippet && self.empty_generic_args {
             if snippet.ends_with('>') {
                 // The user wrote `Trait<'a, T>` or similar. To provide an accurate suggestion
                 // we would have to preserve the right order. For now, as clearly the user is