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

Would it be better to have "reorder_modules" default to false? #4275

Closed
earthengine opened this issue Jun 24, 2020 · 3 comments · Fixed by #4284
Closed

Would it be better to have "reorder_modules" default to false? #4275

earthengine opened this issue Jun 24, 2020 · 3 comments · Fixed by #4284
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@earthengine
Copy link

Say I have the following modules:

mod utils;
mod api;

and I put some local macros (only to be use within my crate) to mod utils, in this case the reordering of the modules will change the meaning of the program/module.

Unless it is not too hard to detect that utils module contains macros that would be used in api module, I think the safe default would be not to reorder it. Am I right?

(FYI, I am experiencing this problem since I am using a real time formatter VS Code plugin)

@topecongiro
Copy link
Contributor

Hmm, are you able to compile your code without #[macro_use] attribute on mod utils;? If the attribute is present, rustfmt will not reorder modules even when reorder_moduels is true.

@earthengine
Copy link
Author

earthengine commented Jun 24, 2020

Yes I can. I put a #![macro_use] as the first line on my mod utils, so I didn't use a #[macro_use] attribute.

BTW, I refactored my code to use the attribute in the module reference, not the module itself. So my problem has been solved, thank you for your tips.

However this is still an issue to fix. I guess we can do something similar to what we have already done for #[macro_export]?

@topecongiro topecongiro added the bug Panic, non-idempotency, invalid code, etc. label Jun 25, 2020
@Riateche
Copy link

I was hit by this issue today. Here's a MCVE, just to clarify the issue:

lib.rs

mod b;
mod a;

a.rs

my_macro!();

b.rs

#![macro_use]

#[macro_export]
macro_rules! my_macro {
    () => {};
}

This code compiles, but running rustfmt on it breaks the build because the macro is no longer visible in a module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants