|
1 | 1 | use rustc_errors::struct_span_err;
|
2 |
| -use rustc_hir as hir; |
3 |
| -use rustc_hir::itemlikevisit::ItemLikeVisitor; |
4 | 2 | use rustc_middle::ty::TyCtxt;
|
5 | 3 | use rustc_span::symbol::sym;
|
6 | 4 |
|
7 | 5 | pub fn test_variance(tcx: TyCtxt<'_>) {
|
8 |
| - tcx.hir().visit_all_item_likes(&mut VarianceTest { tcx }); |
9 |
| -} |
10 |
| - |
11 |
| -struct VarianceTest<'tcx> { |
12 |
| - tcx: TyCtxt<'tcx>, |
13 |
| -} |
14 |
| - |
15 |
| -impl<'tcx> ItemLikeVisitor<'tcx> for VarianceTest<'tcx> { |
16 |
| - fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { |
17 |
| - // For unit testing: check for a special "rustc_variance" |
18 |
| - // attribute and report an error with various results if found. |
19 |
| - if self.tcx.has_attr(item.def_id.to_def_id(), sym::rustc_variance) { |
20 |
| - let variances_of = self.tcx.variances_of(item.def_id); |
21 |
| - struct_span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of).emit(); |
| 6 | + // For unit testing: check for a special "rustc_variance" |
| 7 | + // attribute and report an error with various results if found. |
| 8 | + for id in tcx.hir().items() { |
| 9 | + if tcx.has_attr(id.def_id.to_def_id(), sym::rustc_variance) { |
| 10 | + let variances_of = tcx.variances_of(id.def_id); |
| 11 | + struct_span_err!(tcx.sess, tcx.hir().span(id.hir_id()), E0208, "{:?}", variances_of) |
| 12 | + .emit(); |
22 | 13 | }
|
23 | 14 | }
|
24 |
| - |
25 |
| - fn visit_trait_item(&mut self, _: &'tcx hir::TraitItem<'tcx>) {} |
26 |
| - fn visit_impl_item(&mut self, _: &'tcx hir::ImplItem<'tcx>) {} |
27 |
| - fn visit_foreign_item(&mut self, _: &'tcx hir::ForeignItem<'tcx>) {} |
28 | 15 | }
|
0 commit comments