rust-lang / rust-lang/rust

Importing a private function with a wildcard should have a better error

Open
#144,697 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
// src/lib.rs
fn calculate() -> usize {
    1 + 2
}

// tests/file.rs
use temp::*;

#[test]
fn tmp() {
    assert_eq!(calculate(), 3);
}
Current output
warning: unused import: `temp::*`
 --> tests/file.rs:1:5
  |
1 | use temp::*;
  |     ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0425]: cannot find function `calculate` in this scope
 --> tests/file.rs:5:16
  |
5 |     assert_eq!(calculate(), 3);
  |                ^^^^^^^^^ not found in this scope
Desired output
warning: unused import: `temp::*`
 --> tests/file.rs:1:5
  |
1 | use temp::*;
  |     ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0603]: function `calculate` is private and not accessible via `use temp::*`
 --> tests/file.rs:5:16
  |
1 | use temp::*;
  |     ------- wildcard import excludes private items: `calculate`
...
5 |     assert_eq!(calculate(), 3);
  |                ^^^^^^^^^ function `calculate` is private
  |
note: the function `calculate` is defined here
 --> src/lib.rs:1:1
  |
1 | fn calculate() -> usize {
  | ^^^^^^^^^^^^^^^^^^^^^^^
Rationale and extra context

With the original error, it takes a moment to put two and two together and realize that the calculate function is not imported because it is declared private. It might be nice to follow error E0603's footsteps to make the intended message significantly clearer.

For reference, E0603 looks like:

error[E0603]: function `calculate` is private
 --> tests/file.rs:1:11
  |
1 | use temp::calculate;
  |           ^^^^^^^^^ private function
  |
note: the function `calculate` is defined here
 --> src/lib.rs:1:1
  |
1 | fn calculate() -> usize {
  | ^^^^^^^^^^^^^^^^^^^^^^^
Rust Version
rustc 1.90.0-nightly (ba7e63b63 2025-07-29)
binary: rustc
commit-hash: ba7e63b63871a429533c189adbfb1d9a6337e000
commit-date: 2025-07-29
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the reproduction using src/lib.rs and tests/file.rs, then compare the current and desired diagnostics. Trace the compiler path for wildcard imports and private-item resolution, using the E0603 diagnostic as the reference. Done means the reproduction reports E0603 with the private function and its definition location.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.