Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle missing typeck information if typeck errored #120020

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1526,13 +1526,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

self.check_repeat_element_needs_copy_bound(element, count, element_ty);

self.register_wf_obligation(
Ty::new_array_with_const_len(tcx, t, count).into(),
expr.span,
traits::WellFormed(None),
);
let ty = Ty::new_array_with_const_len(tcx, t, count);

self.register_wf_obligation(ty.into(), expr.span, traits::WellFormed(None));

Ty::new_array_with_const_len(tcx, t, count)
ty
}

fn check_repeat_element_needs_copy_bound(
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
if let Some(def_id) = self.typeck_results().type_dependent_def_id(id) {
self.check_def_id(def_id);
} else {
bug!("no type-dependent def for method");
assert!(
self.typeck_results().tainted_by_errors.is_some(),
"no type-dependent def for method"
);
}
}

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
Loading