forked from rust-lang/rustfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for issue rust-lang#4609 - prevent unlimitted indentations in mac…
…ro formatting when repeating formatting
- Loading branch information
1 parent
a451a39
commit 0097a90
Showing
5 changed files
with
435 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// rustfmt-version: One | ||
|
||
// Original issue - parameters in macro call | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
outer!($); | ||
|
||
fn main() { | ||
inner!("hi"); | ||
} | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
// Variations of the original issue | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
macro_rules! outer { | ||
($ d:tt) => { | ||
macro_rules! inner { | ||
($ d s:expr) => { | ||
println!("INNER1: {}", $d s); | ||
println!("INNER2: {}", $ s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
outer!($); | ||
|
||
inner!("hi"); | ||
} | ||
|
||
// Consecutive identities in macro body | ||
|
||
fn main() { | ||
macro_rules! uniop { | ||
($op:tt, $s:expr) => { | ||
$op $s | ||
}; | ||
} | ||
let x = uniop!(!, true); | ||
println!("{}", x); | ||
let x = uniop!(-, 7); | ||
println!("{}", x); | ||
} | ||
|
||
fn main() { | ||
macro_rules! binop { | ||
($l:expr, $op:tt, $r:expr) => { | ||
$l $op $r | ||
}; | ||
} | ||
let x = binop!(10, -, 7); | ||
println!("{}", x); | ||
let x = binop!(10, +, 7); | ||
println!("{}", x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// rustfmt-version: Two | ||
|
||
// Original issue - parameters in macro call | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
outer!($); | ||
|
||
fn main() { | ||
inner!("hi"); | ||
} | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
// Variations of the original issue | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
macro_rules! outer { | ||
($ d:tt) => { | ||
macro_rules! inner { | ||
($ d s:expr) => { | ||
println!("INNER1: {}", $d s); | ||
println!("INNER2: {}", $ s); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
outer!($); | ||
|
||
inner!("hi"); | ||
} | ||
|
||
// Consecutive identities in macro body | ||
|
||
fn main() { | ||
macro_rules! uniop { | ||
($op:tt, $s:expr) => { | ||
$op $s | ||
}; | ||
} | ||
let x = uniop!(!, true); | ||
println!("{}", x); | ||
let x = uniop!(-, 7); | ||
println!("{}", x); | ||
} | ||
|
||
fn main() { | ||
macro_rules! binop { | ||
($l:expr, $op:tt, $r:expr) => { | ||
$l $op $r | ||
}; | ||
} | ||
let x = binop!(10, -, 7); | ||
println!("{}", x); | ||
let x = binop!(10, +, 7); | ||
println!("{}", x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// rustfmt-version: One | ||
|
||
// Original issue - parameters in macro call | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
outer!($); | ||
|
||
fn main() { | ||
inner!("hi"); | ||
} | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
// Variations of the original issue | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
macro_rules! outer { | ||
($d:tt) => { | ||
macro_rules! inner { | ||
($d s:expr) => { | ||
println!("{}", $d s); | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
macro_rules! outer { | ||
($ d:tt) => { | ||
macro_rules! inner { | ||
($ d s:expr) => { | ||
println!("INNER1: {}", $d s); | ||
println!("INNER2: {}", $ s); | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
outer!($); | ||
|
||
inner!("hi"); | ||
} | ||
|
||
// Consecutive identities in macro body | ||
|
||
fn main() { | ||
macro_rules! uniop { | ||
($op:tt, $s:expr) => { | ||
$op $s | ||
}; | ||
} | ||
let x = uniop!(!, true); | ||
println!("{}", x); | ||
let x = uniop!(-, 7); | ||
println!("{}", x); | ||
} | ||
|
||
fn main() { | ||
macro_rules! binop { | ||
($l:expr, $op:tt, $r:expr) => { | ||
$l $op $r | ||
}; | ||
} | ||
let x = binop!(10, -, 7); | ||
println!("{}", x); | ||
let x = binop!(10, +, 7); | ||
println!("{}", x); | ||
} |
Oops, something went wrong.