@@ -3,7 +3,8 @@ use rustc_front::hir;
3
3
use rustc_front:: intravisit:: FnKind ;
4
4
use syntax:: ast;
5
5
use syntax:: codemap:: Span ;
6
- use utils:: { get_trait_def_id, implements_trait, in_external_macro, return_ty, span_lint, DEFAULT_TRAIT_PATH } ;
6
+ use utils:: { get_trait_def_id, implements_trait, in_external_macro, return_ty, same_tys, span_lint,
7
+ DEFAULT_TRAIT_PATH } ;
7
8
8
9
/// **What it does:** This lints about type with a `fn new() -> Self` method and no `Default`
9
10
/// implementation.
@@ -49,16 +50,15 @@ impl LateLintPass for NewWithoutDefault {
49
50
if decl. inputs . is_empty ( ) && name. as_str ( ) == "new" {
50
51
let self_ty = cx. tcx . lookup_item_type ( cx. tcx . map . local_def_id ( cx. tcx . map . get_parent ( id) ) ) . ty ;
51
52
52
- let ret_ty = return_ty ( cx. tcx . node_id_to_type ( id) ) ;
53
-
54
- if Some ( self_ty) == ret_ty {
55
- if let Some ( default_trait_id) = get_trait_def_id ( cx, & DEFAULT_TRAIT_PATH ) {
56
- if !implements_trait ( cx, self_ty, default_trait_id, Vec :: new ( ) ) {
57
- span_lint ( cx, NEW_WITHOUT_DEFAULT , span,
58
- & format ! ( "you should consider adding a `Default` implementation for `{}`" , self_ty) ) ;
59
- }
60
- }
61
- }
53
+ if_let_chain ! { [
54
+ let Some ( ret_ty) = return_ty( cx. tcx. node_id_to_type( id) ) ,
55
+ same_tys( cx, self_ty, ret_ty) ,
56
+ let Some ( default_trait_id) = get_trait_def_id( cx, & DEFAULT_TRAIT_PATH ) ,
57
+ !implements_trait( cx, self_ty, default_trait_id, Vec :: new( ) )
58
+ ] , {
59
+ span_lint( cx, NEW_WITHOUT_DEFAULT , span,
60
+ & format!( "you should consider adding a `Default` implementation for `{}`" , self_ty) ) ;
61
+ } }
62
62
}
63
63
}
64
64
}
0 commit comments