@@ -283,7 +283,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
283
283
// name `__test`
284
284
if item. span == DUMMY_SP && item. ident . as_str ( ) == "__test" { return }
285
285
286
- check_item ( self . tcx , item,
286
+ check_item ( self . tcx , item, true ,
287
287
& mut |id, sp, stab| self . check ( id, sp, stab) ) ;
288
288
visit:: walk_item ( self , item) ;
289
289
}
@@ -302,7 +302,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
302
302
}
303
303
304
304
/// Helper for discovering nodes to check for stability
305
- pub fn check_item ( tcx : & ty:: ctxt , item : & ast:: Item ,
305
+ pub fn check_item ( tcx : & ty:: ctxt , item : & ast:: Item , warn_about_defns : bool ,
306
306
cb : & mut FnMut ( ast:: DefId , Span , & Option < Stability > ) ) {
307
307
match item. node {
308
308
ast:: ItemExternCrate ( _) => {
@@ -316,6 +316,35 @@ pub fn check_item(tcx: &ty::ctxt, item: &ast::Item,
316
316
let id = ast:: DefId { krate : cnum, node : ast:: CRATE_NODE_ID } ;
317
317
maybe_do_stability_check ( tcx, id, item. span , cb) ;
318
318
}
319
+
320
+ // For implementations of traits, check the stability of each item
321
+ // individually as it's possible to have a stable trait with unstable
322
+ // items.
323
+ ast:: ItemImpl ( _, _, _, Some ( ref t) , _, ref impl_items) => {
324
+ let trait_did = tcx. def_map . borrow ( ) [ t. ref_id ] . def_id ( ) ;
325
+ let trait_items = ty:: trait_items ( tcx, trait_did) ;
326
+
327
+ for impl_item in impl_items {
328
+ let ( ident, span) = match * impl_item {
329
+ ast:: MethodImplItem ( ref method) => {
330
+ ( match method. node {
331
+ ast:: MethDecl ( ident, _, _, _, _, _, _, _) => ident,
332
+ ast:: MethMac ( ..) => unreachable ! ( ) ,
333
+ } , method. span )
334
+ }
335
+ ast:: TypeImplItem ( ref typedef) => {
336
+ ( typedef. ident , typedef. span )
337
+ }
338
+ } ;
339
+ let item = trait_items. iter ( ) . find ( |item| {
340
+ item. name ( ) == ident. name
341
+ } ) . unwrap ( ) ;
342
+ if warn_about_defns {
343
+ maybe_do_stability_check ( tcx, item. def_id ( ) , span, cb) ;
344
+ }
345
+ }
346
+ }
347
+
319
348
_ => ( /* pass */ )
320
349
}
321
350
}
0 commit comments