@@ -117,14 +117,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
117
117
let Some ( default_trait_id) = get_trait_def_id( cx, & paths:: DEFAULT_TRAIT ) ,
118
118
!implements_trait( cx, self_ty, default_trait_id, Vec :: new( ) )
119
119
] , {
120
- if can_derive_default( self_ty, cx, default_trait_id) {
120
+ if let Some ( sp ) = can_derive_default( self_ty, cx, default_trait_id) {
121
121
span_lint_and_then( cx,
122
122
NEW_WITHOUT_DEFAULT_DERIVE , span,
123
123
& format!( "you should consider deriving a \
124
124
`Default` implementation for `{}`",
125
125
self_ty) ,
126
126
|db| {
127
- db. suggest_item_with_attr( cx, span , "try this" , "#[derive(Default)]" ) ;
127
+ db. suggest_item_with_attr( cx, sp , "try this" , "#[derive(Default)]" ) ;
128
128
} ) ;
129
129
} else {
130
130
span_lint_and_then( cx,
@@ -151,17 +151,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
151
151
}
152
152
}
153
153
154
- fn can_derive_default < ' t , ' c > ( ty : ty:: Ty < ' t > , cx : & LateContext < ' c , ' t > , default_trait_id : DefId ) -> bool {
154
+ fn can_derive_default < ' t , ' c > ( ty : ty:: Ty < ' t > , cx : & LateContext < ' c , ' t > , default_trait_id : DefId ) -> Option < Span > {
155
155
match ty. sty {
156
156
ty:: TyAdt ( adt_def, substs) if adt_def. is_struct ( ) => {
157
157
for field in adt_def. all_fields ( ) {
158
158
let f_ty = field. ty ( cx. tcx , substs) ;
159
159
if !implements_trait ( cx, f_ty, default_trait_id, Vec :: new ( ) ) {
160
- return false ;
160
+ return None ;
161
161
}
162
162
}
163
- true
163
+ cx . tcx . map . span_if_local ( adt_def . did )
164
164
} ,
165
- _ => false ,
165
+ _ => None ,
166
166
}
167
167
}
0 commit comments