Skip to content

Commit

Permalink
Fix crash in late internal checking
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Mar 8, 2024
1 parent 9823f17 commit 2a8fcc2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,15 @@ impl LateLintPass<'_> for Diagnostics {
_ => return, // occurs for fns passed as args
}
}
ExprKind::MethodCall(segment, _recv, args, _span) => {
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
let fn_gen_args = cx.typeck_results().node_args(expr.hir_id);
ExprKind::MethodCall(_segment, _recv, args, _span) => {
let Some((span, def_id, fn_gen_args)) = typeck_results_of_method_fn(cx, expr)
else {
return;
};
let mut call_tys: Vec<_> =
args.iter().map(|arg| cx.typeck_results().expr_ty(arg)).collect();
call_tys.insert(0, cx.tcx.types.self_param); // dummy inserted for `self`
(segment.ident.span, def_id, fn_gen_args, call_tys)
(span, def_id, fn_gen_args, call_tys)
}
_ => return,
};
Expand Down
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:12:9
--> $DIR/infinite_loop.rs:15:9
|
LL | / while n != 0 {
LL | |
Expand All @@ -10,7 +10,7 @@ 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:10:18
--> $DIR/infinite_loop.rs:13:18
|
LL | let s = [(); {
| __________________^
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/consts/const-eval/infinite_loop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! 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
//! 3. no ICE when run with `-Z unstable-options` (issue 122177)
//@revisions: no_ice
//@[no_ice] compile-flags: -Zunstable-options
//@ compile-flags: -Z tiny-const-eval-limit

fn main() {
Expand Down

0 comments on commit 2a8fcc2

Please sign in to comment.