Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bvanjoi opened this issue Jul 18, 2023 · 0 comments · Fixed by #115269
Closed

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

bvanjoi opened this issue Jul 18, 2023 · 0 comments · Fixed by #115269
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bvanjoi
Copy link
Contributor

bvanjoi commented Jul 18, 2023

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
@bvanjoi bvanjoi added the C-bug Category: This is a bug. label Jul 18, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 18, 2023
@compiler-errors compiler-errors added A-resolve Area: Name resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 19, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 13, 2023
resolve: mark binding is determined after all macros had been expanded

Fixes rust-lang#113834
Fixes rust-lang#115377

r? `@petrochenkov`
@bors bors closed this as completed in 735bb7e Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name resolution C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants