about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryukang <moorekang@gmail.com>2024-03-08 15:09:53 +0800
committeryukang <moorekang@gmail.com>2024-03-08 19:00:53 +0800
commitc81521ae545faf9e2b6c212f9e3faea69fde4d01 (patch)
tree4943c20b07d0341c473ea9569245967d56b6f27f
parent9823f173150baf893b2491513466ac024ae63e40 (diff)
downloadrust-c81521ae545faf9e2b6c212f9e3faea69fde4d01.tar.gz
rust-c81521ae545faf9e2b6c212f9e3faea69fde4d01.zip
Fix crash in late internal checking
-rw-r--r--compiler/rustc_lint/src/internal.rs10
-rw-r--r--tests/ui/consts/const-eval/infinite_loop.eval_limit.stderr (renamed from tests/ui/consts/const-eval/infinite_loop.stderr)4
-rw-r--r--tests/ui/consts/const-eval/infinite_loop.no_ice.stderr27
-rw-r--r--tests/ui/consts/const-eval/infinite_loop.rs5
4 files changed, 39 insertions, 7 deletions
diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs
index 3a8c8e79b4f..e8fcf4132ea 100644
--- a/compiler/rustc_lint/src/internal.rs
+++ b/compiler/rustc_lint/src/internal.rs
@@ -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,
         };
diff --git a/tests/ui/consts/const-eval/infinite_loop.stderr b/tests/ui/consts/const-eval/infinite_loop.eval_limit.stderr
index 37cd94bf7b7..d664ae88323 100644
--- a/tests/ui/consts/const-eval/infinite_loop.stderr
+++ b/tests/ui/consts/const-eval/infinite_loop.eval_limit.stderr
@@ -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 | |
@@ -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 = [(); {
    |  __________________^
diff --git a/tests/ui/consts/const-eval/infinite_loop.no_ice.stderr b/tests/ui/consts/const-eval/infinite_loop.no_ice.stderr
new file mode 100644
index 00000000000..d664ae88323
--- /dev/null
+++ b/tests/ui/consts/const-eval/infinite_loop.no_ice.stderr
@@ -0,0 +1,27 @@
+error: constant evaluation is taking a long time
+  --> $DIR/infinite_loop.rs:15:9
+   |
+LL | /         while n != 0 {
+LL | |
+LL | |             n = if n % 2 == 0 { n / 2 } else { 3 * n + 1 };
+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:13:18
+   |
+LL |       let s = [(); {
+   |  __________________^
+LL | |         let mut n = 113383; // #20 in https://oeis.org/A006884
+LL | |         while n != 0 {
+LL | |
+...  |
+LL | |         n
+LL | |     }];
+   | |_____^
+   = note: `#[deny(long_running_const_eval)]` on by default
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/consts/const-eval/infinite_loop.rs b/tests/ui/consts/const-eval/infinite_loop.rs
index 44456f1ce47..f8cb79b63db 100644
--- a/tests/ui/consts/const-eval/infinite_loop.rs
+++ b/tests/ui/consts/const-eval/infinite_loop.rs
@@ -1,8 +1,11 @@
 //! 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)
 
-//@ compile-flags: -Z tiny-const-eval-limit
+//@revisions: eval_limit no_ice
+//@[no_ice] compile-flags: -Z tiny-const-eval-limit -Z unstable-options
+//@[eval_limit] compile-flags: -Z tiny-const-eval-limit
 
 fn main() {
     // Tests the Collatz conjecture with an incorrect base case (0 instead of 1).