about summary refs log tree commit diff
path: root/src/librustc_driver/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_driver/test.rs')
-rw-r--r--src/librustc_driver/test.rs103
1 files changed, 57 insertions, 46 deletions
diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs
index 941155ac5e7..6329acfb578 100644
--- a/src/librustc_driver/test.rs
+++ b/src/librustc_driver/test.rs
@@ -28,7 +28,7 @@ use rustc_typeck::middle::infer::glb::Glb;
 use rustc_typeck::middle::infer::sub::Sub;
 use rustc_typeck::util::ppaux::{ty_to_string, Repr, UserString};
 use rustc::session::{mod,config};
-use syntax::{abi, ast, ast_map, ast_util};
+use syntax::{abi, ast, ast_map};
 use syntax::codemap;
 use syntax::codemap::{Span, CodeMap, DUMMY_SP};
 use syntax::diagnostic::{Level, RenderSpan, Bug, Fatal, Error, Warning, Note, Help};
@@ -145,6 +145,10 @@ fn test_env<F>(source_string: &str,
 }
 
 impl<'a, 'tcx> Env<'a, 'tcx> {
+    pub fn tcx(&self) -> &ty::ctxt<'tcx> {
+        self.infcx.tcx
+    }
+
     pub fn create_region_hierarchy(&self, rh: &RH) {
         for child_rh in rh.sub.iter() {
             self.create_region_hierarchy(child_rh);
@@ -296,7 +300,8 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
     }
 
     pub fn t_param(&self, space: subst::ParamSpace, index: u32) -> Ty<'tcx> {
-        ty::mk_param(self.infcx.tcx, space, index, ast_util::local_def(ast::DUMMY_NODE_ID))
+        let name = format!("T{}", index);
+        ty::mk_param(self.infcx.tcx, space, index, token::intern(name[]))
     }
 
     pub fn re_early_bound(&self,
@@ -314,14 +319,16 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
     }
 
     pub fn t_rptr(&self, r: ty::Region) -> Ty<'tcx> {
-        ty::mk_imm_rptr(self.infcx.tcx, self.infcx.tcx.mk_region(r), ty::mk_int())
+        ty::mk_imm_rptr(self.infcx.tcx,
+                        self.infcx.tcx.mk_region(r),
+                        self.tcx().types.int)
     }
 
     pub fn t_rptr_late_bound(&self, id: u32) -> Ty<'tcx> {
         let r = self.re_late_bound_with_debruijn(id, ty::DebruijnIndex::new(1));
         ty::mk_imm_rptr(self.infcx.tcx,
                         self.infcx.tcx.mk_region(r),
-                        ty::mk_int())
+                        self.tcx().types.int)
     }
 
     pub fn t_rptr_late_bound_with_debruijn(&self,
@@ -331,12 +338,13 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
         let r = self.re_late_bound_with_debruijn(id, debruijn);
         ty::mk_imm_rptr(self.infcx.tcx,
                         self.infcx.tcx.mk_region(r),
-                        ty::mk_int())
+                        self.tcx().types.int)
     }
 
     pub fn t_rptr_scope(&self, id: ast::NodeId) -> Ty<'tcx> {
         let r = ty::ReScope(CodeExtent::from_node_id(id));
-        ty::mk_imm_rptr(self.infcx.tcx, self.infcx.tcx.mk_region(r), ty::mk_int())
+        ty::mk_imm_rptr(self.infcx.tcx, self.infcx.tcx.mk_region(r),
+                        self.tcx().types.int)
     }
 
     pub fn re_free(&self, nid: ast::NodeId, id: u32) -> ty::Region {
@@ -346,15 +354,19 @@ impl<'a, 'tcx> Env<'a, 'tcx> {
 
     pub fn t_rptr_free(&self, nid: ast::NodeId, id: u32) -> Ty<'tcx> {
         let r = self.re_free(nid, id);
-        ty::mk_imm_rptr(self.infcx.tcx, self.infcx.tcx.mk_region(r), ty::mk_int())
+        ty::mk_imm_rptr(self.infcx.tcx,
+                        self.infcx.tcx.mk_region(r),
+                        self.tcx().types.int)
     }
 
     pub fn t_rptr_static(&self) -> Ty<'tcx> {
-        ty::mk_imm_rptr(self.infcx.tcx, self.infcx.tcx.mk_region(ty::ReStatic), ty::mk_int())
+        ty::mk_imm_rptr(self.infcx.tcx,
+                        self.infcx.tcx.mk_region(ty::ReStatic),
+                        self.tcx().types.int)
     }
 
     pub fn dummy_type_trace(&self) -> infer::TypeTrace<'tcx> {
-        infer::TypeTrace::dummy()
+        infer::TypeTrace::dummy(self.tcx())
     }
 
     pub fn sub(&self) -> Sub<'a, 'tcx> {
@@ -480,8 +492,8 @@ fn sub_free_bound_false() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_rptr_free1 = env.t_rptr_free(0, 1);
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
-        env.check_not_sub(env.t_fn(&[t_rptr_free1], ty::mk_int()),
-                          env.t_fn(&[t_rptr_bound1], ty::mk_int()));
+        env.check_not_sub(env.t_fn(&[t_rptr_free1], env.tcx().types.int),
+                          env.t_fn(&[t_rptr_bound1], env.tcx().types.int));
     })
 }
 
@@ -496,8 +508,8 @@ fn sub_bound_free_true() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
         let t_rptr_free1 = env.t_rptr_free(0, 1);
-        env.check_sub(env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_free1], ty::mk_int()));
+        env.check_sub(env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_free1], env.tcx().types.int));
     })
 }
 
@@ -512,8 +524,8 @@ fn sub_free_bound_false_infer() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_infer1 = env.infcx.next_ty_var();
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
-        env.check_not_sub(env.t_fn(&[t_infer1], ty::mk_int()),
-                          env.t_fn(&[t_rptr_bound1], ty::mk_int()));
+        env.check_not_sub(env.t_fn(&[t_infer1], env.tcx().types.int),
+                          env.t_fn(&[t_rptr_bound1], env.tcx().types.int));
     })
 }
 
@@ -531,9 +543,9 @@ fn lub_free_bound_infer() {
         let t_infer1 = env.infcx.next_ty_var();
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
         let t_rptr_free1 = env.t_rptr_free(0, 1);
-        env.check_lub(env.t_fn(&[t_infer1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_free1], ty::mk_int()));
+        env.check_lub(env.t_fn(&[t_infer1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_free1], env.tcx().types.int));
     });
 }
 
@@ -542,9 +554,9 @@ fn lub_bound_bound() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
         let t_rptr_bound2 = env.t_rptr_late_bound(2);
-        env.check_lub(env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_bound2], ty::mk_int()),
-                      env.t_fn(&[t_rptr_bound1], ty::mk_int()));
+        env.check_lub(env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_bound2], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_bound1], env.tcx().types.int));
     })
 }
 
@@ -553,9 +565,9 @@ fn lub_bound_free() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
         let t_rptr_free1 = env.t_rptr_free(0, 1);
-        env.check_lub(env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_free1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_free1], ty::mk_int()));
+        env.check_lub(env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_free1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_free1], env.tcx().types.int));
     })
 }
 
@@ -564,9 +576,9 @@ fn lub_bound_static() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
         let t_rptr_static = env.t_rptr_static();
-        env.check_lub(env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_static], ty::mk_int()),
-                      env.t_fn(&[t_rptr_static], ty::mk_int()));
+        env.check_lub(env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_static], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_static], env.tcx().types.int));
     })
 }
 
@@ -587,9 +599,9 @@ fn lub_free_free() {
         let t_rptr_free1 = env.t_rptr_free(0, 1);
         let t_rptr_free2 = env.t_rptr_free(0, 2);
         let t_rptr_static = env.t_rptr_static();
-        env.check_lub(env.t_fn(&[t_rptr_free1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_free2], ty::mk_int()),
-                      env.t_fn(&[t_rptr_static], ty::mk_int()));
+        env.check_lub(env.t_fn(&[t_rptr_free1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_free2], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_static], env.tcx().types.int));
     })
 }
 
@@ -612,9 +624,9 @@ fn glb_free_free_with_common_scope() {
         let t_rptr_free1 = env.t_rptr_free(0, 1);
         let t_rptr_free2 = env.t_rptr_free(0, 2);
         let t_rptr_scope = env.t_rptr_scope(0);
-        env.check_glb(env.t_fn(&[t_rptr_free1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_free2], ty::mk_int()),
-                      env.t_fn(&[t_rptr_scope], ty::mk_int()));
+        env.check_glb(env.t_fn(&[t_rptr_free1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_free2], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_scope], env.tcx().types.int));
     })
 }
 
@@ -623,9 +635,9 @@ fn glb_bound_bound() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
         let t_rptr_bound2 = env.t_rptr_late_bound(2);
-        env.check_glb(env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_bound2], ty::mk_int()),
-                      env.t_fn(&[t_rptr_bound1], ty::mk_int()));
+        env.check_glb(env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_bound2], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_bound1], env.tcx().types.int));
     })
 }
 
@@ -634,9 +646,9 @@ fn glb_bound_free() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
         let t_rptr_free1 = env.t_rptr_free(0, 1);
-        env.check_glb(env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_free1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_bound1], ty::mk_int()));
+        env.check_glb(env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_free1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_bound1], env.tcx().types.int));
     })
 }
 
@@ -648,9 +660,9 @@ fn glb_bound_free_infer() {
 
         // compute GLB(fn(_) -> int, for<'b> fn(&'b int) -> int),
         // which should yield for<'b> fn(&'b int) -> int
-        env.check_glb(env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_infer1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_bound1], ty::mk_int()));
+        env.check_glb(env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_infer1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_bound1], env.tcx().types.int));
 
         // as a side-effect, computing GLB should unify `_` with
         // `&'_ int`
@@ -667,9 +679,9 @@ fn glb_bound_static() {
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let t_rptr_bound1 = env.t_rptr_late_bound(1);
         let t_rptr_static = env.t_rptr_static();
-        env.check_glb(env.t_fn(&[t_rptr_bound1], ty::mk_int()),
-                      env.t_fn(&[t_rptr_static], ty::mk_int()),
-                      env.t_fn(&[t_rptr_bound1], ty::mk_int()));
+        env.check_glb(env.t_fn(&[t_rptr_bound1], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_static], env.tcx().types.int),
+                      env.t_fn(&[t_rptr_bound1], env.tcx().types.int));
     })
 }
 
@@ -790,7 +802,6 @@ fn escaping() {
 /// late-bound region.
 #[test]
 fn subst_region_renumber_region() {
-
     test_env(EMPTY_SOURCE_STR, errors(&[]), |env| {
         let re_bound1 = env.re_late_bound_with_debruijn(1, ty::DebruijnIndex::new(1));