Skip to content

Adding private imports to a module can break downstream crates #95420

@jyn514

Description

@jyn514

I tried this code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7a55c241c30f1231a2711260adc95d22

mod a {
    pub type Result<T> = std::result::Result<T, ()>;
}

mod inner {
    pub use crate::a::*;
    use std::result::Result;
}

fn f() -> inner::Result<i32> {
    Ok(1)
}

I expected to see this happen: The code compiles fine, because inner::Result resolves to a::Result, just as it would without use std::result::Result.

Instead, this happened:

error[E0603]: enum import `Result` is private
   --> src/lib.rs:10:18
    |
10  | fn f() -> inner::Result<i32> {
    |                  ^^^^^^ private enum import
    |
note: the enum import `Result` is defined here...
   --> src/lib.rs:7:9
    |
7   |     use std::result::Result;
    |         ^^^^^^^^^^^^^^^^^^^
note: ...and refers to the enum `Result` which is defined here

Meta

rustc --version --verbose:

1.59.0

I don't know if this is strictly a bug in the sense that it will break things, but it seems like an unfortunate side effect of the resolution rules ... cc @petrochenkov, do you have opinions on this?

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