@@ -15,7 +15,7 @@ use rustc_mir_dataflow::fmt::DebugWithContext;
1515use rustc_mir_dataflow:: { Analysis , Backward , ResultsCursor } ;
1616use rustc_session:: lint;
1717use rustc_span:: Span ;
18- use rustc_span:: symbol:: sym;
18+ use rustc_span:: symbol:: { Symbol , kw , sym} ;
1919
2020use crate :: errors;
2121
@@ -162,7 +162,7 @@ fn is_capture(place: PlaceRef<'_>) -> bool {
162162/// interpolate our dead local.
163163fn maybe_suggest_literal_matching_name (
164164 body : & Body < ' _ > ,
165- name : & str ,
165+ name : Symbol ,
166166) -> Vec < errors:: UnusedVariableStringInterp > {
167167 struct LiteralFinder < ' body , ' tcx > {
168168 body : & ' body Body < ' tcx > ,
@@ -426,7 +426,7 @@ fn find_self_assignments<'tcx>(
426426#[ derive( Default , Debug ) ]
427427struct PlaceSet < ' tcx > {
428428 places : IndexVec < PlaceIndex , PlaceRef < ' tcx > > ,
429- names : IndexVec < PlaceIndex , Option < ( String , Span ) > > ,
429+ names : IndexVec < PlaceIndex , Option < ( Symbol , Span ) > > ,
430430
431431 /// Places corresponding to locals, common case.
432432 locals : IndexVec < Local , Option < PlaceIndex > > ,
@@ -488,7 +488,10 @@ impl<'tcx> PlaceSet<'tcx> {
488488
489489 // Record a variable name from the capture, because it is much friendlier than the
490490 // debuginfo name.
491- self . names . insert ( index, ( capture. to_string ( tcx) , capture. get_path_span ( tcx) ) ) ;
491+ self . names . insert (
492+ index,
493+ ( Symbol :: intern ( & capture. to_string ( tcx) ) , capture. get_path_span ( tcx) ) ,
494+ ) ;
492495 }
493496 }
494497
@@ -498,7 +501,7 @@ impl<'tcx> PlaceSet<'tcx> {
498501 && let Some ( index) = self . locals [ place. local ]
499502 {
500503 self . names . get_or_insert_with ( index, || {
501- ( var_debug_info. name . to_string ( ) , var_debug_info. source_info . span )
504+ ( var_debug_info. name , var_debug_info. source_info . span )
502505 } ) ;
503506 }
504507 }
@@ -790,8 +793,8 @@ impl AssignmentResult {
790793 continue ;
791794 }
792795
793- let Some ( ( ref name, def_span) ) = checked_places. names [ index] else { continue } ;
794- if name. is_empty ( ) || name. starts_with ( '_' ) || name == "self" {
796+ let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
797+ if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw :: SelfLower {
795798 continue ;
796799 }
797800
@@ -818,19 +821,16 @@ impl AssignmentResult {
818821 let statements = & mut self . assignments [ index] ;
819822 if statements. is_empty ( ) {
820823 let sugg = if from_macro {
821- errors:: UnusedVariableSugg :: NoSugg { span : def_span, name : name . clone ( ) }
824+ errors:: UnusedVariableSugg :: NoSugg { span : def_span, name }
822825 } else {
823- errors:: UnusedVariableSugg :: TryPrefix {
824- spans : vec ! [ def_span] ,
825- name : name. clone ( ) ,
826- }
826+ errors:: UnusedVariableSugg :: TryPrefix { spans : vec ! [ def_span] , name }
827827 } ;
828828 tcx. emit_node_span_lint (
829829 lint:: builtin:: UNUSED_VARIABLES ,
830830 hir_id,
831831 def_span,
832832 errors:: UnusedVariable {
833- name : name . clone ( ) ,
833+ name,
834834 string_interp : maybe_suggest_literal_matching_name ( body, name) ,
835835 sugg,
836836 } ,
@@ -868,7 +868,7 @@ impl AssignmentResult {
868868 lint:: builtin:: UNUSED_VARIABLES ,
869869 hir_id,
870870 def_span,
871- errors:: UnusedVarAssignedOnly { name : name . clone ( ) } ,
871+ errors:: UnusedVarAssignedOnly { name } ,
872872 ) ;
873873 continue ;
874874 }
@@ -880,7 +880,7 @@ impl AssignmentResult {
880880
881881 let sugg = if any_shorthand {
882882 errors:: UnusedVariableSugg :: TryIgnore {
883- name : name . clone ( ) ,
883+ name,
884884 shorthands : introductions
885885 . iter ( )
886886 . filter_map (
@@ -897,19 +897,19 @@ impl AssignmentResult {
897897 . collect ( ) ,
898898 }
899899 } else if from_macro {
900- errors:: UnusedVariableSugg :: NoSugg { span : def_span, name : name . clone ( ) }
900+ errors:: UnusedVariableSugg :: NoSugg { span : def_span, name }
901901 } else if !introductions. is_empty ( ) {
902- errors:: UnusedVariableSugg :: TryPrefix { name : name . clone ( ) , spans : spans. clone ( ) }
902+ errors:: UnusedVariableSugg :: TryPrefix { name, spans : spans. clone ( ) }
903903 } else {
904- errors:: UnusedVariableSugg :: TryPrefix { name : name . clone ( ) , spans : vec ! [ def_span] }
904+ errors:: UnusedVariableSugg :: TryPrefix { name, spans : vec ! [ def_span] }
905905 } ;
906906
907907 tcx. emit_node_span_lint (
908908 lint:: builtin:: UNUSED_VARIABLES ,
909909 hir_id,
910910 spans,
911911 errors:: UnusedVariable {
912- name : name . clone ( ) ,
912+ name,
913913 string_interp : maybe_suggest_literal_matching_name ( body, name) ,
914914 sugg,
915915 } ,
@@ -931,8 +931,8 @@ impl AssignmentResult {
931931 continue ;
932932 }
933933
934- let Some ( ( ref name, decl_span) ) = checked_places. names [ index] else { continue } ;
935- if name. is_empty ( ) || name. starts_with ( '_' ) || name == "self" {
934+ let Some ( ( name, decl_span) ) = checked_places. names [ index] else { continue } ;
935+ if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw :: SelfLower {
936936 continue ;
937937 }
938938
@@ -967,24 +967,20 @@ impl AssignmentResult {
967967 lint:: builtin:: UNUSED_ASSIGNMENTS ,
968968 hir_id,
969969 source_info. span ,
970- errors:: UnusedAssign {
971- name : name. clone ( ) ,
972- help : suggestion. is_none ( ) ,
973- suggestion,
974- } ,
970+ errors:: UnusedAssign { name, help : suggestion. is_none ( ) , suggestion } ,
975971 )
976972 }
977973 AccessKind :: Param => tcx. emit_node_span_lint (
978974 lint:: builtin:: UNUSED_ASSIGNMENTS ,
979975 hir_id,
980976 source_info. span ,
981- errors:: UnusedAssignPassed { name : name . clone ( ) } ,
977+ errors:: UnusedAssignPassed { name } ,
982978 ) ,
983979 AccessKind :: Capture => tcx. emit_node_span_lint (
984980 lint:: builtin:: UNUSED_ASSIGNMENTS ,
985981 hir_id,
986982 decl_span,
987- errors:: UnusedCaptureMaybeCaptureRef { name : name . clone ( ) } ,
983+ errors:: UnusedCaptureMaybeCaptureRef { name } ,
988984 ) ,
989985 }
990986 }
0 commit comments