@@ -15,6 +15,7 @@ use rustc_mir_dataflow::fmt::DebugWithContext;
15
15
use rustc_mir_dataflow:: { Analysis , Backward , ResultsCursor } ;
16
16
use rustc_session:: lint;
17
17
use rustc_span:: Span ;
18
+ use rustc_span:: symbol:: { Symbol , kw} ;
18
19
19
20
use crate :: errors;
20
21
@@ -161,7 +162,7 @@ fn is_capture(place: PlaceRef<'_>) -> bool {
161
162
/// interpolate our dead local.
162
163
fn maybe_suggest_literal_matching_name (
163
164
body : & Body < ' _ > ,
164
- name : & str ,
165
+ name : Symbol ,
165
166
) -> Vec < errors:: UnusedVariableStringInterp > {
166
167
struct LiteralFinder < ' body , ' tcx > {
167
168
body : & ' body Body < ' tcx > ,
@@ -425,7 +426,7 @@ fn find_self_assignments<'tcx>(
425
426
#[ derive( Default , Debug ) ]
426
427
struct PlaceSet < ' tcx > {
427
428
places : IndexVec < PlaceIndex , PlaceRef < ' tcx > > ,
428
- names : IndexVec < PlaceIndex , Option < ( String , Span ) > > ,
429
+ names : IndexVec < PlaceIndex , Option < ( Symbol , Span ) > > ,
429
430
430
431
/// Places corresponding to locals, common case.
431
432
locals : IndexVec < Local , Option < PlaceIndex > > ,
@@ -487,7 +488,10 @@ impl<'tcx> PlaceSet<'tcx> {
487
488
488
489
// Record a variable name from the capture, because it is much friendlier than the
489
490
// debuginfo name.
490
- 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
+ ) ;
491
495
}
492
496
}
493
497
@@ -497,7 +501,7 @@ impl<'tcx> PlaceSet<'tcx> {
497
501
&& let Some ( index) = self . locals [ place. local ]
498
502
{
499
503
self . names . get_or_insert_with ( index, || {
500
- ( var_debug_info. name . to_string ( ) , var_debug_info. source_info . span )
504
+ ( var_debug_info. name , var_debug_info. source_info . span )
501
505
} ) ;
502
506
}
503
507
}
@@ -789,8 +793,8 @@ impl AssignmentResult {
789
793
continue ;
790
794
}
791
795
792
- let Some ( ( ref name, def_span) ) = checked_places. names [ index] else { continue } ;
793
- 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 {
794
798
continue ;
795
799
}
796
800
@@ -817,19 +821,16 @@ impl AssignmentResult {
817
821
let statements = & mut self . assignments [ index] ;
818
822
if statements. is_empty ( ) {
819
823
let sugg = if from_macro {
820
- errors:: UnusedVariableSugg :: NoSugg { span : def_span, name : name . clone ( ) }
824
+ errors:: UnusedVariableSugg :: NoSugg { span : def_span, name }
821
825
} else {
822
- errors:: UnusedVariableSugg :: TryPrefix {
823
- spans : vec ! [ def_span] ,
824
- name : name. clone ( ) ,
825
- }
826
+ errors:: UnusedVariableSugg :: TryPrefix { spans : vec ! [ def_span] , name }
826
827
} ;
827
828
tcx. emit_node_span_lint (
828
829
lint:: builtin:: UNUSED_VARIABLES ,
829
830
hir_id,
830
831
def_span,
831
832
errors:: UnusedVariable {
832
- name : name . clone ( ) ,
833
+ name,
833
834
string_interp : maybe_suggest_literal_matching_name ( body, name) ,
834
835
sugg,
835
836
} ,
@@ -867,7 +868,7 @@ impl AssignmentResult {
867
868
lint:: builtin:: UNUSED_VARIABLES ,
868
869
hir_id,
869
870
def_span,
870
- errors:: UnusedVarAssignedOnly { name : name . clone ( ) } ,
871
+ errors:: UnusedVarAssignedOnly { name } ,
871
872
) ;
872
873
continue ;
873
874
}
@@ -879,7 +880,7 @@ impl AssignmentResult {
879
880
880
881
let sugg = if any_shorthand {
881
882
errors:: UnusedVariableSugg :: TryIgnore {
882
- name : name . clone ( ) ,
883
+ name,
883
884
shorthands : introductions
884
885
. iter ( )
885
886
. filter_map (
@@ -896,19 +897,19 @@ impl AssignmentResult {
896
897
. collect ( ) ,
897
898
}
898
899
} else if from_macro {
899
- errors:: UnusedVariableSugg :: NoSugg { span : def_span, name : name . clone ( ) }
900
+ errors:: UnusedVariableSugg :: NoSugg { span : def_span, name }
900
901
} else if !introductions. is_empty ( ) {
901
- errors:: UnusedVariableSugg :: TryPrefix { name : name . clone ( ) , spans : spans. clone ( ) }
902
+ errors:: UnusedVariableSugg :: TryPrefix { name, spans : spans. clone ( ) }
902
903
} else {
903
- errors:: UnusedVariableSugg :: TryPrefix { name : name . clone ( ) , spans : vec ! [ def_span] }
904
+ errors:: UnusedVariableSugg :: TryPrefix { name, spans : vec ! [ def_span] }
904
905
} ;
905
906
906
907
tcx. emit_node_span_lint (
907
908
lint:: builtin:: UNUSED_VARIABLES ,
908
909
hir_id,
909
910
spans,
910
911
errors:: UnusedVariable {
911
- name : name . clone ( ) ,
912
+ name,
912
913
string_interp : maybe_suggest_literal_matching_name ( body, name) ,
913
914
sugg,
914
915
} ,
@@ -930,8 +931,8 @@ impl AssignmentResult {
930
931
continue ;
931
932
}
932
933
933
- let Some ( ( ref name, decl_span) ) = checked_places. names [ index] else { continue } ;
934
- 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 {
935
936
continue ;
936
937
}
937
938
@@ -966,24 +967,20 @@ impl AssignmentResult {
966
967
lint:: builtin:: UNUSED_ASSIGNMENTS ,
967
968
hir_id,
968
969
source_info. span ,
969
- errors:: UnusedAssign {
970
- name : name. clone ( ) ,
971
- help : suggestion. is_none ( ) ,
972
- suggestion,
973
- } ,
970
+ errors:: UnusedAssign { name, help : suggestion. is_none ( ) , suggestion } ,
974
971
)
975
972
}
976
973
AccessKind :: Param => tcx. emit_node_span_lint (
977
974
lint:: builtin:: UNUSED_ASSIGNMENTS ,
978
975
hir_id,
979
976
source_info. span ,
980
- errors:: UnusedAssignPassed { name : name . clone ( ) } ,
977
+ errors:: UnusedAssignPassed { name } ,
981
978
) ,
982
979
AccessKind :: Capture => tcx. emit_node_span_lint (
983
980
lint:: builtin:: UNUSED_ASSIGNMENTS ,
984
981
hir_id,
985
982
decl_span,
986
- errors:: UnusedCaptureMaybeCaptureRef { name : name . clone ( ) } ,
983
+ errors:: UnusedCaptureMaybeCaptureRef { name } ,
987
984
) ,
988
985
}
989
986
}
0 commit comments