Rollup merge of #109856 - bvanjoi:fix-issue-109304, r=compiler-errors
fix(middle): emit error rather than delay bug when reaching limit close #109304
This commit is contained in:
commit
99a71dc4d6
@ -16,6 +16,10 @@ middle_limit_invalid =
|
|||||||
`limit` must be a non-negative integer
|
`limit` must be a non-negative integer
|
||||||
.label = {$error_str}
|
.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 =
|
middle_const_eval_non_int =
|
||||||
constant evaluation of enum discriminant resulted in non-integer
|
constant evaluation of enum discriminant resulted in non-integer
|
||||||
|
|
||||||
|
@ -49,6 +49,14 @@ pub struct LimitInvalid<'a> {
|
|||||||
pub error_str: &'a str,
|
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)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(middle_const_eval_non_int)]
|
#[diag(middle_const_eval_non_int)]
|
||||||
pub struct ConstEvalNonIntError {
|
pub struct ConstEvalNonIntError {
|
||||||
|
@ -19,7 +19,8 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
|||||||
use rustc_index::bit_set::GrowableBitSet;
|
use rustc_index::bit_set::GrowableBitSet;
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::{Idx, IndexVec};
|
||||||
use rustc_macros::HashStable;
|
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::abi::{Integer, IntegerType, Size, TargetDataLayout};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
@ -225,10 +226,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
let recursion_limit = self.recursion_limit();
|
let recursion_limit = self.recursion_limit();
|
||||||
for iteration in 0.. {
|
for iteration in 0.. {
|
||||||
if !recursion_limit.value_within_limit(iteration) {
|
if !recursion_limit.value_within_limit(iteration) {
|
||||||
return self.ty_error_with_message(
|
let suggested_limit = match recursion_limit {
|
||||||
DUMMY_SP,
|
Limit(0) => Limit(2),
|
||||||
&format!("reached the recursion limit finding the struct tail for {}", ty),
|
limit => limit * 2,
|
||||||
);
|
};
|
||||||
|
let reported =
|
||||||
|
self.sess.emit_err(crate::error::RecursionLimitReached { ty, suggested_limit });
|
||||||
|
return self.ty_error(reported);
|
||||||
}
|
}
|
||||||
match *ty.kind() {
|
match *ty.kind() {
|
||||||
ty::Adt(def, substs) => {
|
ty::Adt(def, substs) => {
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
// issue-38940: error printed twice for deref recursion limit exceeded
|
|
||||||
// Test that the recursion limit can be changed. In this case, we have
|
|
||||||
// deeply nested types that will fail the `Send` check by overflow
|
|
||||||
// when the recursion limit is set very low.
|
|
||||||
// compile-flags: -Zdeduplicate-diagnostics=yes
|
|
||||||
|
|
||||||
#![allow(dead_code)]
|
|
||||||
#![recursion_limit = "10"]
|
|
||||||
macro_rules! link {
|
|
||||||
($outer:ident, $inner:ident) => {
|
|
||||||
struct $outer($inner);
|
|
||||||
impl $outer {
|
|
||||||
fn new() -> $outer {
|
|
||||||
$outer($inner::new())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl std::ops::Deref for $outer {
|
|
||||||
type Target = $inner;
|
|
||||||
fn deref(&self) -> &$inner {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Bottom;
|
|
||||||
|
|
||||||
impl Bottom {
|
|
||||||
fn new() -> Bottom {
|
|
||||||
Bottom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
link!(Top, A);
|
|
||||||
link!(A, B);
|
|
||||||
link!(B, C);
|
|
||||||
link!(C, D);
|
|
||||||
link!(D, E);
|
|
||||||
link!(E, F);
|
|
||||||
link!(F, G);
|
|
||||||
link!(G, H);
|
|
||||||
link!(H, I);
|
|
||||||
link!(I, J);
|
|
||||||
link!(J, K);
|
|
||||||
link!(K, Bottom);
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let t = Top::new();
|
|
||||||
let x: &Bottom = &t;
|
|
||||||
//~^ ERROR mismatched types
|
|
||||||
//~| ERROR reached the recursion limit while auto-dereferencing `J`
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
error[E0055]: reached the recursion limit while auto-dereferencing `J`
|
|
||||||
--> $DIR/issue-38940.rs:49:22
|
|
||||||
|
|
|
||||||
LL | let x: &Bottom = &t;
|
|
||||||
| ^^ deref recursion limit reached
|
|
||||||
|
|
|
||||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]` attribute to your crate (`issue_38940`)
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
|
||||||
--> $DIR/issue-38940.rs:49:22
|
|
||||||
|
|
|
||||||
LL | let x: &Bottom = &t;
|
|
||||||
| ------- ^^ expected `&Bottom`, found `&Top`
|
|
||||||
| |
|
|
||||||
| expected due to this
|
|
||||||
|
|
|
||||||
= note: expected reference `&Bottom`
|
|
||||||
found reference `&Top`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
Some errors have detailed explanations: E0055, E0308.
|
|
||||||
For more information about an error, try `rustc --explain E0055`.
|
|
@ -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`
|
error[E0055]: reached the recursion limit while auto-dereferencing `J`
|
||||||
--> $DIR/recursion_limit_deref.rs:51:22
|
--> $DIR/recursion_limit_deref.rs:51:22
|
||||||
|
|
|
|
||||||
@ -17,7 +21,7 @@ LL | let x: &Bottom = &t;
|
|||||||
= note: expected reference `&Bottom`
|
= note: expected reference `&Bottom`
|
||||||
found reference `&Top`
|
found reference `&Top`
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0055, E0308.
|
Some errors have detailed explanations: E0055, E0308.
|
||||||
For more information about an error, try `rustc --explain E0055`.
|
For more information about an error, try `rustc --explain E0055`.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user