1
- // This implements the dead-code warning pass. It follows middle ::reachable
1
+ // This implements the dead-code warning pass. It follows crate ::reachable
2
2
// closely. The idea is that all reachable symbols are live, codes called
3
3
// from live codes are live, and everything else is dead.
4
4
@@ -814,13 +814,15 @@ impl<'tcx> DeadVisitor<'tcx> {
814
814
}
815
815
} ;
816
816
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
+ // }
824
826
self . tcx . emit_spanned_lint (
825
827
lint,
826
828
tcx. hir ( ) . local_def_id_to_hir_id ( first_id) ,
@@ -829,7 +831,7 @@ impl<'tcx> DeadVisitor<'tcx> {
829
831
) ;
830
832
}
831
833
832
- fn warn_dead_fields_and_variants (
834
+ fn warn_dead_code_grouped_by_lint_level (
833
835
& self ,
834
836
def_id : LocalDefId ,
835
837
participle : & str ,
@@ -903,13 +905,21 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
903
905
for item in impl_item. items {
904
906
let did = item. id . owner_id . def_id ;
905
907
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
+ } )
907
917
}
908
918
}
909
- visitor. warn_multiple_dead_codes (
910
- & dead_items ,
919
+ visitor. warn_dead_code_grouped_by_lint_level (
920
+ item . owner_id . def_id ,
911
921
"used" ,
912
- Some ( item . owner_id . def_id ) ,
922
+ dead_items ,
913
923
false ,
914
924
) ;
915
925
}
@@ -966,10 +976,10 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
966
976
}
967
977
} )
968
978
. 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)
970
980
}
971
981
972
- visitor. warn_dead_fields_and_variants (
982
+ visitor. warn_dead_code_grouped_by_lint_level (
973
983
item. owner_id . def_id ,
974
984
"constructed" ,
975
985
dead_variants,
0 commit comments