fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
let generics = self.context.generics.take();
self.context.generics = it.kind.generics();
+ let old_cached_typeck_results = self.context.cached_typeck_results.take();
+ let old_enclosing_body = self.context.enclosing_body.take();
self.with_lint_attrs(it.hir_id, &it.attrs, |cx| {
cx.with_param_env(it.hir_id, |cx| {
lint_callback!(cx, check_item, it);
lint_callback!(cx, check_item_post, it);
});
});
+ self.context.enclosing_body = old_enclosing_body;
+ self.context.cached_typeck_results.set(old_cached_typeck_results);
self.context.generics = generics;
}
}
fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
- // statement attributes are actually just attributes on one of
- // - item
- // - local
- // - expression
- // so we keep track of lint levels there
- lint_callback!(self, check_stmt, s);
+ let get_item = |id: hir::ItemId| self.context.tcx.hir().item(id.id);
+ let attrs = &s.kind.attrs(get_item);
+ // See `EarlyContextAndPass::visit_stmt` for an explanation
+ // of why we call `walk_stmt` outside of `with_lint_attrs`
+ self.with_lint_attrs(s.hir_id, attrs, |cx| {
+ lint_callback!(cx, check_stmt, s);
+ });
hir_visit::walk_stmt(self, s);
}