about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2015-01-16 05:48:15 +0200
committerEduard Burtescu <edy.burt@gmail.com>2015-01-30 00:27:12 +0200
commitf9f3ba5920ddb2b8bae5047eea556081e0da159d (patch)
tree1ca9765eb7499b1dbd4072d92b3164e7c4f42fb4 /src
parent265a23320dbeaeca45b889cfea684d71dec1b8e6 (diff)
downloadrust-f9f3ba5920ddb2b8bae5047eea556081e0da159d.tar.gz
rust-f9f3ba5920ddb2b8bae5047eea556081e0da159d.zip
rustc: move infer::coercion to rustc_typeck.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/infer/mod.rs43
-rw-r--r--src/librustc_typeck/check/coercion.rs (renamed from src/librustc/middle/infer/coercion.rs)42
-rw-r--r--src/librustc_typeck/check/mod.rs18
3 files changed, 43 insertions, 60 deletions
diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs
index cfcead51f78..1665966a5e5 100644
--- a/src/librustc/middle/infer/mod.rs
+++ b/src/librustc/middle/infer/mod.rs
@@ -33,12 +33,10 @@ use std::rc::Rc;
 use syntax::ast;
 use syntax::codemap;
 use syntax::codemap::Span;
-use util::common::indent;
 use util::nodemap::FnvHashMap;
 use util::ppaux::{ty_to_string};
 use util::ppaux::{Repr, UserString};
 
-use self::coercion::Coerce;
 use self::combine::{Combine, Combineable, CombineFields};
 use self::region_inference::{RegionVarBindings, RegionSnapshot};
 use self::equate::Equate;
@@ -47,7 +45,6 @@ use self::lub::Lub;
 use self::unify::{UnificationTable, InferCtxtMethodsForSimplyUnifiableTypes};
 use self::error_reporting::ErrorReporting;
 
-pub mod coercion;
 pub mod combine;
 pub mod doc;
 pub mod equate;
@@ -68,7 +65,6 @@ pub type Bound<T> = Option<T>;
 pub type cres<'tcx, T> = Result<T,ty::type_err<'tcx>>; // "combine result"
 pub type ures<'tcx> = cres<'tcx, ()>; // "unify result"
 pub type fres<T> = Result<T, fixup_err>; // "fixup result"
-pub type CoerceResult<'tcx> = cres<'tcx, Option<ty::AutoAdjustment<'tcx>>>;
 
 pub struct InferCtxt<'a, 'tcx: 'a> {
     pub tcx: &'a ty::ctxt<'tcx>,
@@ -409,24 +405,6 @@ fn expected_found<T>(a_is_expected: bool,
     }
 }
 
-pub fn mk_coercety<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
-                             a_is_expected: bool,
-                             origin: TypeOrigin,
-                             a: Ty<'tcx>,
-                             b: Ty<'tcx>)
-                             -> CoerceResult<'tcx> {
-    debug!("mk_coercety({} -> {})", a.repr(cx.tcx), b.repr(cx.tcx));
-    indent(|| {
-        cx.commit_if_ok(|| {
-            let trace = TypeTrace {
-                origin: origin,
-                values: Types(expected_found(a_is_expected, a, b))
-            };
-            Coerce(cx.combine_fields(a_is_expected, trace)).tys(a, b)
-        })
-    })
-}
-
 trait then<'tcx> {
     fn then<T, F>(&self, f: F) -> Result<T, ty::type_err<'tcx>> where
         T: Clone,
@@ -689,10 +667,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
     {
         debug!("sub_types({} <: {})", a.repr(self.tcx), b.repr(self.tcx));
         self.commit_if_ok(|| {
-            let trace = TypeTrace {
-                origin: origin,
-                values: Types(expected_found(a_is_expected, a, b))
-            };
+            let trace = TypeTrace::types(origin, a_is_expected, a, b);
             self.sub(a_is_expected, trace).tys(a, b).to_ures()
         })
     }
@@ -705,10 +680,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                     -> ures<'tcx>
     {
         self.commit_if_ok(|| {
-            let trace = TypeTrace {
-                origin: origin,
-                values: Types(expected_found(a_is_expected, a, b))
-            };
+            let trace = TypeTrace::types(origin, a_is_expected, a, b);
             self.equate(a_is_expected, trace).tys(a, b).to_ures()
         })
     }
@@ -1118,6 +1090,17 @@ impl<'tcx> TypeTrace<'tcx> {
         self.origin.span()
     }
 
+    pub fn types(origin: TypeOrigin,
+                 a_is_expected: bool,
+                 a: Ty<'tcx>,
+                 b: Ty<'tcx>)
+                 -> TypeTrace<'tcx> {
+        TypeTrace {
+            origin: origin,
+            values: Types(expected_found(a_is_expected, a, b))
+        }
+    }
+
     pub fn dummy(tcx: &ty::ctxt<'tcx>) -> TypeTrace<'tcx> {
         TypeTrace {
             origin: Misc(codemap::DUMMY_SP),
diff --git a/src/librustc/middle/infer/coercion.rs b/src/librustc_typeck/check/coercion.rs
index e8b8ecc701f..e375647bc28 100644
--- a/src/librustc/middle/infer/coercion.rs
+++ b/src/librustc_typeck/check/coercion.rs
@@ -60,14 +60,15 @@
 //! sort of a minor point so I've opted to leave it for later---after all
 //! we may want to adjust precisely when coercions occur.
 
-use super::{CoerceResult, Coercion};
-use super::combine::{CombineFields, Combine};
-use super::sub::Sub;
+use middle::infer::{cres, Coercion, InferCtxt, TypeOrigin, TypeTrace};
+use middle::infer::combine::{CombineFields, Combine};
+use middle::infer::sub::Sub;
 
 use middle::subst;
 use middle::ty::{AutoPtr, AutoDerefRef, AdjustDerefRef, AutoUnsize, AutoUnsafe};
 use middle::ty::{mt};
 use middle::ty::{self, Ty};
+use util::common::indent;
 use util::ppaux;
 use util::ppaux::Repr;
 
@@ -472,24 +473,6 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
         }
     }
 
-    pub fn coerce_borrowed_fn(&self,
-                              a: Ty<'tcx>,
-                              b: Ty<'tcx>)
-                              -> CoerceResult<'tcx> {
-        debug!("coerce_borrowed_fn(a={}, b={})",
-               a.repr(self.tcx()),
-               b.repr(self.tcx()));
-
-        match a.sty {
-            ty::ty_bare_fn(Some(a_def_id), f) => {
-                self.coerce_from_fn_item(a, a_def_id, f, b)
-            }
-            _ => {
-                self.subtype(a, b)
-            }
-        }
-    }
-
     fn coerce_from_fn_item(&self,
                            a: Ty<'tcx>,
                            fn_def_id_a: ast::DefId,
@@ -551,6 +534,23 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
     }
 }
 
+pub type CoerceResult<'tcx> = cres<'tcx, Option<ty::AutoAdjustment<'tcx>>>;
+
+pub fn mk_coercety<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
+                             a_is_expected: bool,
+                             origin: TypeOrigin,
+                             a: Ty<'tcx>,
+                             b: Ty<'tcx>)
+                             -> CoerceResult<'tcx> {
+    debug!("mk_coercety({} -> {})", a.repr(cx.tcx), b.repr(cx.tcx));
+    indent(|| {
+        cx.commit_if_ok(|| {
+            let trace = TypeTrace::types(origin, a_is_expected, a, b);
+            Coerce(cx.combine_fields(a_is_expected, trace)).tys(a, b)
+        })
+    })
+}
+
 fn can_coerce_mutbls(from_mutbl: ast::Mutability,
                      to_mutbl: ast::Mutability)
                      -> bool {
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 6dabec31e2c..799c7a355b7 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -132,6 +132,7 @@ pub mod vtable;
 pub mod writeback;
 pub mod regionmanip;
 pub mod regionck;
+pub mod coercion;
 pub mod demand;
 pub mod method;
 mod upvar;
@@ -1730,18 +1731,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                        sub: Ty<'tcx>,
                        sup: Ty<'tcx>)
                        -> Result<(), ty::type_err<'tcx>> {
-        match infer::mk_coercety(self.infcx(),
-                                 false,
-                                 infer::ExprAssignable(expr.span),
-                                 sub,
-                                 sup) {
-            Ok(None) => Ok(()),
-            Err(ref e) => Err((*e)),
-            Ok(Some(adjustment)) => {
+        match try!(coercion::mk_coercety(self.infcx(),
+                                         false,
+                                         infer::ExprAssignable(expr.span),
+                                         sub,
+                                         sup)) {
+            None => {}
+            Some(adjustment) => {
                 self.write_adjustment(expr.id, expr.span, adjustment);
-                Ok(())
             }
         }
+        Ok(())
     }
 
     pub fn mk_eqty(&self,