Skip to content

Do not panic when special macros have less args than expected #2371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ fn maybe_get_args_offset<T: ToExpr>(callee_str: &str, args: &[&T]) -> Option<(bo
.iter()
.find(|&&(s, _)| s == callee_str)
{
let all_simple = args.len() >= num_args_before && is_every_args_simple(args);
let all_simple = args.len() > num_args_before && is_every_args_simple(args);

Some((all_simple, num_args_before))
} else {
Expand Down
6 changes: 6 additions & 0 deletions tests/source/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ make_test!(str_searcher_ascii_haystack, "bb", "abbcbbd", [
}

fn special_case_macros() {
let p = eprint!();
let q = eprint!("{}", 1);
let r = eprint!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
let s = eprint!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);
Expand Down Expand Up @@ -266,10 +267,15 @@ fn special_case_macros() {
warn!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
warn!("{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);

assert!();
assert!(result == 42);
assert!(result == 42, "Ahoy there, {}!", target);
assert!(result == 42, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
assert!(result == 42, "{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26);

assert_eq!();
assert_eq!(left);
assert_eq!(left, right);
assert_eq!(left, right, "Ahoy there, {}!", target);
assert_eq!(left, right, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
assert_eq!(first_realllllllllllly_long_variable_that_doesnt_fit_one_one_line, second_reallllllllllly_long_variable_that_doesnt_fit_one_one_line, "Arr! While plunderin' the hold, we got '{}' when given '{}' (we expected '{}')", result, input, expected);
Expand Down
6 changes: 6 additions & 0 deletions tests/target/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ fn issue2214() {
}

fn special_case_macros() {
let p = eprint!();
let q = eprint!("{}", 1);
let r = eprint!(
"{}{}{}{}{}{}{}{}{}{}{}{}{}{}{}",
Expand Down Expand Up @@ -691,6 +692,8 @@ fn special_case_macros() {
26
);

assert!();
assert!(result == 42);
assert!(result == 42, "Ahoy there, {}!", target);
assert!(
result == 42,
Expand Down Expand Up @@ -730,6 +733,9 @@ fn special_case_macros() {
26
);

assert_eq!();
assert_eq!(left);
assert_eq!(left, right);
assert_eq!(left, right, "Ahoy there, {}!", target);
assert_eq!(
left, right,
Expand Down