]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/infer/type_variable.rs
make `Default` Copy and Clone
[rust.git] / src / librustc / infer / type_variable.rs
index 4ae2a8026409d3fcd4082562c4f8d850041da957..36afb8b536725134f449f54f59a9b678265d23d3 100644 (file)
@@ -56,7 +56,10 @@ pub enum TypeVariableOrigin {
     NormalizeProjectionType(Span),
     TypeInference(Span),
     TypeParameterDefinition(Span, ast::Name),
-    TransformedUpvar(Span),
+
+    /// one of the upvars or closure kind parameters in a `ClosureSubsts`
+    /// (before it has been determined)
+    ClosureSynthetic(Span),
     SubstitutionPlaceholder(Span),
     AutoDeref(Span),
     AdjustmentType(Span),
@@ -76,7 +79,9 @@ struct TypeVariableData<'tcx> {
 }
 
 enum TypeVariableValue<'tcx> {
-    Known(Ty<'tcx>),
+    Known {
+        value: Ty<'tcx>
+    },
     Bounded {
         default: Option<Default<'tcx>>
     }
@@ -84,7 +89,7 @@ enum TypeVariableValue<'tcx> {
 
 // We will use this to store the required information to recapitulate what happened when
 // an error occurs.
-#[derive(Clone, Debug, PartialEq, Eq, Hash)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
 pub struct Default<'tcx> {
     pub ty: Ty<'tcx>,
     /// The span where the default was incurred
@@ -117,8 +122,8 @@ pub fn new() -> TypeVariableTable<'tcx> {
 
     pub fn default(&self, vid: ty::TyVid) -> Option<Default<'tcx>> {
         match &self.values.get(vid.index as usize).value {
-            &Known(_) => None,
-            &Bounded { ref default, .. } => default.clone()
+            &Known { .. } => None,
+            &Bounded { default, .. } => default,
         }
     }
 
@@ -158,14 +163,14 @@ pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
 
         let old_value = {
             let vid_data = &mut self.values[vid.index as usize];
-            mem::replace(&mut vid_data.value, TypeVariableValue::Known(ty))
+            mem::replace(&mut vid_data.value, TypeVariableValue::Known { value: ty })
         };
 
         match old_value {
             TypeVariableValue::Bounded { default } => {
                 self.values.record(Instantiate { vid: vid, default: default });
             }
-            TypeVariableValue::Known(old_ty) => {
+            TypeVariableValue::Known { value: old_ty } => {
                 bug!("instantiating type variable `{:?}` twice: new-value = {:?}, old-value={:?}",
                      vid, ty, old_ty)
             }
@@ -180,9 +185,9 @@ pub fn new_var(&mut self,
         self.eq_relations.new_key(());
         self.sub_relations.new_key(());
         let index = self.values.push(TypeVariableData {
-            value: Bounded { default: default },
-            origin: origin,
-            diverging: diverging
+            value: Bounded { default },
+            origin,
+            diverging,
         });
         let v = ty::TyVid { index: index as u32 };
         debug!("new_var: diverging={:?} index={:?}", diverging, v);
@@ -233,7 +238,7 @@ pub fn probe_root(&mut self, vid: ty::TyVid) -> Option<Ty<'tcx>> {
         debug_assert!(self.root_var(vid) == vid);
         match self.values.get(vid.index as usize).value {
             Bounded { .. } => None,
-            Known(t) => Some(t)
+            Known { value } => Some(value)
         }
     }
 
@@ -334,7 +339,7 @@ pub fn types_escaping_snapshot(&mut self, s: &Snapshot) -> Vec<Ty<'tcx>> {
                         // created since the snapshot started or not.
                         let escaping_type = match self.values.get(vid.index as usize).value {
                             Bounded { .. } => bug!(),
-                            Known(ty) => ty,
+                            Known { value } => value,
                         };
                         escaping_types.push(escaping_type);
                     }
@@ -369,7 +374,7 @@ impl<'tcx> sv::SnapshotVecDelegate for Delegate<'tcx> {
     fn reverse(values: &mut Vec<TypeVariableData<'tcx>>, action: Instantiate<'tcx>) {
         let Instantiate { vid, default } = action;
         values[vid.index as usize].value = Bounded {
-            default: default
+            default,
         };
     }
 }