-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #28351 - jonas-schievink:macro-bt, r=nrc
The second commit in this PR will stop printing the macro definition site in backtraces, which cuts their length in half and increases readability (the definition site was only correct for local macros). The third commit will not print an invocation if the last one printed occurred at the same place (span). This will make backtraces caused by a self-recursive macro much shorter. (A possible alternative would be to capture the backtrace first, then limit it to a few frames at the start and end of the chain and print `...` inbetween. This would also work with multiple macros calling each other, which is not addressed by this PR - although the backtrace will still be halved) Example: ```rust macro_rules! m { ( 0 $($t:tt)* ) => ( m!($($t)*); ); () => ( fn main() {0} ); } m!(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0); ``` On a semi-recent nightly, this yields: ``` test.rs:3:21: 3:22 error: mismatched types: expected `()`, found `_` (expected (), found integral variable) [E0308] test.rs:3 () => ( fn main() {0} ); ^ test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:2:23: 2:34 note: expansion site test.rs:1:1: 4:2 note: in expansion of m! test.rs:6:1: 6:35 note: expansion site test.rs:3:21: 3:22 help: run `rustc --explain E0308` to see a detailed explanation error: aborting due to previous error ``` After this patch: ``` test.rs:3:21: 3:22 error: mismatched types: expected `()`, found `_` (expected (), found integral variable) [E0308] test.rs:3 () => ( fn main() {0} ); ^ test.rs:2:23: 2:34 note: in this expansion of m! test.rs:6:1: 6:35 note: in this expansion of m! test.rs:3:21: 3:22 help: run `rustc --explain E0308` to see a detailed explanation error: aborting due to previous error ```
- Loading branch information
Showing
6 changed files
with
56 additions
and
38 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
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
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