Skip to content

Rustc shows unnecessary big error when glob reexport failed #81413

Closed
@WaffleLapkin

Description

@WaffleLapkin

I tried this code:

pub const ITEM: Item = Item;

pub struct Item;

pub fn item() {}

// Glob (*) is required to cause the error
pub use doesnt_exist::*;

mod a {
    use crate::{item, Item, ITEM};
}

mod b {
    use crate::item;
    use crate::Item;
    use crate::ITEM;
}

mod c {
    use crate::item;
}

(play)

I expected to see an error that only says that "doesnt_exist is unresolved".

But the error says that all uses of items from the module with glob import (crate in this case) are unresolved too:

error[E0432]: unresolved imports `doesnt_exist`, `crate::item`, `crate::Item`, `crate::ITEM`, `crate::item`, `crate::Item`, `crate::ITEM`, `crate::item`
  --> src/lib.rs:41:9
   |
41 | pub use doesnt_exist::*;
   |         ^^^^^^^^^^^^ use of undeclared crate or module `doesnt_exist`
...
44 |     use crate::{item, Item, ITEM};
   |                 ^^^^  ^^^^  ^^^^
...
48 |     use crate::item;
   |         ^^^^^^^^^^^
49 |     use crate::Item;
   |         ^^^^^^^^^^^
50 |     use crate::ITEM;
   |         ^^^^^^^^^^^
...
54 |     use crate::item;
   |         ^^^^^^^^^^^

This may lead to extremely long and unreadable errors. The issue was originally found while developing teloxide where it caused 1500+ lines error.

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (c97f11af7 2021-01-10)
binary: rustc
commit-hash: c97f11af7bc4a6d3578f6a953be04ab2449a5728
commit-date: 2021-01-10
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions