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