@@ -19,10 +19,14 @@ pub(super) fn check(
19
19
) {
20
20
if_chain ! {
21
21
if is_type_diagnostic_item( cx, cx. typeck_results( ) . expr_ty( recv) , sym:: Result ) ;
22
+ // Test the version to make sure the lint can be showed (expect_err has been introduced in rust 1.17.0 : https://github.com/rust-lang/rust/pull/38982)
22
23
if meets_msrv( msrv, & msrvs:: EXPECT_ERR ) ;
23
24
25
+ // Grabs the `Result<T, E>` type
24
26
let result_type = cx. typeck_results( ) . expr_ty( recv) ;
27
+ // Tests if the T type in a `Result<T, E>` is not None
25
28
if let Some ( data_type) = get_data_type( cx, result_type) ;
29
+ // Tests if the T type in a `Result<T, E>` implements debug
26
30
if has_debug_impl( data_type, cx) ;
27
31
28
32
then {
@@ -42,11 +46,12 @@ pub(super) fn check(
42
46
/// Given a `Result<T, E>` type, return its data (`T`).
43
47
fn get_data_type < ' a > ( cx : & LateContext < ' _ > , ty : Ty < ' a > ) -> Option < Ty < ' a > > {
44
48
match ty. kind ( ) {
45
- ty:: Adt ( _, substs) if is_type_diagnostic_item ( cx, ty, sym:: Result ) => substs. types ( ) . nth ( 0 ) ,
49
+ ty:: Adt ( _, substs) if is_type_diagnostic_item ( cx, ty, sym:: Result ) => substs. types ( ) . next ( ) ,
46
50
_ => None ,
47
51
}
48
52
}
49
53
54
+ /// Givn a type, very if the Debug trait has been impl'd
50
55
fn has_debug_impl < ' tcx > ( ty : Ty < ' tcx > , cx : & LateContext < ' tcx > ) -> bool {
51
56
cx. tcx
52
57
. get_diagnostic_item ( sym:: Debug )
0 commit comments