Skip to content

Commit 8087147

Browse files
authored
Rollup merge of #89232 - rossmacarthur:fix-76424, r=wesleywiser
Improve help for recursion limit errors - Tweak help message and suggested limit (handle `0` case). - Add test for #75602 (it was already fixed, maybe can be resolved too). Fixes #76424
2 parents 7c23ff2 + d2613fb commit 8087147

26 files changed

+75
-35
lines changed

compiler/rustc_expand/src/expand.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,18 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
633633

634634
fn error_recursion_limit_reached(&mut self) {
635635
let expn_data = self.cx.current_expansion.id.expn_data();
636-
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
636+
let suggested_limit = match self.cx.ecfg.recursion_limit {
637+
Limit(0) => Limit(2),
638+
limit => limit * 2,
639+
};
637640
self.cx
638641
.struct_span_err(
639642
expn_data.call_site,
640643
&format!("recursion limit reached while expanding `{}`", expn_data.kind.descr()),
641644
)
642645
.help(&format!(
643-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
646+
"consider increasing the recursion limit by adding a \
647+
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
644648
suggested_limit, self.cx.ecfg.crate_name,
645649
))
646650
.emit();

compiler/rustc_trait_selection/src/autoderef.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir as hir;
55
use rustc_infer::infer::InferCtxt;
66
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness};
77
use rustc_middle::ty::{ToPredicate, TypeFoldable};
8-
use rustc_session::DiagnosticMessageId;
8+
use rustc_session::{DiagnosticMessageId, Limit};
99
use rustc_span::def_id::LOCAL_CRATE;
1010
use rustc_span::Span;
1111

@@ -217,7 +217,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
217217

218218
pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
219219
// We've reached the recursion limit, error gracefully.
220-
let suggested_limit = tcx.recursion_limit() * 2;
220+
let suggested_limit = match tcx.recursion_limit() {
221+
Limit(0) => Limit(2),
222+
limit => limit * 2,
223+
};
221224
let msg = format!("reached the recursion limit while auto-dereferencing `{:?}`", ty);
222225
let error_id = (DiagnosticMessageId::ErrorId(55), Some(span), msg);
223226
let fresh = tcx.sess.one_time_diagnostics.borrow_mut().insert(error_id);
@@ -231,7 +234,8 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
231234
)
232235
.span_label(span, "deref recursion limit reached")
233236
.help(&format!(
234-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
237+
"consider increasing the recursion limit by adding a \
238+
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
235239
suggested_limit,
236240
tcx.crate_name(LOCAL_CRATE),
237241
))

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_middle::ty::{
2222
Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
2323
};
2424
use rustc_middle::ty::{TypeAndMut, TypeckResults};
25+
use rustc_session::Limit;
2526
use rustc_span::def_id::LOCAL_CRATE;
2627
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2728
use rustc_span::{BytePos, DesugaringKind, ExpnKind, ForLoopLoc, MultiSpan, Span, DUMMY_SP};
@@ -2426,10 +2427,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24262427
}
24272428

24282429
fn suggest_new_overflow_limit(&self, err: &mut DiagnosticBuilder<'_>) {
2429-
let current_limit = self.tcx.recursion_limit();
2430-
let suggested_limit = current_limit * 2;
2430+
let suggested_limit = match self.tcx.recursion_limit() {
2431+
Limit(0) => Limit(2),
2432+
limit => limit * 2,
2433+
};
24312434
err.help(&format!(
2432-
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate (`{}`)",
2435+
"consider increasing the recursion limit by adding a \
2436+
`#![recursion_limit = \"{}\"]` attribute to your crate (`{}`)",
24332437
suggested_limit,
24342438
self.tcx.crate_name(LOCAL_CRATE),
24352439
));

src/test/ui/associated-types/hr-associated-type-bound-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | | type U = str;
99
LL | | }
1010
| |_^
1111
|
12-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`hr_associated_type_bound_2`)
12+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`hr_associated_type_bound_2`)
1313
note: required because of the requirements on the impl of `for<'b> X<'b>` for `u32`
1414
--> $DIR/hr-associated-type-bound-2.rs:11:6
1515
|
@@ -24,7 +24,7 @@ error[E0275]: overflow evaluating the requirement `for<'b> u32: X<'b>`
2424
LL | type U = str;
2525
| ^^^^^^^^^^^^^
2626
|
27-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`hr_associated_type_bound_2`)
27+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`hr_associated_type_bound_2`)
2828
note: required because of the requirements on the impl of `for<'b> X<'b>` for `u32`
2929
--> $DIR/hr-associated-type-bound-2.rs:11:6
3030
|

src/test/ui/autoref-autoderef/issue-38940.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0055]: reached the recursion limit while auto-dereferencing `J`
44
LL | let x: &Bottom = &t;
55
| ^^ deref recursion limit reached
66
|
7-
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate (`issue_38940`)
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]` attribute to your crate (`issue_38940`)
88

99
error[E0308]: mismatched types
1010
--> $DIR/issue-38940.rs:43:22

src/test/ui/did_you_mean/recursion_limit.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0275]: overflow evaluating the requirement `K: Send`
44
LL | is_send::<A>();
55
| ^^^^^^^^^^^^
66
|
7-
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate (`recursion_limit`)
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]` attribute to your crate (`recursion_limit`)
88
note: required because it appears within the type `J`
99
--> $DIR/recursion_limit.rs:24:9
1010
|

src/test/ui/did_you_mean/recursion_limit_deref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0055]: reached the recursion limit while auto-dereferencing `J`
44
LL | let x: &Bottom = &t;
55
| ^^ deref recursion limit reached
66
|
7-
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate (`recursion_limit_deref`)
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]` attribute to your crate (`recursion_limit_deref`)
88

99
error[E0308]: mismatched types
1010
--> $DIR/recursion_limit_deref.rs:50:22

src/test/ui/did_you_mean/recursion_limit_macro.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | ($t:tt $($tail:tt)*) => { recurse!($($tail)*) };
77
LL | recurse!(0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9);
88
| -------------------------------------------------- in this macro invocation
99
|
10-
= help: consider adding a `#![recursion_limit="20"]` attribute to your crate (`recursion_limit_macro`)
10+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "20"]` attribute to your crate (`recursion_limit_macro`)
1111
= note: this error originates in the macro `recurse` (in Nightly builds, run with -Z macro-backtrace for more info)
1212

1313
error: aborting due to previous error

src/test/ui/error-codes/E0055.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
44
LL | ref_foo.foo();
55
| ^^^ deref recursion limit reached
66
|
7-
= help: consider adding a `#![recursion_limit="8"]` attribute to your crate (`E0055`)
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "8"]` attribute to your crate (`E0055`)
88

99
error: aborting due to previous error
1010

src/test/ui/error-codes/E0275.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0275]: overflow evaluating the requirement `Bar<Bar<Bar<Bar<Bar<Bar<Bar<B
44
LL | impl<T> Foo for T where Bar<T>: Foo {}
55
| ^^^
66
|
7-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`E0275`)
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`E0275`)
88
note: required because of the requirements on the impl of `Foo` for `Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<Bar<T>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
99
--> $DIR/E0275.rs:5:9
1010
|

src/test/ui/infinite/infinite-autoderef.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
1212
LL | Foo.foo;
1313
| ^^^^^^^ deref recursion limit reached
1414
|
15-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`infinite_autoderef`)
15+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`infinite_autoderef`)
1616

1717
error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
1818
--> $DIR/infinite-autoderef.rs:25:9
1919
|
2020
LL | Foo.foo;
2121
| ^^^ deref recursion limit reached
2222
|
23-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`infinite_autoderef`)
23+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`infinite_autoderef`)
2424

2525
error[E0609]: no field `foo` on type `Foo`
2626
--> $DIR/infinite-autoderef.rs:25:9
@@ -34,7 +34,7 @@ error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
3434
LL | Foo.bar();
3535
| ^^^ deref recursion limit reached
3636
|
37-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`infinite_autoderef`)
37+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`infinite_autoderef`)
3838

3939
error[E0599]: no method named `bar` found for struct `Foo` in the current scope
4040
--> $DIR/infinite-autoderef.rs:26:9

src/test/ui/infinite/infinite-macro-expansion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | () => (recursive!())
77
LL | recursive!()
88
| ------------ in this macro invocation
99
|
10-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`infinite_macro_expansion`)
10+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`infinite_macro_expansion`)
1111
= note: this error originates in the macro `recursive` (in Nightly builds, run with -Z macro-backtrace for more info)
1212

1313
error: aborting due to previous error

src/test/ui/issues/issue-16098.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | $n + prob1!($n - 1);
77
LL | println!("Problem 1: {}", prob1!(1000));
88
| ------------ in this macro invocation
99
|
10-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`issue_16098`)
10+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_16098`)
1111
= note: this error originates in the macro `prob1` (in Nightly builds, run with -Z macro-backtrace for more info)
1212

1313
error: aborting due to previous error

src/test/ui/issues/issue-18400.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0275]: overflow evaluating the requirement `_: Sized`
44
LL | 0.contains(bits);
55
| ^^^^^^^^
66
|
7-
= help: consider adding a `#![recursion_limit="256"]` attribute to your crate (`issue_18400`)
7+
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`issue_18400`)
88
note: required because of the requirements on the impl of `Set<&[_]>` for `{integer}`
99
--> $DIR/issue-18400.rs:6:16
1010
|

0 commit comments

Comments
 (0)