@@ -10,6 +10,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
10
10
use rustc_errors:: Applicability ;
11
11
use rustc_hir as hir;
12
12
use rustc_hir:: def:: { DefKind , Res } ;
13
+ use rustc_hir:: def_id:: DefId ;
13
14
use rustc_hir:: hir_id:: CRATE_HIR_ID ;
14
15
use rustc_hir:: intravisit:: { NestedVisitorMap , Visitor } ;
15
16
use rustc_hir:: { Crate , Expr , ExprKind , HirId , Item , MutTy , Mutability , Node , Path , StmtKind , Ty , TyKind } ;
@@ -868,8 +869,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
868
869
869
870
#[ derive( Default ) ]
870
871
pub struct InterningDefinedSymbol {
871
- // Maps the symbol value to the constant name .
872
- symbol_map : FxHashMap < u32 , String > ,
872
+ // Maps the symbol value to the constant DefId .
873
+ symbol_map : FxHashMap < u32 , DefId > ,
873
874
}
874
875
875
876
impl_lint_pass ! ( InterningDefinedSymbol => [ INTERNING_DEFINED_SYMBOL ] ) ;
@@ -889,7 +890,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
889
890
if let Ok ( ConstValue :: Scalar ( value) ) = cx. tcx. const_eval_poly( item_def_id) ;
890
891
if let Ok ( value) = value. to_u32( ) ;
891
892
then {
892
- self . symbol_map. insert( value, item . ident . to_string ( ) ) ;
893
+ self . symbol_map. insert( value, item_def_id ) ;
893
894
}
894
895
}
895
896
}
@@ -903,15 +904,15 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
903
904
if match_def_path( cx, * def_id, & paths:: SYMBOL_INTERN ) ;
904
905
if let Some ( Constant :: Str ( arg) ) = constant_simple( cx, cx. typeck_results( ) , arg) ;
905
906
let value = Symbol :: intern( & arg) . as_u32( ) ;
906
- if let Some ( symbol_const ) = self . symbol_map. get( & value) ;
907
+ if let Some ( & def_id ) = self . symbol_map. get( & value) ;
907
908
then {
908
909
span_lint_and_sugg(
909
910
cx,
910
911
INTERNING_DEFINED_SYMBOL ,
911
912
is_expn_of( expr. span, "sym" ) . unwrap_or( expr. span) ,
912
913
"interning a defined symbol" ,
913
914
"try" ,
914
- format! ( "rustc_span::symbol::sym::{}" , symbol_const ) ,
915
+ cx . tcx . def_path_str ( def_id ) ,
915
916
Applicability :: MachineApplicable ,
916
917
) ;
917
918
}
0 commit comments