Skip to content

Commit d7ab07b

Browse files
committed
merge typeck_body call into existing if block
1 parent 2f88da8 commit d7ab07b

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

‎compiler/rustc_lint/src/late.rs‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,21 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
9393
}
9494

9595
fn visit_nested_body(&mut self, body_id: hir::BodyId) {
96-
// The typeck_result shouldn't be tainted, otherwise it will cause ICE.
97-
// If rustdoc is the caller of this function, we shouldn't run typeck_body here.
98-
if !self.context.tcx.sess.opts.actually_rustdoc
99-
&& self.context.tcx.typeck_body(body_id).tainted_by_errors.is_some()
100-
{
101-
return;
102-
}
103-
10496
let old_enclosing_body = self.context.enclosing_body.replace(body_id);
10597
let old_typeck_results = self.context.typeck_results;
10698

10799
// The body and typeck results are also set in `visit_fn`.
108100
// Only fetch the results if this is for a new body.
109101
if old_enclosing_body != Some(body_id) && !self.actually_rustdoc {
110-
self.context.typeck_results = Some(self.context.tcx.typeck_body(body_id));
102+
let typeck_results = self.context.tcx.typeck_body(body_id);
103+
104+
// To avoid ICE, skip visiting the body if the typeck_results is tainted.
105+
if typeck_results.tainted_by_errors.is_some() {
106+
self.context.enclosing_body = old_enclosing_body;
107+
self.context.typeck_results = old_typeck_results;
108+
return;
109+
}
110+
self.context.typeck_results = Some(typeck_results);
111111
}
112112

113113
let body = self.context.tcx.hir_body(body_id);
@@ -197,7 +197,16 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
197197
let old_enclosing_body = self.context.enclosing_body.replace(body_id);
198198
let old_typeck_results = self.context.typeck_results;
199199
if !self.actually_rustdoc {
200-
self.context.typeck_results = Some(self.context.tcx.typeck_body(body_id));
200+
let typeck_results = self.context.tcx.typeck_body(body_id);
201+
202+
// To avoid ICE, skip visiting the body if the typeck_results is tainted.
203+
if typeck_results.tainted_by_errors.is_some() {
204+
self.context.enclosing_body = old_enclosing_body;
205+
self.context.typeck_results = old_typeck_results;
206+
return;
207+
}
208+
209+
self.context.typeck_results = Some(typeck_results);
201210
}
202211
let body = self.context.tcx.hir_body(body_id);
203212
lint_callback!(self, check_fn, fk, decl, body, span, id);

0 commit comments

Comments
 (0)