Skip to content

Commit

Permalink
Rollup merge of #109856 - bvanjoi:fix-issue-109304, r=compiler-errors
Browse files Browse the repository at this point in the history
fix(middle): emit error rather than delay bug when reaching limit

close #109304
  • Loading branch information
matthiaskrgr committed Apr 3, 2023
2 parents f2f5efc + d8a4e7c commit 99a71dc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 81 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_middle/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ middle_limit_invalid =
`limit` must be a non-negative integer
.label = {$error_str}
middle_recursion_limit_reached =
reached the recursion limit finding the struct tail for `{$ty}`
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]`
middle_const_eval_non_int =
constant evaluation of enum discriminant resulted in non-integer
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_middle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ pub struct LimitInvalid<'a> {
pub error_str: &'a str,
}

#[derive(Diagnostic)]
#[diag(middle_recursion_limit_reached)]
#[help]
pub struct RecursionLimitReached<'tcx> {
pub ty: Ty<'tcx>,
pub suggested_limit: rustc_session::Limit,
}

#[derive(Diagnostic)]
#[diag(middle_const_eval_non_int)]
pub struct ConstEvalNonIntError {
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_index::bit_set::GrowableBitSet;
use rustc_index::vec::{Idx, IndexVec};
use rustc_macros::HashStable;
use rustc_span::{sym, DUMMY_SP};
use rustc_session::Limit;
use rustc_span::sym;
use rustc_target::abi::{Integer, IntegerType, Size, TargetDataLayout};
use rustc_target::spec::abi::Abi;
use smallvec::SmallVec;
Expand Down Expand Up @@ -225,10 +226,13 @@ impl<'tcx> TyCtxt<'tcx> {
let recursion_limit = self.recursion_limit();
for iteration in 0.. {
if !recursion_limit.value_within_limit(iteration) {
return self.ty_error_with_message(
DUMMY_SP,
&format!("reached the recursion limit finding the struct tail for {}", ty),
);
let suggested_limit = match recursion_limit {
Limit(0) => Limit(2),
limit => limit * 2,
};
let reported =
self.sess.emit_err(crate::error::RecursionLimitReached { ty, suggested_limit });
return self.ty_error(reported);
}
match *ty.kind() {
ty::Adt(def, substs) => {
Expand Down
52 changes: 0 additions & 52 deletions tests/ui/autoref-autoderef/issue-38940.rs

This file was deleted.

23 changes: 0 additions & 23 deletions tests/ui/autoref-autoderef/issue-38940.stderr

This file was deleted.

6 changes: 5 additions & 1 deletion tests/ui/did_you_mean/recursion_limit_deref.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
error: reached the recursion limit finding the struct tail for `Bottom`
|
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]`

error[E0055]: reached the recursion limit while auto-dereferencing `J`
--> $DIR/recursion_limit_deref.rs:51:22
|
Expand All @@ -17,7 +21,7 @@ LL | let x: &Bottom = &t;
= note: expected reference `&Bottom`
found reference `&Top`

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

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

0 comments on commit 99a71dc

Please sign in to comment.