about summary refs log tree commit diff
diff options
context:
space:
mode:
authortoidiu <toidiu@protonmail.com>2017-09-27 20:18:41 -0400
committertoidiu <toidiu@protonmail.com>2017-10-16 14:26:11 -0400
commit7c8a7221a4e3d926c419e1d681db450835733aef (patch)
tree3497333f4e0ccafa57cb652d9619929060b79f85
parent32b968ce443a840b51e605e8a29408aa903aa6bf (diff)
downloadrust-7c8a7221a4e3d926c419e1d681db450835733aef.tar.gz
rust-7c8a7221a4e3d926c419e1d681db450835733aef.zip
create a seperate module for outlives. added a query for inferred_outlives. setup some files for upcoming tests
-rw-r--r--src/librustc/ty/maps/mod.rs2
-rw-r--r--src/librustc_typeck/collect.rs9
-rw-r--r--src/librustc_typeck/lib.rs8
-rw-r--r--src/librustc_typeck/outlives/mod.rs22
-rw-r--r--src/librustc_typeck/outlives/test.rs41
5 files changed, 73 insertions, 9 deletions
diff --git a/src/librustc/ty/maps/mod.rs b/src/librustc/ty/maps/mod.rs
index e14a77ea93b..d13de98df28 100644
--- a/src/librustc/ty/maps/mod.rs
+++ b/src/librustc/ty/maps/mod.rs
@@ -122,7 +122,7 @@ define_maps! { <'tcx>
     [] fn variances_of: ItemVariances(DefId) -> Rc<Vec<ty::Variance>>,
 
     /// Maps from def-id of a type to its (inferred) outlives.
-    [] fn inferred_outlives_of: PredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>,
+    [] fn inferred_outlives_of: PredicatesOfItem(DefId) -> Vec<ty::Predicate<'tcx>>,
 
     /// Maps from an impl/trait def-id to a list of the def-ids of its items
     [] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 9a66f07cba4..a5b3f8cb806 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -1329,20 +1329,13 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
         })
 }
 
-//todo
-fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                           _def_id: DefId)
-                           -> Vec<ty::Predicate<'tcx>> {
-    Vec::new()
-}
-
 fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                            def_id: DefId)
                            -> ty::GenericPredicates<'tcx> {
     let explicit = explicit_predicates_of(tcx, def_id);
     ty::GenericPredicates {
         parent: explicit.parent,
-        predicates: [&explicit.predicates[..], &inferred_outlives_of(tcx, def_id)[..]].concat()
+        predicates: [&explicit.predicates[..], &tcx.inferred_outlives_of(def_id)[..]].concat()
     }
 }
 
diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs
index 1c047ef98d8..9cf954cecc9 100644
--- a/src/librustc_typeck/lib.rs
+++ b/src/librustc_typeck/lib.rs
@@ -50,6 +50,8 @@ independently:
 
 - variance: variance inference
 
+- outlives: outlives inference
+
 - check: walks over function bodies and type checks them, inferring types for
   local variables, type parameters, etc as necessary.
 
@@ -122,6 +124,7 @@ mod collect;
 mod constrained_type_params;
 mod impl_wf_check;
 mod coherence;
+mod outlives;
 mod variance;
 mod namespace;
 
@@ -316,6 +319,11 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
              variance::test::test_variance(tcx));
     })?;
 
+//    tcx.sess.track_errors(|| {
+//        time(time_passes, "outlives testing", ||
+//            outlives::test::test_inferred_outlives(tcx));
+//    })?;
+
     time(time_passes, "wf checking", || check::check_wf_new(tcx))?;
 
     time(time_passes, "item-types checking", || check::check_item_types(tcx))?;
diff --git a/src/librustc_typeck/outlives/mod.rs b/src/librustc_typeck/outlives/mod.rs
new file mode 100644
index 00000000000..d496ed0e46d
--- /dev/null
+++ b/src/librustc_typeck/outlives/mod.rs
@@ -0,0 +1,22 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use rustc::hir::def_id::DefId;
+use rustc::ty::{self, TyCtxt};
+
+/// Code to write unit test for outlives.
+pub mod test;
+
+//todo
+pub fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                                  _def_id: DefId)
+                                  -> Vec<ty::Predicate<'tcx>> {
+    Vec::new()
+}
diff --git a/src/librustc_typeck/outlives/test.rs b/src/librustc_typeck/outlives/test.rs
new file mode 100644
index 00000000000..0d45fc58637
--- /dev/null
+++ b/src/librustc_typeck/outlives/test.rs
@@ -0,0 +1,41 @@
+// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//use rustc::hir;
+//use rustc::hir::itemlikevisit::ItemLikeVisitor;
+use rustc::ty::TyCtxt;
+
+//pub fn test_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
+//    tcx.hir.krate().visit_all_item_likes(&mut OutlivesTest { tcx });
+//}
+
+struct OutlivesTest<'a, 'tcx: 'a> {
+    tcx: TyCtxt<'a, 'tcx, 'tcx>
+}
+
+//impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
+//    fn visit_item(&mut self, item: &'tcx hir::Item) {
+//        let item_def_id = self.tcx.hir.local_def_id(item.id);
+//
+//        // For unit testing: check for a special "rustc_outlives"
+//        // attribute and report an error with various results if found.
+//        if self.tcx.has_attr(item_def_id, "rustc_outlives") {
+//            let outlives_of = self.tcx.outlives_of(item_def_id);
+//            span_err!(self.tcx.sess,
+//                      item.span,
+//                      E0208,
+//                      "{:?}",
+//                      outlives_of);
+//        }
+//    }
+//
+//    fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { }
+//    fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
+//}