]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/outlives/test.rs
Rollup merge of #62379 - GuillaumeGomez:option-doc-links, r=QuietMisdreavus
[rust.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 pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
7     tcx.hir()
8        .krate()
9        .visit_all_item_likes(&mut OutlivesTest { tcx });
10 }
11
12 struct OutlivesTest<'tcx> {
13     tcx: TyCtxt<'tcx>,
14 }
15
16 impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> {
17     fn visit_item(&mut self, item: &'tcx hir::Item) {
18         let item_def_id = self.tcx.hir().local_def_id(item.hir_id);
19
20         // For unit testing: check for a special "rustc_outlives"
21         // attribute and report an error with various results if found.
22         if self.tcx.has_attr(item_def_id, sym::rustc_outlives) {
23             let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
24             span_err!(
25                 self.tcx.sess,
26                 item.span,
27                 E0640,
28                 "{:?}",
29                 inferred_outlives_of
30             );
31         }
32     }
33
34     fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem) {}
35     fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem) {}
36 }