Skip to content

Ambiguous glob import of main errors even in library crate #149412

@theemathas

Description

@theemathas

I compiled the following code with rustc --crate-type=lib repro.rs

mod a {
    pub fn main() {}
}
mod b {
    pub fn main() {}
}

use a::*;
use b::*;

I expected the code to compile, but instead I got the following error:

error[E0659]: `main` is ambiguous
  |
  = note: ambiguous because of multiple glob imports of a name in the same module
note: `main` could refer to the function imported here
 --> repro.rs:8:5
  |
8 | use a::*;
  |     ^^^^
  = help: consider adding an explicit import of `main` to disambiguate
note: `main` could also refer to the function imported here
 --> repro.rs:9:5
  |
9 | use b::*;
  |     ^^^^
  = help: consider adding an explicit import of `main` to disambiguate

warning: unused import: `b::*`
 --> repro.rs:9:5
  |
9 | use b::*;
  |     ^^^^
  |
  = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0659`.

In a library crate, rustc shouldn't be caring whether a function is named main or not.

Renaming both functions from main to foo makes the code compile without errors.

Possibly relevant code:

self.tcx.sess.time("resolve_main", || self.resolve_main());

Meta

rustc --version --verbose:

rustc 1.93.0-nightly (80d8f292d 2025-11-25)
binary: rustc
commit-hash: 80d8f292d82d735f83417221dd63b0dd2bbb8dd2
commit-date: 2025-11-25
host: aarch64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.5

Metadata

Metadata

Assignees

Labels

A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions