added components for testing. added outlives test to the check_crate function of librustc_typeck
This commit is contained in:
parent
7c8a7221a4
commit
ba1efa3b61
@ -4679,4 +4679,5 @@ register_diagnostics! {
|
||||
E0627, // yield statement outside of generator literal
|
||||
E0632, // cannot provide explicit type parameters when `impl Trait` is used in
|
||||
// argument position.
|
||||
E0628, // infer outlives
|
||||
}
|
||||
|
@ -289,6 +289,7 @@ pub fn provide(providers: &mut Providers) {
|
||||
coherence::provide(providers);
|
||||
check::provide(providers);
|
||||
variance::provide(providers);
|
||||
outlives::provide(providers);
|
||||
}
|
||||
|
||||
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
|
||||
@ -319,10 +320,10 @@ 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));
|
||||
// })?;
|
||||
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))?;
|
||||
|
||||
|
@ -10,13 +10,20 @@
|
||||
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::ty::{self, TyCtxt};
|
||||
use rustc::ty::maps::Providers;
|
||||
|
||||
/// Code to write unit test for outlives.
|
||||
pub mod test;
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
*providers = Providers {
|
||||
inferred_outlives_of,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
||||
//todo
|
||||
pub fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
_def_id: DefId)
|
||||
fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>, _def_id: DefId)
|
||||
-> Vec<ty::Predicate<'tcx>> {
|
||||
Vec::new()
|
||||
}
|
||||
|
@ -8,34 +8,34 @@
|
||||
// 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::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 });
|
||||
//}
|
||||
pub fn test_inferred_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) { }
|
||||
//}
|
||||
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 inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
|
||||
span_err!(self.tcx.sess,
|
||||
item.span,
|
||||
E0628,
|
||||
"{:?}",
|
||||
inferred_outlives_of);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { }
|
||||
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user