|
| 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.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 inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id); |
| 31 | + span_err!(self.tcx.sess, |
| 32 | + item.span, |
| 33 | + E0640, |
| 34 | + "{:?}", |
| 35 | + inferred_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