]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #99837 - TaKO8Ki:avoid-symbol-to-string-conversions, r=fee1-dead
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Thu, 28 Jul 2022 11:08:34 +0000 (16:38 +0530)
committerGitHub <noreply@github.com>
Thu, 28 Jul 2022 11:08:34 +0000 (16:38 +0530)
Avoid `Symbol` to `String` conversions

follow-up to #99508

compiler/rustc_expand/src/config.rs
compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

index 2b941ec68098a0a76836886948c110c09d4745b0..ccc29adc0153ee206a14d14fa03e1ffaf07af8ee 100644 (file)
@@ -129,7 +129,7 @@ fn active_features_up_to(edition: Edition) -> impl Iterator<Item = &'static Feat
                         .span_suggestion(
                             mi.span(),
                             "expected just one word",
-                            format!("{}", ident.name),
+                            ident.name,
                             Applicability::MaybeIncorrect,
                         )
                         .emit();
index 89d7c050c408bc757fbf9ef9d277f41e0c39fe60..6c8faed0df4867125b990be66441157b3d469339 100644 (file)
@@ -184,7 +184,7 @@ fn suggest_dereferences(
         trait_pred: ty::PolyTraitPredicate<'tcx>,
     ) -> bool;
 
-    fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String>;
+    fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<Symbol>;
 
     fn suggest_fn_call(
         &self,
@@ -737,13 +737,13 @@ fn suggest_dereferences(
     /// Given a closure's `DefId`, return the given name of the closure.
     ///
     /// This doesn't account for reassignments, but it's only used for suggestions.
-    fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<String> {
-        let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<String> {
+    fn get_closure_name(&self, def_id: DefId, err: &mut Diagnostic, msg: &str) -> Option<Symbol> {
+        let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<Symbol> {
             // Get the local name of this closure. This can be inaccurate because
             // of the possibility of reassignment, but this should be good enough.
             match &kind {
-                hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => {
-                    Some(format!("{}", name))
+                hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) => {
+                    Some(ident.name)
                 }
                 _ => {
                     err.note(msg);