Skip to content

Rustfmt changes meaning of 2018 import starting with colons #3501

Closed
@dtolnay

Description

@dtolnay

Repro against current master branch (8ec0750):

echo 'use ::serde::Serialize; mod serde {}' | cargo run --bin rustfmt

Output:

use serde::Serialize;
mod serde {}

The original code imports ::serde::Serialize which refers to the external crate serde, not the local module. The formatted code imports serde::Serialize which refers to the local module and does not exist.

Interestingly, cargo fmt against the same code does not break the code, presumably because cargo fmt somehow understands that the edition of this code is 2018 and so the leading :: is meaningful. In the absence of knowing the edition for sure, would it be possible for rustfmt to treat this case more conservatively and keep the leading ::? We can continue to remove the colons if the edition is known to be 2015.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions