Skip to content
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

Equivalent of rustc's -Zunpretty=expanded #3420

Closed
aytey opened this issue Feb 4, 2025 · 3 comments
Closed

Equivalent of rustc's -Zunpretty=expanded #3420

aytey opened this issue Feb 4, 2025 · 3 comments
Labels

Comments

@aytey
Copy link

aytey commented Feb 4, 2025

When working with macros, it is sometimes useful to use rustc's -Zunpretty=expanded flag to see how a macro is being expanded (think of this like -E when working with gcc for C or C++).

I checked the source tree, the tests and the help of a recent build (4d7e7d9), but I couldn't see anything that looked like it matched dumping -Zunpretty=expanded to stdout/stderr/a file.

Is there an equivalent for gccrs?

@aytey
Copy link
Author

aytey commented Feb 4, 2025

By way of an example:

${HOME}/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc ${HOME}/clones/gccrs/gcc/testsuite/rust/execute/torture/macros22.rs -Zunpretty=expanded

Gives:

#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
// { dg-output "1\r*\n2\r*\nNaN\r*\n3\r*\n" }

macro_rules! print_num {
    ($l:literal) =>
    { { unsafe { printf("%d\n\0" as *const str as *const i8, $l); } } };
}

extern "C" {
    fn printf(s: *const i8, ...);
}

// Check to make sure that expanding macros does not break the flow of calls
fn main() -> i32 {
    { unsafe { printf("%d\n\0" as *const str as *const i8, 1); } };
    { unsafe { printf("%d\n\0" as *const str as *const i8, 2); } };

    unsafe { printf("NaN\n\0" as *const str as *const i8); }
    {
        unsafe {
            printf("%d\n\0" as *const str as *const i8,
                3);
        }
    };

    0
}

So I was wondering if it is possible to do the same with gccrs.

@P-E-P
Copy link
Member

P-E-P commented Feb 4, 2025

You can use -frust-dump-expansion although it is not 100% perfect for now, it'll insert some comments for tail expressions. Some work is already on track to improve that #3212 should allow more customization and #3209 should fix a slight issue with doc comments being converted to attributes.

@P-E-P P-E-P added the question label Feb 4, 2025
@aytey
Copy link
Author

aytey commented Feb 4, 2025

Works perfectly -- thank you!

@aytey aytey closed this as completed Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants