]> git.lizzy.rs Git - rust.git/commitdiff
Fix bug with defaults not being restored
authorJared Roesch <roeschinc@gmail.com>
Thu, 9 Jul 2015 23:04:37 +0000 (16:04 -0700)
committerJared Roesch <jroesch@MacBook.home>
Sun, 26 Jul 2015 02:57:58 +0000 (19:57 -0700)
src/librustc/middle/infer/type_variable.rs

index 6ba289d3665aa7d870145117a72128839591462b..fa7cd143e3b21da93c32ec5215490bf976958d2f 100644 (file)
@@ -47,9 +47,9 @@ pub struct Snapshot {
     snapshot: sv::Snapshot
 }
 
-enum UndoEntry {
+enum UndoEntry<'tcx> {
     // The type of the var was specified.
-    SpecifyVar(ty::TyVid, Vec<Relation>),
+    SpecifyVar(ty::TyVid, Vec<Relation>, Option<Default<'tcx>>),
     Relate(ty::TyVid, ty::TyVid),
 }
 
@@ -118,8 +118,8 @@ pub fn instantiate_and_push(
             mem::replace(value_ptr, Known(ty))
         };
 
-        let relations = match old_value {
-            Bounded { relations, .. } => relations,
+        let (relations, default) = match old_value {
+            Bounded { relations, default } => (relations, default),
             Known(_) => panic!("Asked to instantiate variable that is \
                                already instantiated")
         };
@@ -128,7 +128,7 @@ pub fn instantiate_and_push(
             stack.push((ty, dir, vid));
         }
 
-        self.values.record(SpecifyVar(vid, relations));
+        self.values.record(SpecifyVar(vid, relations, default));
     }
 
     pub fn new_var(&mut self,
@@ -198,7 +198,7 @@ pub fn types_escaping_snapshot(&self, s: &Snapshot) -> Vec<Ty<'tcx>> {
                     debug!("NewElem({}) new_elem_threshold={}", index, new_elem_threshold);
                 }
 
-                sv::UndoLog::Other(SpecifyVar(vid, _)) => {
+                sv::UndoLog::Other(SpecifyVar(vid, _, _)) => {
                     if vid.index < new_elem_threshold {
                         // quick check to see if this variable was
                         // created since the snapshot started or not.
@@ -229,12 +229,15 @@ pub fn unsolved_variables(&self) -> Vec<ty::TyVid> {
 
 impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {
     type Value = TypeVariableData<'tcx>;
-    type Undo = UndoEntry;
+    type Undo = UndoEntry<'tcx>;
 
-    fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: UndoEntry) {
+    fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: UndoEntry<'tcx>) {
         match action {
-            SpecifyVar(vid, relations) => {
-                values[vid.index as usize].value = Bounded { relations: relations, default: None };
+            SpecifyVar(vid, relations, default) => {
+                values[vid.index as usize].value = Bounded {
+                    relations: relations,
+                    default: default
+                };
             }
 
             Relate(a, b) => {