Skip to content

Commit ba1efa3

Browse files
author
toidiu
committed
added components for testing. added outlives test to the check_crate function of librustc_typeck
1 parent 7c8a722 commit ba1efa3

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4679,4 +4679,5 @@ register_diagnostics! {
46794679
E0627, // yield statement outside of generator literal
46804680
E0632, // cannot provide explicit type parameters when `impl Trait` is used in
46814681
// argument position.
4682+
E0628, // infer outlives
46824683
}

src/librustc_typeck/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ pub fn provide(providers: &mut Providers) {
289289
coherence::provide(providers);
290290
check::provide(providers);
291291
variance::provide(providers);
292+
outlives::provide(providers);
292293
}
293294

294295
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>)
319320
variance::test::test_variance(tcx));
320321
})?;
321322

322-
// tcx.sess.track_errors(|| {
323-
// time(time_passes, "outlives testing", ||
324-
// outlives::test::test_inferred_outlives(tcx));
325-
// })?;
323+
tcx.sess.track_errors(|| {
324+
time(time_passes, "outlives testing", ||
325+
outlives::test::test_inferred_outlives(tcx));
326+
})?;
326327

327328
time(time_passes, "wf checking", || check::check_wf_new(tcx))?;
328329

src/librustc_typeck/outlives/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010

1111
use rustc::hir::def_id::DefId;
1212
use rustc::ty::{self, TyCtxt};
13+
use rustc::ty::maps::Providers;
1314

1415
/// Code to write unit test for outlives.
1516
pub mod test;
1617

18+
pub fn provide(providers: &mut Providers) {
19+
*providers = Providers {
20+
inferred_outlives_of,
21+
..*providers
22+
};
23+
}
24+
1725
//todo
18-
pub fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
19-
_def_id: DefId)
26+
fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>, _def_id: DefId)
2027
-> Vec<ty::Predicate<'tcx>> {
2128
Vec::new()
2229
}

src/librustc_typeck/outlives/test.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//use rustc::hir;
12-
//use rustc::hir::itemlikevisit::ItemLikeVisitor;
11+
use rustc::hir;
12+
use rustc::hir::itemlikevisit::ItemLikeVisitor;
1313
use rustc::ty::TyCtxt;
1414

15-
//pub fn test_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
16-
// tcx.hir.krate().visit_all_item_likes(&mut OutlivesTest { tcx });
17-
//}
15+
pub fn test_inferred_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
16+
tcx.hir.krate().visit_all_item_likes(&mut OutlivesTest { tcx });
17+
}
1818

1919
struct OutlivesTest<'a, 'tcx: 'a> {
2020
tcx: TyCtxt<'a, 'tcx, 'tcx>
2121
}
2222

23-
//impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
24-
// fn visit_item(&mut self, item: &'tcx hir::Item) {
25-
// let item_def_id = self.tcx.hir.local_def_id(item.id);
26-
//
27-
// // For unit testing: check for a special "rustc_outlives"
28-
// // attribute and report an error with various results if found.
29-
// if self.tcx.has_attr(item_def_id, "rustc_outlives") {
30-
// let outlives_of = self.tcx.outlives_of(item_def_id);
31-
// span_err!(self.tcx.sess,
32-
// item.span,
33-
// E0208,
34-
// "{:?}",
35-
// outlives_of);
36-
// }
37-
// }
38-
//
39-
// fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { }
40-
// fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
41-
//}
23+
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
24+
fn visit_item(&mut self, item: &'tcx hir::Item) {
25+
let item_def_id = self.tcx.hir.local_def_id(item.id);
26+
27+
// For unit testing: check for a special "rustc_outlives"
28+
// attribute and report an error with various results if found.
29+
if self.tcx.has_attr(item_def_id, "rustc_outlives") {
30+
let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
31+
span_err!(self.tcx.sess,
32+
item.span,
33+
E0628,
34+
"{:?}",
35+
inferred_outlives_of);
36+
}
37+
}
38+
39+
fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) { }
40+
fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) { }
41+
}

0 commit comments

Comments
 (0)