File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed 
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 1- A type with a ` Drop `  implementation was destructured when trying to initialize
2- a static item.
1+ A value with a custom ` Drop `  implementation may be dropped during const-eval.
32
43Erroneous code example:
54
@@ -16,13 +15,14 @@ struct Foo {
1615    field1: DropType, 
1716} 
1817
19- static FOO: Foo = Foo { ..Foo {  field1: DropType::A }  }; // error! 
18+ static FOO: Foo = Foo { field1: ( DropType::A, DropType::A).1  }; // error! 
2019``` 
2120
2221The problem here is that if the given type or one of its fields implements the
23- ` Drop `  trait, this ` Drop `  implementation cannot be called during the static
24- type initialization which might cause a memory leak. To prevent this issue,
25- you need to instantiate all the static type's fields by hand.
22+ ` Drop `  trait, this ` Drop `  implementation cannot be called within a const
23+ context since it may run arbitrary, non-const-checked code. To prevent this
24+ issue, ensure all values with custom a custom ` Drop `  implementation escape the
25+ initializer.
2626
2727``` 
2828enum DropType { 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments