Skip to content

Commit a08a5d4

Browse files
authored
Rollup merge of rust-lang#122181 - chenyukang:yukang-fix-late-lint-crash, r=oli-obk
Fix crash in internal late lint checking Fixes rust-lang#122177
2 parents 9fd60c5 + c81521a commit a08a5d4

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
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.eval_limit.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
| __________________^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: constant evaluation is taking a long time
2+
--> $DIR/infinite_loop.rs:15:9
3+
|
4+
LL | / while n != 0 {
5+
LL | |
6+
LL | | n = if n % 2 == 0 { n / 2 } else { 3 * n + 1 };
7+
LL | | }
8+
| |_________^
9+
|
10+
= note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval.
11+
If your compilation actually takes a long time, you can safely allow the lint.
12+
help: the constant being evaluated
13+
--> $DIR/infinite_loop.rs:13:18
14+
|
15+
LL | let s = [(); {
16+
| __________________^
17+
LL | | let mut n = 113383; // #20 in https://oeis.org/A006884
18+
LL | | while n != 0 {
19+
LL | |
20+
... |
21+
LL | | n
22+
LL | | }];
23+
| |_____^
24+
= note: `#[deny(long_running_const_eval)]` on by default
25+
26+
error: aborting due to 1 previous error
27+

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
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
5-
//@ compile-flags: -Z tiny-const-eval-limit
6+
//@revisions: eval_limit no_ice
7+
//@[no_ice] compile-flags: -Z tiny-const-eval-limit -Z unstable-options
8+
//@[eval_limit] compile-flags: -Z tiny-const-eval-limit
69

710
fn main() {
811
// Tests the Collatz conjecture with an incorrect base case (0 instead of 1).

0 commit comments

Comments
 (0)