]> git.lizzy.rs Git - rust.git/commitdiff
avoid `&str`/`Symbol` to `String` conversions
authorTakayuki Maeda <takoyaki0316@gmail.com>
Mon, 25 Jul 2022 13:40:00 +0000 (22:40 +0900)
committerTakayuki Maeda <takoyaki0316@gmail.com>
Mon, 25 Jul 2022 13:40:00 +0000 (22:40 +0900)
compiler/rustc_borrowck/src/diagnostics/region_errors.rs
compiler/rustc_mir_build/src/thir/pattern/check_match.rs
compiler/rustc_resolve/src/diagnostics.rs
compiler/rustc_typeck/src/astconv/errors.rs
compiler/rustc_typeck/src/astconv/mod.rs
compiler/rustc_typeck/src/errors.rs

index 07aba50f03b996c40680ca6c9d3f7cc4751dd43b..1d66153734c782f36d0217ecf35e29615ff5379f 100644 (file)
@@ -850,13 +850,11 @@ fn suggest_constrain_dyn_trait_in_impl(
             debug!("trait spans found: {:?}", traits);
             for span in &traits {
                 let mut multi_span: MultiSpan = vec![*span].into();
-                multi_span.push_span_label(
-                    *span,
-                    "this has an implicit `'static` lifetime requirement".to_string(),
-                );
+                multi_span
+                    .push_span_label(*span, "this has an implicit `'static` lifetime requirement");
                 multi_span.push_span_label(
                     ident.span,
-                    "calling this method introduces the `impl`'s 'static` requirement".to_string(),
+                    "calling this method introduces the `impl`'s 'static` requirement",
                 );
                 err.span_note(multi_span, "the used `impl` has a `'static` requirement");
                 err.span_suggestion_verbose(
index 5bd1fad0bcb9f9cbbe1e9ec2edfff178451afd97..3435f127c72e2420306ef0895b5cdf9dbd7ee30a 100644 (file)
@@ -951,7 +951,7 @@ fn adt_defined_here<'p, 'tcx>(
         let mut span: MultiSpan =
             if spans.is_empty() { def_span.into() } else { spans.clone().into() };
 
-        span.push_span_label(def_span, String::new());
+        span.push_span_label(def_span, "");
         for pat in spans {
             span.push_span_label(pat, "not covered");
         }
index d74e26fc84498cf6c3bf997ccd68b558ad64a5ca..8a655cbf3845ad68a182ec1578b86f1e4a48cd1c 100644 (file)
@@ -565,8 +565,7 @@ pub(crate) fn into_struct_error(
                     } else if let Some(sp) = sm.generate_fn_name_span(span) {
                         err.span_label(
                             sp,
-                            "try adding a local generic parameter in this method instead"
-                                .to_string(),
+                            "try adding a local generic parameter in this method instead",
                         );
                     } else {
                         err.help("try using a local generic parameter instead");
index c873cf27e42c51cae416f53811b555344b85e679..99a8101dc96ba3b60239fc167345fed08b70ab67 100644 (file)
@@ -8,7 +8,7 @@
 use rustc_session::parse::feature_err;
 use rustc_span::lev_distance::find_best_match_for_name;
 use rustc_span::symbol::{sym, Ident};
-use rustc_span::{Span, DUMMY_SP};
+use rustc_span::{Span, Symbol, DUMMY_SP};
 
 use std::collections::BTreeSet;
 
@@ -17,7 +17,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
     /// the type parameter's name as a placeholder.
     pub(crate) fn complain_about_missing_type_params(
         &self,
-        missing_type_params: Vec<String>,
+        missing_type_params: Vec<Symbol>,
         def_id: DefId,
         span: Span,
         empty_generic_args: bool,
index 7111812f0b090aadb68bcf303225ace290c6ec3d..eacc9df8da7980efb872c82c7a6af20a2fe10ad2 100644 (file)
@@ -382,7 +382,7 @@ struct SubstsForAstPathCtxt<'a, 'tcx> {
             def_id: DefId,
             generic_args: &'a GenericArgs<'a>,
             span: Span,
-            missing_type_params: Vec<String>,
+            missing_type_params: Vec<Symbol>,
             inferred_params: Vec<Span>,
             infer_args: bool,
             is_object: bool,
@@ -514,7 +514,7 @@ fn inferred_kind(
                             // defaults. This will lead to an ICE if we are not
                             // careful!
                             if self.default_needs_object_self(param) {
-                                self.missing_type_params.push(param.name.to_string());
+                                self.missing_type_params.push(param.name);
                                 tcx.ty_error().into()
                             } else {
                                 // This is a default type parameter.
index 4cdec615d8290352067207817dc8dd95ddff0823..0438ac02ea91a75fed88aa5e83d42b617667afa2 100644 (file)
@@ -244,7 +244,7 @@ pub struct UnconstrainedOpaqueType {
 pub struct MissingTypeParams {
     pub span: Span,
     pub def_span: Span,
-    pub missing_type_params: Vec<String>,
+    pub missing_type_params: Vec<Symbol>,
     pub empty_generic_args: bool,
 }
 
@@ -285,7 +285,15 @@ fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuar
                 err.span_suggestion(
                     self.span,
                     rustc_errors::fluent::typeck::suggestion,
-                    format!("{}<{}>", snippet, self.missing_type_params.join(", ")),
+                    format!(
+                        "{}<{}>",
+                        snippet,
+                        self.missing_type_params
+                            .iter()
+                            .map(|n| n.to_string())
+                            .collect::<Vec<_>>()
+                            .join(", ")
+                    ),
                     Applicability::HasPlaceholders,
                 );
                 suggested = true;