]> git.proxmox.com Git - rustc.git/blob - src/librustc_typeck/outlives/test.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / librustc_typeck / outlives / test.rs
1 use rustc::hir;
2 use rustc::hir::itemlikevisit::ItemLikeVisitor;
3 use rustc::ty::TyCtxt;
4 use syntax::symbol::sym;
5
6 use rustc_error_codes::*;
7
8 pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
9 tcx.hir()
10 .krate()
11 .visit_all_item_likes(&mut OutlivesTest { tcx });
12 }
13
14 struct OutlivesTest<'tcx> {
15 tcx: TyCtxt<'tcx>,
16 }
17
18 impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> {
19 fn visit_item(&mut self, item: &'tcx hir::Item) {
20 let item_def_id = self.tcx.hir().local_def_id(item.hir_id);
21
22 // For unit testing: check for a special "rustc_outlives"
23 // attribute and report an error with various results if found.
24 if self.tcx.has_attr(item_def_id, sym::rustc_outlives) {
25 let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
26 span_err!(
27 self.tcx.sess,
28 item.span,
29 E0640,
30 "{:?}",
31 inferred_outlives_of
32 );
33 }
34 }
35
36 fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {}
37 fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {}
38 }