]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/outlives/test.rs
Rollup merge of #58931 - estebank:elide-receiver-tyerr, r=varkor
[rust.git] / src / librustc_typeck / outlives / test.rs
1 use rustc::hir;
2 use rustc::hir::itemlikevisit::ItemLikeVisitor;
3 use rustc::ty::TyCtxt;
4
5 pub fn test_inferred_outlives<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
6     tcx.hir()
7        .krate()
8        .visit_all_item_likes(&mut OutlivesTest { tcx });
9 }
10
11 struct OutlivesTest<'a, 'tcx: 'a> {
12     tcx: TyCtxt<'a, 'tcx, 'tcx>,
13 }
14
15 impl<'a, 'tcx> ItemLikeVisitor<'tcx> for OutlivesTest<'a, 'tcx> {
16     fn visit_item(&mut self, item: &'tcx hir::Item) {
17         let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item.hir_id);
18
19         // For unit testing: check for a special "rustc_outlives"
20         // attribute and report an error with various results if found.
21         if self.tcx.has_attr(item_def_id, "rustc_outlives") {
22             let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
23             span_err!(
24                 self.tcx.sess,
25                 item.span,
26                 E0640,
27                 "{:?}",
28                 inferred_outlives_of
29             );
30         }
31     }
32
33     fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {}
34     fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {}
35 }