1
Fork 0

avoid Symbol to String conversions

This commit is contained in:
Takayuki Maeda 2022-07-28 10:20:55 +09:00
parent 3ae03e027a
commit 3cbc94427c
2 changed files with 6 additions and 6 deletions

View file

@ -129,7 +129,7 @@ fn get_features(
.span_suggestion( .span_suggestion(
mi.span(), mi.span(),
"expected just one word", "expected just one word",
format!("{}", ident.name), ident.name,
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
) )
.emit(); .emit();

View file

@ -184,7 +184,7 @@ pub trait InferCtxtExt<'tcx> {
trait_pred: ty::PolyTraitPredicate<'tcx>, trait_pred: ty::PolyTraitPredicate<'tcx>,
) -> bool; ) -> 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( fn suggest_fn_call(
&self, &self,
@ -737,13 +737,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
/// Given a closure's `DefId`, return the given name of the closure. /// 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. /// 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> { 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<String> { let get_name = |err: &mut Diagnostic, kind: &hir::PatKind<'_>| -> Option<Symbol> {
// Get the local name of this closure. This can be inaccurate because // Get the local name of this closure. This can be inaccurate because
// of the possibility of reassignment, but this should be good enough. // of the possibility of reassignment, but this should be good enough.
match &kind { match &kind {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, name, None) => { hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, _, ident, None) => {
Some(format!("{}", name)) Some(ident.name)
} }
_ => { _ => {
err.note(msg); err.note(msg);