Skip to content

Formatting changes semantics of imports #3750

@Robbepop

Description

@Robbepop

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-imports`use` syntaxbugPanic, non-idempotency, invalid code, etc.only-with-optionrequires a non-default option value to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions