Skip to content

Commit

Permalink
add test of the new attr and fix the breaking test
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Jun 8, 2023
1 parent 5a014eb commit 2361904
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2027,7 +2027,7 @@ impl<'feat> ExpansionConfig<'feat> {
crate_name,
features: None,
recursion_limit: Limit::new(1024),
expansion_growth_limit: Limit::new(1500),
expansion_growth_limit: Limit::new(6000),
trace_mac: false,
should_test: false,
span_debug: false,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn get_recursion_limit(krate_attrs: &[Attribute], sess: &Session) -> Limit {
}

pub fn get_expansion_growth_limit(krate_attrs: &[Attribute], sess: &Session) -> Limit {
get_limit(krate_attrs, sess, sym::expansion_growth_limit, 1500)
get_limit(krate_attrs, sess, sym::expansion_growth_limit, 6000)
}

fn get_limit(krate_attrs: &[Attribute], sess: &Session, name: Symbol, default: usize) -> Limit {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ pub struct Limits {
pub move_size_limit: Limit,
/// The maximum length of types during monomorphization.
pub type_length_limit: Limit,
/// FIXME(vincenzopalazzo) add docs
/// The maximum blocks a const expression can evaluate.
pub const_eval_limit: Limit,
/// The maximum tokens limit for potentially infinitely resolving
/// a macros that add infinite tokens inside the buffer.
pub expansion_growth_limit: Limit,
}

Expand Down
25 changes: 25 additions & 0 deletions tests/ui/limits/issue-95698.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// check-fail

/// issue #95698
macro_rules! from_cow_impls {
($( $from: ty ),+ $(,)? ) => {
// recursion call
from_cow_impls!(
$( $from, Cow::from ),+
);
//~^^^ ERROR expansion grow limit reached while expanding `from_cow_impls!`
};

($( $from: ty, $normalizer: expr ),+ $(,)? ) => {
$( impl<'a> From<$from> for LhsValue<'a> {
fn from(val: $from) -> Self {
LhsValue::Bytes($normalizer(val))
}
} )+
};
}

from_cow_impls!(
&'a [u8], /*callback,*/
Vec<u8>, /*callback,*/
);
19 changes: 19 additions & 0 deletions tests/ui/limits/issue-95698.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error: expansion grow limit reached while expanding `from_cow_impls!`
--> $DIR/issue-95698.rs:7:9
|
LL | / from_cow_impls!(
LL | | $( $from, Cow::from ),+
LL | | );
| |_________^
...
LL | / from_cow_impls!(
LL | | &'a [u8], /*callback,*/
LL | | Vec<u8>, /*callback,*/
LL | | );
| |_- in this macro invocation
|
= help: consider increasing the expansion grow limit by adding a `#![expansion_growth_limit = "12000"]` attribute to your crate (`issue_95698`)
= note: this error originates in the macro `from_cow_impls` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui/mir/issue-29227.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![expansion_growth_limit = "16000"]
// run-pass
// ignore-tidy-linelength

Expand Down

0 comments on commit 2361904

Please sign in to comment.