1- // This implements the dead-code warning pass. It follows middle ::reachable
1+ // This implements the dead-code warning pass. It follows crate ::reachable
22// closely. The idea is that all reachable symbols are live, codes called
33// from live codes are live, and everything else is dead.
44
@@ -814,13 +814,15 @@ impl<'tcx> DeadVisitor<'tcx> {
814814 }
815815 } ;
816816
817- for id in & dead_codes[ 1 ..] {
818- let hir = self . tcx . hir ( ) . local_def_id_to_hir_id ( * id) ;
819- let lint_level = self . tcx . lint_level_at_node ( lint:: builtin:: DEAD_CODE , hir) . 0 ;
820- if let Some ( expectation_id) = lint_level. get_expectation_id ( ) {
821- self . tcx . sess . diagnostic ( ) . insert_fulfilled_expectation ( expectation_id) ;
822- }
823- }
817+ // FIXME: Remove this before landing the PR.
818+ // Just keeping it around so that I remember how to get the expectation id.
819+ // for id in &dead_codes[1..] {
820+ // let hir = self.tcx.hir().local_def_id_to_hir_id(*id);
821+ // let lint_level = self.tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir).0;
822+ // if let Some(expectation_id) = lint_level.get_expectation_id() {
823+ // self.tcx.sess.diagnostic().insert_fulfilled_expectation(expectation_id);
824+ // }
825+ // }
824826 self . tcx . emit_spanned_lint (
825827 lint,
826828 tcx. hir ( ) . local_def_id_to_hir_id ( first_id) ,
@@ -829,7 +831,7 @@ impl<'tcx> DeadVisitor<'tcx> {
829831 ) ;
830832 }
831833
832- fn warn_dead_fields_and_variants (
834+ fn warn_dead_code_grouped_by_lint_level (
833835 & self ,
834836 def_id : LocalDefId ,
835837 participle : & str ,
@@ -903,13 +905,21 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
903905 for item in impl_item. items {
904906 let did = item. id . owner_id . def_id ;
905907 if !visitor. is_live_code ( did) {
906- dead_items. push ( did)
908+ let name = tcx. item_name ( def_id. to_def_id ( ) ) ;
909+ let hir = tcx. hir ( ) . local_def_id_to_hir_id ( did) ;
910+ let level = tcx. lint_level_at_node ( lint:: builtin:: DEAD_CODE , hir) . 0 ;
911+
912+ dead_items. push ( DeadVariant {
913+ def_id : did,
914+ name,
915+ level,
916+ } )
907917 }
908918 }
909- visitor. warn_multiple_dead_codes (
910- & dead_items ,
919+ visitor. warn_dead_code_grouped_by_lint_level (
920+ item . owner_id . def_id ,
911921 "used" ,
912- Some ( item . owner_id . def_id ) ,
922+ dead_items ,
913923 false ,
914924 ) ;
915925 }
@@ -966,10 +976,10 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
966976 }
967977 } )
968978 . collect ( ) ;
969- visitor. warn_dead_fields_and_variants ( def_id, "read" , dead_fields, is_positional)
979+ visitor. warn_dead_code_grouped_by_lint_level ( def_id, "read" , dead_fields, is_positional)
970980 }
971981
972- visitor. warn_dead_fields_and_variants (
982+ visitor. warn_dead_code_grouped_by_lint_level (
973983 item. owner_id . def_id ,
974984 "constructed" ,
975985 dead_variants,
0 commit comments