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