Skip to content

Commit 2a8fcc2

Browse files
committed
Fix crash in late internal checking
1 parent 9823f17 commit 2a8fcc2

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

compiler/rustc_lint/src/internal.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,15 @@ impl LateLintPass<'_> for Diagnostics {
379379
_ => return, // occurs for fns passed as args
380380
}
381381
}
382-
ExprKind::MethodCall(segment, _recv, args, _span) => {
383-
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
384-
let fn_gen_args = cx.typeck_results().node_args(expr.hir_id);
382+
ExprKind::MethodCall(_segment, _recv, args, _span) => {
383+
let Some((span, def_id, fn_gen_args)) = typeck_results_of_method_fn(cx, expr)
384+
else {
385+
return;
386+
};
385387
let mut call_tys: Vec<_> =
386388
args.iter().map(|arg| cx.typeck_results().expr_ty(arg)).collect();
387389
call_tys.insert(0, cx.tcx.types.self_param); // dummy inserted for `self`
388-
(segment.ident.span, def_id, fn_gen_args, call_tys)
390+
(span, def_id, fn_gen_args, call_tys)
389391
}
390392
_ => return,
391393
};

tests/ui/consts/const-eval/infinite_loop.stderr renamed to tests/ui/consts/const-eval/infinite_loop.no_ice.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: constant evaluation is taking a long time
2-
--> $DIR/infinite_loop.rs:12:9
2+
--> $DIR/infinite_loop.rs:15:9
33
|
44
LL | / while n != 0 {
55
LL | |
@@ -10,7 +10,7 @@ LL | | }
1010
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
1111
If your compilation actually takes a long time, you can safely allow the lint.
1212
help: the constant being evaluated
13-
--> $DIR/infinite_loop.rs:10:18
13+
--> $DIR/infinite_loop.rs:13:18
1414
|
1515
LL | let s = [(); {
1616
| __________________^

tests/ui/consts/const-eval/infinite_loop.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! This test tests two things at once:
22
//! 1. we error if a const evaluation hits the deny-by-default lint limit
33
//! 2. we do not ICE on invalid follow-up code
4+
//! 3. no ICE when run with `-Z unstable-options` (issue 122177)
45
6+
//@revisions: no_ice
7+
//@[no_ice] compile-flags: -Zunstable-options
58
//@ compile-flags: -Z tiny-const-eval-limit
69

710
fn main() {

0 commit comments

Comments
 (0)