Skip to content

Incorrect reference to the glob binding caused by the macro expansion #113834

Closed
@bvanjoi

Description

@bvanjoi

I tried this code:

pub mod a {
    pub use crate::b::*;
}

mod b {
    pub mod http {
        pub struct HeaderMap;
    }

    pub use self::http::*;
    #[derive(Debug)]
    pub struct HeaderMap;
}

use crate::a::HeaderMap;

fn main() {
    let h: crate::b::http::HeaderMap = HeaderMap;
}

I expected to see this happen: h should refer to crate::b::HeaderMap.

Instead, this happened: h refers to crate::b::http::HeaderMap.

If you remove the #[derive(Debug)] attribute, then h will refer to crate::b::HeaderMap.

And there is also another example(#56593 (comment)):

use thing::*;

#[derive(Debug)]
pub enum Thing {
    Foo
}

mod tests {
    use super::*;

    fn test_thing() {
        let thing: crate::thing::Thing = Thing::Bar; // should refer to `crate::Thing`
    }
}

mod thing {
    pub enum Thing {
        Bar
    }
}

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (0e8e857b1 2023-07-16)
binary: rustc
commit-hash: 0e8e857b11f60a785aea24a84f280f6dad7a4d42
commit-date: 2023-07-16
host: aarch64-apple-darwin
release: 1.73.0-nightly
LLVM version: 16.0.5

Metadata

Metadata

Assignees

No one assigned

    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