Skip to content

Commit 95d23d5

Browse files
impl new way to generate the compiler suggestion
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent 5d2abbb commit 95d23d5

File tree

8 files changed

+28
-27
lines changed

8 files changed

+28
-27
lines changed

compiler/rustc_expand/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ expand_duplicate_matcher_binding = duplicate matcher binding
2323
.label = duplicate binding
2424
.label2 = previous binding
2525
26+
expand_expansion_growth_limit_reached =
27+
expansion grow limit reached while expanding `{$descr}`
28+
.help = consider increasing the expansion grow limit by adding a `#![expansion_growth_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
29+
2630
expand_expected_comma_in_list =
2731
expected token: `,`
2832

compiler/rustc_expand/src/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ pub(crate) struct RecursionLimitReached<'a> {
212212
pub crate_name: &'a str,
213213
}
214214

215+
#[derive(Diagnostic)]
216+
#[diag(expand_expansion_growth_limit_reached)]
217+
#[help]
218+
pub(crate) struct ExpansionGrowthLimitReached<'a> {
219+
#[primary_span]
220+
pub span: Span,
221+
pub descr: String,
222+
pub suggested_limit: Limit,
223+
pub crate_name: &'a str,
224+
}
225+
215226
#[derive(Diagnostic)]
216227
#[diag(expand_malformed_feature_attribute, code = "E0556")]
217228
pub(crate) struct MalformedFeatureAttribute {

compiler/rustc_expand/src/expand.rs

+10-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::base::*;
22
use crate::config::StripUnconfigured;
33
use crate::errors::{
4-
IncompleteParse, RecursionLimitReached, RemoveExprNotSupported, RemoveNodeNotSupported,
5-
UnsupportedKeyValue, WrongFragmentKind,
4+
ExpansionGrowthLimitReached, IncompleteParse, RecursionLimitReached, RemoveExprNotSupported,
5+
RemoveNodeNotSupported, UnsupportedKeyValue, WrongFragmentKind,
66
};
77
use crate::hygiene::SyntaxContext;
88
use crate::mbe::diagnostics::annotate_err_with_kind;
@@ -628,20 +628,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
628628
limit => limit * 2,
629629
};
630630

631-
self.cx
632-
.struct_span_err(
633-
expn_data.call_site,
634-
&format!(
635-
"expansion grow limit reached while expanding `{}`",
636-
expn_data.kind.descr()
637-
),
638-
)
639-
.help(&format!(
640-
"consider increasing the expansion grow limit by adding a \
641-
`#![expansion_growth_limit = \"{}\"]` attribute to your crate (`{}`)",
642-
suggested_limit, self.cx.ecfg.crate_name,
643-
))
644-
.emit();
631+
self.cx.emit_err(ExpansionGrowthLimitReached {
632+
span: expn_data.call_site,
633+
descr: expn_data.kind.descr(),
634+
suggested_limit,
635+
crate_name: &self.cx.ecfg.crate_name,
636+
});
645637
self.cx.trace_macros_diag();
646638
}
647639

@@ -663,7 +655,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
663655

664656
// Reduce the recursion limit by half each time it triggers.
665657
self.cx.reduced_recursion_limit = Some(expansion_limit / 2);
666-
667658
return Err(());
668659
}
669660
Ok(())
@@ -698,11 +689,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
698689
self.parse_ast_fragment(tok_result, fragment_kind, &mac.path, span)
699690
}
700691
SyntaxExtensionKind::LegacyBang(expander) => {
701-
if self.reduce_expansion_growth_limit(mac.args.inner_tokens().len()).is_err() {
692+
if self.reduce_expansion_growth_limit(mac.args.tokens.len()).is_err() {
702693
return ExpandResult::Ready(fragment_kind.dummy(span));
703694
}
704-
let prev = self.cx.current_expansion.prior_type_ascription;
705-
self.cx.current_expansion.prior_type_ascription = mac.prior_type_ascription;
706695
let tok_result = expander.expand(self.cx, span, mac.args.tokens.clone());
707696
let result = if let Some(result) = fragment_kind.make_from(tok_result) {
708697
result
@@ -2040,7 +2029,7 @@ impl ExpansionConfig<'_> {
20402029
crate_name,
20412030
features,
20422031
recursion_limit: Limit::new(1024),
2043-
expansion_growth_limit: Limit::new(6000),
2032+
expansion_growth_limit: Limit::new(1000000),
20442033
trace_mac: false,
20452034
should_test: false,
20462035
span_debug: false,

compiler/rustc_middle/src/middle/limits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn get_recursion_limit(krate_attrs: &[Attribute], sess: &Session) -> Limit {
4242
}
4343

4444
pub fn get_expansion_growth_limit(krate_attrs: &[Attribute], sess: &Session) -> Limit {
45-
get_limit(krate_attrs, sess, sym::expansion_growth_limit, 6000)
45+
get_limit(krate_attrs, sess, sym::expansion_growth_limit, 1000000)
4646
}
4747

4848
fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: usize) -> Limit {

compiler/rustc_session/src/session.rs

-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ pub struct Limits {
130130
pub move_size_limit: Limit,
131131
/// The maximum length of types during monomorphization.
132132
pub type_length_limit: Limit,
133-
/// The maximum blocks a const expression can evaluate.
134-
pub const_eval_limit: Limit,
135133
/// The maximum tokens limit for potentially infinitely resolving
136134
/// a macros that add infinite tokens inside the buffer.
137135
pub expansion_growth_limit: Limit,

tests/ui/limits/issue-95698.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// check-fail
22

3-
/// issue #95698
3+
// issue #95698
44
macro_rules! from_cow_impls {
55
($( $from: ty ),+ $(,)? ) => {
66
// recursion call

tests/ui/limits/issue-95698.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | | Vec<u8>, /*callback,*/
1212
LL | | );
1313
| |_- in this macro invocation
1414
|
15-
= help: consider increasing the expansion grow limit by adding a `#![expansion_growth_limit = "12000"]` attribute to your crate (`issue_95698`)
15+
= help: consider increasing the expansion grow limit by adding a `#![expansion_growth_limit = "2000000"]` attribute to your crate (`issue_95698`)
1616
= note: this error originates in the macro `from_cow_impls` (in Nightly builds, run with -Z macro-backtrace for more info)
1717

1818
error: aborting due to previous error

tests/ui/mir/issue-29227.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![expansion_growth_limit = "16000"]
21
// run-pass
32
// ignore-tidy-linelength
43

0 commit comments

Comments
 (0)