Skip to content

Commit

Permalink
Skip dead code checks on items that failed typeck
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 16, 2024
1 parent 9a8f117 commit 0787a5f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {

impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
fn visit_nested_body(&mut self, body: hir::BodyId) {
let old_maybe_typeck_results =
self.maybe_typeck_results.replace(self.tcx.typeck_body(body));
let typeck_results = self.tcx.typeck_body(body);
if typeck_results.tainted_by_errors.is_some() {
return;
}
let old_maybe_typeck_results = self.maybe_typeck_results.replace(typeck_results);
let body = self.tcx.hir().body(body);
self.visit_body(body);
self.maybe_typeck_results = old_maybe_typeck_results;
Expand Down
10 changes: 9 additions & 1 deletion tests/ui/consts/const-eval/infinite_loop.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
//! This test tests two things at once:
//! 1. we error if a const evaluation hits the deny-by-default lint limit
//! 2. we do not ICE on invalid follow-up code
// compile-flags: -Z tiny-const-eval-limit

fn main() {
// Tests the Collatz conjecture with an incorrect base case (0 instead of 1).
// The value of `n` will loop indefinitely (4 - 2 - 1 - 4).
let _ = [(); {
let s = [(); {
let mut n = 113383; // #20 in https://oeis.org/A006884
while n != 0 {
//~^ ERROR is taking a long time
n = if n % 2 == 0 { n / 2 } else { 3 * n + 1 };
}
n
}];

s.nonexistent_method();
}
6 changes: 3 additions & 3 deletions tests/ui/consts/const-eval/infinite_loop.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: constant evaluation is taking a long time
--> $DIR/infinite_loop.rs:6:9
--> $DIR/infinite_loop.rs:12:9
|
LL | / while n != 0 {
LL | |
Expand All @@ -10,9 +10,9 @@ LL | | }
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
If your compilation actually takes a long time, you can safely allow the lint.
help: the constant being evaluated
--> $DIR/infinite_loop.rs:4:18
--> $DIR/infinite_loop.rs:10:18
|
LL | let _ = [(); {
LL | let s = [(); {
| __________________^
LL | | let mut n = 113383; // #20 in https://oeis.org/A006884
LL | | while n != 0 {
Expand Down

0 comments on commit 0787a5f

Please sign in to comment.