]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/variance/test.rs
change various uses of `item_variances` to `variances_of`
[rust.git] / src / librustc_typeck / variance / 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_variance<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
16     tcx.hir.krate().visit_all_item_likes(&mut VarianceTest { tcx });
17 }
18
19 struct VarianceTest<'a, 'tcx: 'a> {
20     tcx: TyCtxt<'a, 'tcx, 'tcx>
21 }
22
23 impl<'a, 'tcx> ItemLikeVisitor<'tcx> for VarianceTest<'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_variance"
28         // attribute and report an error with various results if found.
29         if self.tcx.has_attr(item_def_id, "rustc_variance") {
30             let variances_of = self.tcx.variances_of(item_def_id);
31             span_err!(self.tcx.sess,
32                       item.span,
33                       E0208,
34                       "{:?}",
35                       variances_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 }