@@ -18,6 +18,7 @@ use rustc_data_structures::bitvec::BitVector;
1818use  rustc_data_structures:: indexed_vec:: { IndexVec ,  Idx } ; 
1919use  rustc:: dep_graph:: DepNode ; 
2020use  rustc:: hir; 
21+ use  rustc:: hir:: map as  hir_map; 
2122use  rustc:: hir:: def_id:: DefId ; 
2223use  rustc:: hir:: intravisit:: FnKind ; 
2324use  rustc:: hir:: map:: blocks:: FnLikeNode ; 
@@ -252,14 +253,46 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
252253
253254        let  mut  err =
254255            struct_span_err ! ( self . tcx. sess,  self . span,  E0493 ,  "{}" ,  msg) ; 
256+ 
255257        if  self . mode  != Mode :: Const  { 
256258            help ! ( & mut  err, 
257259                  "in Nightly builds, add `#![feature(drop_types_in_const)]` \  
258260                    to the crate attributes to enable") ; 
261+         }  else  { 
262+             self . find_drop_implementation_method_span ( ) 
263+                 . map ( |span| err. span_label ( span,  & format ! ( "destructor defined here" ) ) ) ; 
264+ 
265+             err. span_label ( self . span ,  & format ! ( "constants cannot have destructors" ) ) ; 
259266        } 
267+ 
260268        err. emit ( ) ; 
261269    } 
262270
271+     fn  find_drop_implementation_method_span ( & self )  -> Option < Span >  { 
272+         self . tcx . lang_items 
273+             . drop_trait ( ) 
274+             . and_then ( |drop_trait_id| { 
275+                 let  mut  span = None ; 
276+ 
277+                 self . tcx 
278+                     . lookup_trait_def ( drop_trait_id) 
279+                     . for_each_relevant_impl ( self . tcx ,  self . mir . return_ty ,  |impl_did| { 
280+                         self . tcx . map 
281+                             . as_local_node_id ( impl_did) 
282+                             . and_then ( |impl_node_id| self . tcx . map . find ( impl_node_id) ) 
283+                             . map ( |node| { 
284+                                 if  let  hir_map:: NodeItem ( item)  = node { 
285+                                     if  let  hir:: ItemImpl ( _,  _,  _,  _,  _,  ref  methods)  = item. node  { 
286+                                         span = methods. first ( ) . map ( |method| method. span ) ; 
287+                                     } 
288+                                 } 
289+                             } ) ; 
290+                     } ) ; 
291+ 
292+                 span
293+             } ) 
294+     } 
295+ 
263296    /// Check if an Lvalue with the current qualifications could 
264297     /// be consumed, by either an operand or a Deref projection. 
265298     fn  try_consume ( & mut  self )  -> bool  { 
0 commit comments