@@ -1627,6 +1627,69 @@ impl LintPass for MissingCopyImplementations {
1627
1627
}
1628
1628
}
1629
1629
1630
+ declare_lint ! {
1631
+ MISSING_DEBUG_IMPLEMENTATIONS ,
1632
+ Allow ,
1633
+ "detects missing implementations of fmt::Debug"
1634
+ }
1635
+
1636
+ pub struct MissingDebugImplementations {
1637
+ impling_types : Option < NodeSet > ,
1638
+ }
1639
+
1640
+ impl MissingDebugImplementations {
1641
+ pub fn new ( ) -> MissingDebugImplementations {
1642
+ MissingDebugImplementations {
1643
+ impling_types : None ,
1644
+ }
1645
+ }
1646
+ }
1647
+
1648
+ impl LintPass for MissingDebugImplementations {
1649
+ fn get_lints ( & self ) -> LintArray {
1650
+ lint_array ! ( MISSING_DEBUG_IMPLEMENTATIONS )
1651
+ }
1652
+
1653
+ fn check_item ( & mut self , cx : & Context , item : & ast:: Item ) {
1654
+ if !cx. exported_items . contains ( & item. id ) {
1655
+ return ;
1656
+ }
1657
+
1658
+ match item. node {
1659
+ ast:: ItemStruct ( ..) | ast:: ItemEnum ( ..) => { } ,
1660
+ _ => return ,
1661
+ }
1662
+
1663
+ let debug = match cx. tcx . lang_items . debug_trait ( ) {
1664
+ Some ( debug) => debug,
1665
+ None => return ,
1666
+ } ;
1667
+
1668
+ if self . impling_types . is_none ( ) {
1669
+ let impls = cx. tcx . trait_impls . borrow ( ) ;
1670
+ let impls = match impls. get ( & debug) {
1671
+ Some ( impls) => {
1672
+ impls. borrow ( ) . iter ( )
1673
+ . filter ( |d| d. krate == ast:: LOCAL_CRATE )
1674
+ . filter_map ( |d| ty:: ty_to_def_id ( ty:: node_id_to_type ( cx. tcx , d. node ) ) )
1675
+ . map ( |d| d. node )
1676
+ . collect ( )
1677
+ }
1678
+ None => NodeSet ( ) ,
1679
+ } ;
1680
+ self . impling_types = Some ( impls) ;
1681
+ debug ! ( "{:?}" , self . impling_types) ;
1682
+ }
1683
+
1684
+ if !self . impling_types . as_ref ( ) . unwrap ( ) . contains ( & item. id ) {
1685
+ cx. span_lint ( MISSING_DEBUG_IMPLEMENTATIONS ,
1686
+ item. span ,
1687
+ "type does not implement `fmt::Debug`; consider adding #[derive(Debug)] \
1688
+ or a manual implementation")
1689
+ }
1690
+ }
1691
+ }
1692
+
1630
1693
declare_lint ! {
1631
1694
DEPRECATED ,
1632
1695
Warn ,
0 commit comments