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

Formatting changes semantics of imports #3750

Closed
Robbepop opened this issue Aug 19, 2019 · 4 comments · Fixed by #3753 or #3769
Closed

Formatting changes semantics of imports #3750

Robbepop opened this issue Aug 19, 2019 · 4 comments · Fixed by #3753 or #3769
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce

Comments

@Robbepop
Copy link

Robbepop commented Aug 19, 2019

I have a project with a module that re-exports other definitions as follows:

mod defs {
    #[cfg(feature = "std")]
    pub use std::vec;
    #[cfg(not(feature = "std"))]
    pub use alloc::vec;
}

Oftentimes I want to use the vec! macro and Vec type like so:

use defs::{
    vec,
    vec::Vec,
};

However, rustfmt thinks this is worse than

use defs::vec::{self, Vec};

However, this has different semantics since vec above refers to the vec! macro while self in the replaced variant refers to the vec submodule of defs. So I can no longer access the vec! macro whenever rustfmt replaced this.

To be honest: I don't know whether this is a rustfmt bug or a Rust compiler bug.

@topecongiro topecongiro added a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. labels Aug 20, 2019
@topecongiro
Copy link
Contributor

This is not reproducible with the latest rustfmt, both in stable and nightly. Would you mind telling us which version you have used?

@Robbepop
Copy link
Author

Robbepop commented Aug 20, 2019

cargo fmt --version yields rustfmt 1.4.4-nightly (0462008 2019-08-06)
Good to know that it is already fixed at the latest rustfmt.
Sadly I am not able to upgrade at the moment.

@topecongiro
Copy link
Contributor

@Robbepop Never mind, this is actually reproducible with merge_imports = true. Do you set
the option as well?

@topecongiro topecongiro added the only-with-option requires a non-default option value to reproduce label Aug 21, 2019
@Robbepop
Copy link
Author

@Robbepop Never mind, this is actually reproducible with merge_imports = true. Do you set
the option as well?

yes it is enabled!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-imports `use` syntax bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants