@@ -16,6 +16,7 @@ use rustc_mir_dataflow::fmt::DebugWithContext;
1616use rustc_mir_dataflow:: { Analysis , Backward , ResultsCursor } ;
1717use rustc_session:: lint;
1818use rustc_span:: Span ;
19+ use rustc_span:: symbol:: { Symbol , kw} ;
1920
2021use crate :: errors;
2122
@@ -162,7 +163,7 @@ fn is_capture(place: PlaceRef<'_>) -> bool {
162163/// interpolate our dead local.
163164fn maybe_suggest_literal_matching_name (
164165 body : & Body < ' _ > ,
165- name : & str ,
166+ name : Symbol ,
166167) -> Vec < errors:: UnusedVariableStringInterp > {
167168 struct LiteralFinder < ' body , ' tcx > {
168169 body : & ' body Body < ' tcx > ,
@@ -426,7 +427,7 @@ fn find_self_assignments<'tcx>(
426427#[ derive( Default , Debug ) ]
427428struct PlaceSet < ' tcx > {
428429 places : IndexVec < PlaceIndex , PlaceRef < ' tcx > > ,
429- names : IndexVec < PlaceIndex , Option < ( String , Span ) > > ,
430+ names : IndexVec < PlaceIndex , Option < ( Symbol , Span ) > > ,
430431
431432 /// Places corresponding to locals, common case.
432433 locals : IndexVec < Local , Option < PlaceIndex > > ,
@@ -488,7 +489,10 @@ impl<'tcx> PlaceSet<'tcx> {
488489
489490 // Record a variable name from the capture, because it is much friendlier than the
490491 // debuginfo name.
491- self . names . insert ( index, ( capture. to_string ( tcx) , capture. get_path_span ( tcx) ) ) ;
492+ self . names . insert (
493+ index,
494+ ( Symbol :: intern ( & capture. to_string ( tcx) ) , capture. get_path_span ( tcx) ) ,
495+ ) ;
492496 }
493497 }
494498
@@ -498,7 +502,7 @@ impl<'tcx> PlaceSet<'tcx> {
498502 && let Some ( index) = self . locals [ place. local ]
499503 {
500504 self . names . get_or_insert_with ( index, || {
501- ( var_debug_info. name . to_string ( ) , var_debug_info. source_info . span )
505+ ( var_debug_info. name , var_debug_info. source_info . span )
502506 } ) ;
503507 }
504508 }
@@ -790,8 +794,8 @@ impl AssignmentResult {
790794 continue ;
791795 }
792796
793- let Some ( ( ref name, def_span) ) = checked_places. names [ index] else { continue } ;
794- if name. is_empty ( ) || name. starts_with ( '_' ) || name == "self" {
797+ let Some ( ( name, def_span) ) = checked_places. names [ index] else { continue } ;
798+ if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw :: SelfLower {
795799 continue ;
796800 }
797801
@@ -818,19 +822,16 @@ impl AssignmentResult {
818822 let statements = & mut self . assignments [ index] ;
819823 if statements. is_empty ( ) {
820824 let sugg = if from_macro {
821- errors:: UnusedVariableSugg :: NoSugg { span : def_span, name : name . clone ( ) }
825+ errors:: UnusedVariableSugg :: NoSugg { span : def_span, name }
822826 } else {
823- errors:: UnusedVariableSugg :: TryPrefix {
824- spans : vec ! [ def_span] ,
825- name : name. clone ( ) ,
826- }
827+ errors:: UnusedVariableSugg :: TryPrefix { spans : vec ! [ def_span] , name }
827828 } ;
828829 tcx. emit_node_span_lint (
829830 lint:: builtin:: UNUSED_VARIABLES ,
830831 hir_id,
831832 def_span,
832833 errors:: UnusedVariable {
833- name : name . clone ( ) ,
834+ name,
834835 string_interp : maybe_suggest_literal_matching_name ( body, name) ,
835836 sugg,
836837 } ,
@@ -868,7 +869,7 @@ impl AssignmentResult {
868869 lint:: builtin:: UNUSED_VARIABLES ,
869870 hir_id,
870871 def_span,
871- errors:: UnusedVarAssignedOnly { name : name . clone ( ) } ,
872+ errors:: UnusedVarAssignedOnly { name } ,
872873 ) ;
873874 continue ;
874875 }
@@ -880,7 +881,7 @@ impl AssignmentResult {
880881
881882 let sugg = if any_shorthand {
882883 errors:: UnusedVariableSugg :: TryIgnore {
883- name : name . clone ( ) ,
884+ name,
884885 shorthands : introductions
885886 . iter ( )
886887 . filter_map (
@@ -897,19 +898,19 @@ impl AssignmentResult {
897898 . collect ( ) ,
898899 }
899900 } else if from_macro {
900- errors:: UnusedVariableSugg :: NoSugg { span : def_span, name : name . clone ( ) }
901+ errors:: UnusedVariableSugg :: NoSugg { span : def_span, name }
901902 } else if !introductions. is_empty ( ) {
902- errors:: UnusedVariableSugg :: TryPrefix { name : name . clone ( ) , spans : spans. clone ( ) }
903+ errors:: UnusedVariableSugg :: TryPrefix { name, spans : spans. clone ( ) }
903904 } else {
904- errors:: UnusedVariableSugg :: TryPrefix { name : name . clone ( ) , spans : vec ! [ def_span] }
905+ errors:: UnusedVariableSugg :: TryPrefix { name, spans : vec ! [ def_span] }
905906 } ;
906907
907908 tcx. emit_node_span_lint (
908909 lint:: builtin:: UNUSED_VARIABLES ,
909910 hir_id,
910911 spans,
911912 errors:: UnusedVariable {
912- name : name . clone ( ) ,
913+ name,
913914 string_interp : maybe_suggest_literal_matching_name ( body, name) ,
914915 sugg,
915916 } ,
@@ -931,8 +932,8 @@ impl AssignmentResult {
931932 continue ;
932933 }
933934
934- let Some ( ( ref name, decl_span) ) = checked_places. names [ index] else { continue } ;
935- if name. is_empty ( ) || name. starts_with ( '_' ) || name == "self" {
935+ let Some ( ( name, decl_span) ) = checked_places. names [ index] else { continue } ;
936+ if name. is_empty ( ) || name. as_str ( ) . starts_with ( '_' ) || name == kw :: SelfLower {
936937 continue ;
937938 }
938939
@@ -967,24 +968,20 @@ impl AssignmentResult {
967968 lint:: builtin:: UNUSED_ASSIGNMENTS ,
968969 hir_id,
969970 source_info. span ,
970- errors:: UnusedAssign {
971- name : name. clone ( ) ,
972- help : suggestion. is_none ( ) ,
973- suggestion,
974- } ,
971+ errors:: UnusedAssign { name, help : suggestion. is_none ( ) , suggestion } ,
975972 )
976973 }
977974 AccessKind :: Param => tcx. emit_node_span_lint (
978975 lint:: builtin:: UNUSED_ASSIGNMENTS ,
979976 hir_id,
980977 source_info. span ,
981- errors:: UnusedAssignPassed { name : name . clone ( ) } ,
978+ errors:: UnusedAssignPassed { name } ,
982979 ) ,
983980 AccessKind :: Capture => tcx. emit_node_span_lint (
984981 lint:: builtin:: UNUSED_ASSIGNMENTS ,
985982 hir_id,
986983 decl_span,
987- errors:: UnusedCaptureMaybeCaptureRef { name : name . clone ( ) } ,
984+ errors:: UnusedCaptureMaybeCaptureRef { name } ,
988985 ) ,
989986 }
990987 }
0 commit comments