@@ -13,7 +13,6 @@ use rustc::ty::util::CopyImplementationError;
1313use rustc:: ty:: TypeFoldable ;
1414use rustc:: ty:: { self , Ty , TyCtxt } ;
1515
16- use hir:: Node ;
1716use rustc:: hir:: def_id:: DefId ;
1817use rustc:: hir:: { self , ItemKind } ;
1918
@@ -51,35 +50,25 @@ impl<'tcx> Checker<'tcx> {
5150}
5251
5352fn visit_implementation_of_drop ( tcx : TyCtxt < ' _ > , impl_did : DefId ) {
54- if let ty:: Adt ( ..) = tcx. type_of ( impl_did) . kind {
55- /* do nothing */
56- } else {
57- // Destructors only work on nominal types.
58- if let Some ( impl_hir_id) = tcx. hir ( ) . as_local_hir_id ( impl_did) {
59- if let Some ( Node :: Item ( item) ) = tcx. hir ( ) . find ( impl_hir_id) {
60- let span = match item. kind {
61- ItemKind :: Impl ( .., ref ty, _) => ty. span ,
62- _ => item. span ,
63- } ;
64- struct_span_err ! (
65- tcx. sess,
66- span,
67- E0120 ,
68- "the Drop trait may only be implemented on \
69- structures"
70- )
71- . span_label ( span, "implementing Drop requires a struct" )
72- . emit ( ) ;
73- } else {
74- bug ! ( "didn't find impl in ast map" ) ;
75- }
76- } else {
77- bug ! (
78- "found external impl of Drop trait on \
79- something other than a struct"
80- ) ;
81- }
53+ // Destructors only work on nominal types.
54+ if let ty:: Adt ( ..) | ty:: Error = tcx. type_of ( impl_did) . kind {
55+ return ;
8256 }
57+
58+ let impl_hir_id = tcx. hir ( ) . as_local_hir_id ( impl_did) . expect ( "foreign Drop impl on non-ADT" ) ;
59+ let sp = match tcx. hir ( ) . expect_item ( impl_hir_id) . kind {
60+ ItemKind :: Impl ( .., ty, _) => ty. span ,
61+ _ => bug ! ( "expected Drop impl item" ) ,
62+ } ;
63+
64+ struct_span_err ! (
65+ tcx. sess,
66+ sp,
67+ E0120 ,
68+ "the `Drop` trait may only be implemented for structs, enums, and unions" ,
69+ )
70+ . span_label ( sp, "must be a struct, enum, or union" )
71+ . emit ( ) ;
8372}
8473
8574fn visit_implementation_of_copy ( tcx : TyCtxt < ' _ > , impl_did : DefId ) {
0 commit comments