Skip to content

Commit 99a71dc

Browse files
authored
Rollup merge of #109856 - bvanjoi:fix-issue-109304, r=compiler-errors
fix(middle): emit error rather than delay bug when reaching limit close #109304
2 parents f2f5efc + d8a4e7c commit 99a71dc

File tree

6 files changed

+26
-81
lines changed

6 files changed

+26
-81
lines changed

compiler/rustc_middle/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ middle_limit_invalid =
1616
`limit` must be a non-negative integer
1717
.label = {$error_str}
1818
19+
middle_recursion_limit_reached =
20+
reached the recursion limit finding the struct tail for `{$ty}`
21+
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]`
22+
1923
middle_const_eval_non_int =
2024
constant evaluation of enum discriminant resulted in non-integer
2125

compiler/rustc_middle/src/error.rs

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ pub struct LimitInvalid<'a> {
4949
pub error_str: &'a str,
5050
}
5151

52+
#[derive(Diagnostic)]
53+
#[diag(middle_recursion_limit_reached)]
54+
#[help]
55+
pub struct RecursionLimitReached<'tcx> {
56+
pub ty: Ty<'tcx>,
57+
pub suggested_limit: rustc_session::Limit,
58+
}
59+
5260
#[derive(Diagnostic)]
5361
#[diag(middle_const_eval_non_int)]
5462
pub struct ConstEvalNonIntError {

compiler/rustc_middle/src/ty/util.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use rustc_hir::def_id::{DefId, LocalDefId};
1919
use rustc_index::bit_set::GrowableBitSet;
2020
use rustc_index::vec::{Idx, IndexVec};
2121
use rustc_macros::HashStable;
22-
use rustc_span::{sym, DUMMY_SP};
22+
use rustc_session::Limit;
23+
use rustc_span::sym;
2324
use rustc_target::abi::{Integer, IntegerType, Size, TargetDataLayout};
2425
use rustc_target::spec::abi::Abi;
2526
use smallvec::SmallVec;
@@ -225,10 +226,13 @@ impl<'tcx> TyCtxt<'tcx> {
225226
let recursion_limit = self.recursion_limit();
226227
for iteration in 0.. {
227228
if !recursion_limit.value_within_limit(iteration) {
228-
return self.ty_error_with_message(
229-
DUMMY_SP,
230-
&format!("reached the recursion limit finding the struct tail for {}", ty),
231-
);
229+
let suggested_limit = match recursion_limit {
230+
Limit(0) => Limit(2),
231+
limit => limit * 2,
232+
};
233+
let reported =
234+
self.sess.emit_err(crate::error::RecursionLimitReached { ty, suggested_limit });
235+
return self.ty_error(reported);
232236
}
233237
match *ty.kind() {
234238
ty::Adt(def, substs) => {

tests/ui/autoref-autoderef/issue-38940.rs

-52
This file was deleted.

tests/ui/autoref-autoderef/issue-38940.stderr

-23
This file was deleted.

tests/ui/did_you_mean/recursion_limit_deref.stderr

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
error: reached the recursion limit finding the struct tail for `Bottom`
2+
|
3+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`
4+
15
error[E0055]: reached the recursion limit while auto-dereferencing `J`
26
--> $DIR/recursion_limit_deref.rs:51:22
37
|
@@ -17,7 +21,7 @@ LL | let x: &Bottom = &t;
1721
= note: expected reference `&Bottom`
1822
found reference `&Top`
1923

20-
error: aborting due to 2 previous errors
24+
error: aborting due to 3 previous errors
2125

2226
Some errors have detailed explanations: E0055, E0308.
2327
For more information about an error, try `rustc --explain E0055`.

0 commit comments

Comments
 (0)