Skip to content

Commit 63a1eee

Browse files
committed
Reset LateContext enclosing body in nested items
Prevents LateContext::maybe_typeck_results() from returning data in a nested item without a body. Consequently, LateContext::qpath_res is less likely to ICE when called in a nested item. Would have prevented rust-lang/rust-clippy#4545, presumably.
1 parent 5e91c4e commit 63a1eee

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compiler/rustc_lint/src/late.rs

+4
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,17 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
140140
fn visit_item(&mut self, it: &'tcx hir::Item<'tcx>) {
141141
let generics = self.context.generics.take();
142142
self.context.generics = it.kind.generics();
143+
let old_cached_typeck_results = self.context.cached_typeck_results.take();
144+
let old_enclosing_body = self.context.enclosing_body.take();
143145
self.with_lint_attrs(it.hir_id, &it.attrs, |cx| {
144146
cx.with_param_env(it.hir_id, |cx| {
145147
lint_callback!(cx, check_item, it);
146148
hir_visit::walk_item(cx, it);
147149
lint_callback!(cx, check_item_post, it);
148150
});
149151
});
152+
self.context.enclosing_body = old_enclosing_body;
153+
self.context.cached_typeck_results.set(old_cached_typeck_results);
150154
self.context.generics = generics;
151155
}
152156

0 commit comments

Comments
 (0)