Skip to content

Importing from module with same name as tool module causes ambiguity #111135

Closed
@clubby789

Description

@clubby789

I tried this code:

mod rustfmt { pub fn skip() {} }

use rustfmt::skip;
fn main() {
  skip()
}

I expected to see this happen: No error, as the rustfmt tool module cannot be imported from, so the path should resolve to the module.

Instead, this happened:

error[E0659]: `rustfmt` is ambiguous
 --> poc.rs:3:5
  |
3 | use rustfmt::skip;
  |     ^^^^^^^ ambiguous name
  |
  = note: ambiguous because of multiple potential import sources
  = note: `rustfmt` could refer to a tool module
note: `rustfmt` could also refer to the module defined here
 --> poc.rs:1:1
  |
1 | mod rustfmt { pub fn skip() {} }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: use `crate::rustfmt` to refer to this module unambiguously

This would make adding new tool namespaces (such as the proposed RFC 3368 a breaking change.

Meta

Present on stable, nightly and master.

@rustbot label +A-resolve

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions