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