Skip to content

crash: compile-time typeck/check.rs failure #3668

Closed
@BigEndian

Description

@BigEndian

Result of attempted compilation:

rust: task failed at 'Assertion fcx.inh.locals.contains_key(nid) failed', /Users/superjapanfreak/build/rust/src/rustc/middle/typeck/check.rs:2388
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=0,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /Users/superjapanfreak/build/rust/src/rustc/driver/rustc.rs:275
rust: domain main @0x7fb97b800010 root task failed
rust: task failed at 'killed', /Users/superjapanfreak/build/rust/src/libcore/task.rs:705
struct Employee { name: ~str, mut employer: Option<@Business> }                                                                                                                    
struct Business { name: ~str, mut boss: Option<@mut Employee>, mut employees: ~[Option<@mut Employee>] }                                                                           

trait EmployeeTrait {                                                                                                                                                              
   pure fn isEmployed() -> bool;                                                                                                                                                   
   fn setEmployer(employer: @Business);                                                                                                                                            
}                                                                                                                                                                                  

impl Employee: EmployeeTrait {                                                                                                                                                        pure fn isEmployed() -> bool {                                                                                                                                                        self.employer.is_some()                                                                                                                                                      
   }                                                                                                                                                                               
   fn setEmployer(employer: @Business) {                                                                                                                                           
      self.employer = Some(employer);                                                                                                                                              
   }                                                                                                                                                                               
}                                                                                                                                                                                  

trait BusinessTrait {                                                                                                                                                              
   fn fireBoss() -> bool;                                                                                                                                                          
   fn hireBoss(e: @mut Employee);                                                                                                                                                  
   fn getBossOption() -> Option<@Employee>;                                                                                                                                        
}                                                                                                                                                                                  

impl Business: BusinessTrait {                                                                                                                                                     
   fn fireBoss() -> bool {                                                                                                                                                         
      if self.boss.is_none() {                                                                                                                                                     
         return false;                                                                                                                                                             
      }                                                                                                                                                                            
      let oldBoss = self.boss.get();                                                                                                                                               
      oldBoss.employer = None;                                                                                                                                                     
      self.boss = None;                                                                                                                                                            
      true                                                                                                                                                                         
   }                                                                                                                                                                               
   fn hireBoss(newBoss: @mut Employee) {                                                                                                                                           
      if self.boss.is_some() {                                                                                                                                                     
         self.fireBoss();                                                                                                                                                          
      }                                                                                                                                                                            
      newBoss.setEmployer(@copy self);                                                                                                                                             
      self.boss = Some(newBoss);                                                                                                                                                   
   }                                                                                                                                                                               
   fn getBossOption() -> Option<@Employee> {                                                                                                                                       
      let opt: Option<@Employee> = None;                                                                                                                                           
      if self.boss.is_some() {                                                                                                                                                     
         const bossCopy: @Employee = self.boss.get();                                                                                                                              
         opt = Some(bossCopy);                                                                                                                                                     
      }                                                                                                                                                                            
      opt                                                                                                                                                                          
   }                                                                                                                                                                               
}                                                                                                                                                                                  

fn main() {                                                                                                                                                                        
   let bob = @mut Employee { name: ~"Bob Newhart", employer: None };
   let restaurant = Business { name: ~"In-N-Out", boss: Some(bob), employees: ~[] };                                                                                               

   io::println(#fmt("Bob is %s", if bob.isEmployed() { ~"employed" } else { ~"not employed" }));                                                                                   
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-type-systemArea: Type systemI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions