]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/outlives/test.rs
A few cleanups and minor improvements to typeck
[rust.git] / src / librustc_typeck / outlives / test.rs
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_inferred_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
16     tcx.hir
17        .krate()
18        .visit_all_item_likes(&mut OutlivesTest { tcx });
19 }
20
21 struct OutlivesTest<'a, 'tcx: 'a> {
22     tcx: TyCtxt<'a, 'tcx, 'tcx>,
23 }
24
25 impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
26     fn visit_item(&mut self, item: &'tcx hir::Item) {
27         let item_def_id = self.tcx.hir.local_def_id(item.id);
28
29         // For unit testing: check for a special "rustc_outlives"
30         // attribute and report an error with various results if found.
31         if self.tcx.has_attr(item_def_id, "rustc_outlives") {
32             let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
33             span_err!(
34                 self.tcx.sess,
35                 item.span,
36                 E0640,
37                 "{:?}",
38                 inferred_outlives_of
39             );
40         }
41     }
42
43     fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {}
44     fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {}
45 }