create a seperate module for outlives. added a query for inferred_outlives. setup some files for upcoming tests

This commit is contained in:
toidiu 2017-09-27 20:18:41 -04:00
parent 32b968ce44
commit 7c8a7221a4
5 changed files with 73 additions and 9 deletions

View file

@ -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>>,

View file

@ -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()
}
}

View file

@ -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))?;

View file

@ -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()
}

View file

@ -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) { }
//}