Skip to content

Commit 7c8a722

Browse files
author
toidiu
committed
create a seperate module for outlives. added a query for inferred_outlives. setup some files for upcoming tests
1 parent 32b968c commit 7c8a722

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
lines changed

src/librustc/ty/maps/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ define_maps! { <'tcx>
122122
[] fn variances_of: ItemVariances(DefId) -> Rc<Vec<ty::Variance>>,
123123

124124
/// Maps from def-id of a type to its (inferred) outlives.
125-
[] fn inferred_outlives_of: PredicatesOfItem(DefId) -> ty::GenericPredicates<'tcx>,
125+
[] fn inferred_outlives_of: PredicatesOfItem(DefId) -> Vec<ty::Predicate<'tcx>>,
126126

127127
/// Maps from an impl/trait def-id to a list of the def-ids of its items
128128
[] fn associated_item_def_ids: AssociatedItemDefIds(DefId) -> Rc<Vec<DefId>>,

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,20 +1329,13 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>(
13291329
})
13301330
}
13311331

1332-
//todo
1333-
fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
1334-
_def_id: DefId)
1335-
-> Vec<ty::Predicate<'tcx>> {
1336-
Vec::new()
1337-
}
1338-
13391332
fn predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13401333
def_id: DefId)
13411334
-> ty::GenericPredicates<'tcx> {
13421335
let explicit = explicit_predicates_of(tcx, def_id);
13431336
ty::GenericPredicates {
13441337
parent: explicit.parent,
1345-
predicates: [&explicit.predicates[..], &inferred_outlives_of(tcx, def_id)[..]].concat()
1338+
predicates: [&explicit.predicates[..], &tcx.inferred_outlives_of(def_id)[..]].concat()
13461339
}
13471340
}
13481341

src/librustc_typeck/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ independently:
5050
5151
- variance: variance inference
5252
53+
- outlives: outlives inference
54+
5355
- check: walks over function bodies and type checks them, inferring types for
5456
local variables, type parameters, etc as necessary.
5557
@@ -122,6 +124,7 @@ mod collect;
122124
mod constrained_type_params;
123125
mod impl_wf_check;
124126
mod coherence;
127+
mod outlives;
125128
mod variance;
126129
mod namespace;
127130

@@ -316,6 +319,11 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
316319
variance::test::test_variance(tcx));
317320
})?;
318321

322+
// tcx.sess.track_errors(|| {
323+
// time(time_passes, "outlives testing", ||
324+
// outlives::test::test_inferred_outlives(tcx));
325+
// })?;
326+
319327
time(time_passes, "wf checking", || check::check_wf_new(tcx))?;
320328

321329
time(time_passes, "item-types checking", || check::check_item_types(tcx))?;

src/librustc_typeck/outlives/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use rustc::hir::def_id::DefId;
12+
use rustc::ty::{self, TyCtxt};
13+
14+
/// Code to write unit test for outlives.
15+
pub mod test;
16+
17+
//todo
18+
pub fn inferred_outlives_of<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
19+
_def_id: DefId)
20+
-> Vec<ty::Predicate<'tcx>> {
21+
Vec::new()
22+
}

src/librustc_typeck/outlives/test.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//use rustc::hir;
12+
//use rustc::hir::itemlikevisit::ItemLikeVisitor;
13+
use rustc::ty::TyCtxt;
14+
15+
//pub fn test_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
16+
// tcx.hir.krate().visit_all_item_likes(&mut OutlivesTest { tcx });
17+
//}
18+
19+
struct OutlivesTest<'a, 'tcx: 'a> {
20+
tcx: TyCtxt<'a, 'tcx, 'tcx>
21+
}
22+
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+
//}

0 commit comments

Comments
 (0)