@@ -10,6 +10,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010use rustc_errors:: Applicability ;
1111use rustc_hir as hir;
1212use rustc_hir:: def:: { DefKind , Res } ;
13+ use rustc_hir:: def_id:: DefId ;
1314use rustc_hir:: hir_id:: CRATE_HIR_ID ;
1415use rustc_hir:: intravisit:: { NestedVisitorMap , Visitor } ;
1516use rustc_hir:: { Crate , Expr , ExprKind , HirId , Item , MutTy , Mutability , Node , Path , StmtKind , Ty , TyKind } ;
@@ -868,8 +869,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidPaths {
868869
869870#[ derive( Default ) ]
870871pub 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 > ,
873874}
874875
875876impl_lint_pass ! ( InterningDefinedSymbol => [ INTERNING_DEFINED_SYMBOL ] ) ;
@@ -889,7 +890,7 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
889890 if let Ok ( ConstValue :: Scalar ( value) ) = cx. tcx. const_eval_poly( item_def_id) ;
890891 if let Ok ( value) = value. to_u32( ) ;
891892 then {
892- self . symbol_map. insert( value, item . ident . to_string ( ) ) ;
893+ self . symbol_map. insert( value, item_def_id ) ;
893894 }
894895 }
895896 }
@@ -903,15 +904,15 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
903904 if match_def_path( cx, * def_id, & paths:: SYMBOL_INTERN ) ;
904905 if let Some ( Constant :: Str ( arg) ) = constant_simple( cx, cx. typeck_results( ) , arg) ;
905906 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) ;
907908 then {
908909 span_lint_and_sugg(
909910 cx,
910911 INTERNING_DEFINED_SYMBOL ,
911912 is_expn_of( expr. span, "sym" ) . unwrap_or( expr. span) ,
912913 "interning a defined symbol" ,
913914 "try" ,
914- format! ( "rustc_span::symbol::sym::{}" , symbol_const ) ,
915+ cx . tcx . def_path_str ( def_id ) ,
915916 Applicability :: MachineApplicable ,
916917 ) ;
917918 }
0 commit comments