- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Don't project into NonNull when dropping a Box
          #137112
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            94 changes: 94 additions & 0 deletions
          
          94 
        
  tests/mir-opt/box_partial_move.maybe_move.ElaborateDrops.diff
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| - // MIR for `maybe_move` before ElaborateDrops | ||
| + // MIR for `maybe_move` after ElaborateDrops | ||
|  | ||
| fn maybe_move(_1: bool, _2: Box<String>) -> Option<String> { | ||
| debug cond => _1; | ||
| debug thing => _2; | ||
| let mut _0: std::option::Option<std::string::String>; | ||
| let mut _3: bool; | ||
| let mut _4: std::string::String; | ||
| + let mut _5: bool; | ||
| + let mut _6: &mut std::boxed::Box<std::string::String>; | ||
| + let mut _7: (); | ||
| + let mut _8: &mut std::boxed::Box<std::string::String>; | ||
| + let mut _9: (); | ||
| + let mut _10: *const std::string::String; | ||
|  | ||
| bb0: { | ||
| + _5 = const false; | ||
| + _5 = const true; | ||
| StorageLive(_3); | ||
| _3 = copy _1; | ||
| switchInt(move _3) -> [0: bb3, otherwise: bb1]; | ||
| } | ||
|  | ||
| bb1: { | ||
| StorageLive(_4); | ||
| + _5 = const false; | ||
| _4 = move (*_2); | ||
| _0 = Option::<String>::Some(move _4); | ||
| - drop(_4) -> [return: bb2, unwind: bb6]; | ||
| + goto -> bb2; | ||
| } | ||
|  | ||
| bb2: { | ||
| StorageDead(_4); | ||
| goto -> bb4; | ||
| } | ||
|  | ||
| bb3: { | ||
| _0 = Option::<String>::None; | ||
| goto -> bb4; | ||
| } | ||
|  | ||
| bb4: { | ||
| StorageDead(_3); | ||
| - drop(_2) -> [return: bb5, unwind continue]; | ||
| + goto -> bb14; | ||
| } | ||
|  | ||
| bb5: { | ||
| return; | ||
| } | ||
|  | ||
| bb6 (cleanup): { | ||
| - drop(_2) -> [return: bb7, unwind terminate(cleanup)]; | ||
| + goto -> bb7; | ||
| } | ||
|  | ||
| bb7 (cleanup): { | ||
| resume; | ||
| + } | ||
| + | ||
| + bb8: { | ||
| + goto -> bb5; | ||
| + } | ||
| + | ||
| + bb9: { | ||
| + _6 = &mut _2; | ||
| + _7 = <Box<String> as Drop>::drop(move _6) -> [return: bb8, unwind: bb7]; | ||
| + } | ||
| + | ||
| + bb10 (cleanup): { | ||
| + _8 = &mut _2; | ||
| + _9 = <Box<String> as Drop>::drop(move _8) -> [return: bb7, unwind terminate(cleanup)]; | ||
| + } | ||
| + | ||
| + bb11: { | ||
| + goto -> bb13; | ||
| + } | ||
| + | ||
| + bb12: { | ||
| + drop((*_10)) -> [return: bb9, unwind: bb10]; | ||
| + } | ||
| + | ||
| + bb13: { | ||
| + switchInt(copy _5) -> [0: bb9, otherwise: bb12]; | ||
| + } | ||
| + | ||
| + bb14: { | ||
| + _10 = copy ((_2.0: std::ptr::Unique<std::string::String>).0: std::ptr::NonNull<std::string::String>) as *const std::string::String (Transmute); | ||
| + goto -> bb11; | ||
| } | ||
| } | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| //@ test-mir-pass: ElaborateDrops | ||
| //@ needs-unwind | ||
|  | ||
| #![feature(rustc_attrs, liballoc_internals)] | ||
|  | ||
| // EMIT_MIR box_partial_move.maybe_move.ElaborateDrops.diff | ||
| fn maybe_move(cond: bool, thing: Box<String>) -> Option<String> { | ||
| // CHECK-LABEL: fn maybe_move( | ||
| // CHECK: let mut [[PTR:_[0-9]+]]: *const std::string::String; | ||
| // CHECK: [[PTR]] = copy ((_2.0: std::ptr::Unique<std::string::String>).0: std::ptr::NonNull<std::string::String>) as *const std::string::String (Transmute); | ||
| // CHECK: drop((*[[PTR]])) | ||
| if cond { Some(*thing) } else { None } | ||
| } | ||
|  | ||
| fn main() { | ||
| maybe_move(false, Box::new("hello".to_string())); | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
annot: the other test didn't seem to have a use of the new pointer local this PR adds, so added this. If there's a better place to test it, let me know.