]> git.lizzy.rs Git - rust.git/commitdiff
avoid `&str` to String conversions
authorTakayuki Maeda <takoyaki0316@gmail.com>
Wed, 20 Jul 2022 09:19:57 +0000 (18:19 +0900)
committerTakayuki Maeda <takoyaki0316@gmail.com>
Wed, 20 Jul 2022 09:19:57 +0000 (18:19 +0900)
compiler/rustc_errors/src/diagnostic.rs
compiler/rustc_resolve/src/diagnostics.rs

index 7d7f3e1833576c080318f6eba2ba6abed9290aa7..ba888d77b15c1644708d9e82c13dd49833d594fb 100644 (file)
@@ -390,18 +390,17 @@ pub fn note_unsuccessful_coercion(
         expected: DiagnosticStyledString,
         found: DiagnosticStyledString,
     ) -> &mut Self {
-        let mut msg: Vec<_> =
-            vec![("required when trying to coerce from type `".to_string(), Style::NoStyle)];
+        let mut msg: Vec<_> = vec![("required when trying to coerce from type `", Style::NoStyle)];
         msg.extend(expected.0.iter().map(|x| match *x {
-            StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
-            StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
+            StringPart::Normal(ref s) => (s.as_str(), Style::NoStyle),
+            StringPart::Highlighted(ref s) => (s.as_str(), Style::Highlight),
         }));
-        msg.push(("` to type '".to_string(), Style::NoStyle));
+        msg.push(("` to type '", Style::NoStyle));
         msg.extend(found.0.iter().map(|x| match *x {
-            StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
-            StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
+            StringPart::Normal(ref s) => (s.as_str(), Style::NoStyle),
+            StringPart::Highlighted(ref s) => (s.as_str(), Style::Highlight),
         }));
-        msg.push(("`".to_string(), Style::NoStyle));
+        msg.push(("`", Style::NoStyle));
 
         // For now, just attach these as notes
         self.highlighted_note(msg);
index 7a1695fc862bf603daa67504d882366b225b79f5..df13136dcce37c42a7649ebac92eddbe3562c4fa 100644 (file)
@@ -2603,9 +2603,9 @@ fn show_candidates(
                 .skip(1)
                 .all(|(_, descr, _, _)| descr == descr_first)
             {
-                descr_first.to_string()
+                descr_first
             } else {
-                "item".to_string()
+                "item"
             };
             let plural_descr =
                 if descr.ends_with("s") { format!("{}es", descr) } else { format!("{}s", descr) };