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

Adding #[derive()] changes blob import semantics #115377

Closed
danielhenrymantilla opened this issue Aug 30, 2023 · 2 comments · Fixed by #115269
Closed

Adding #[derive()] changes blob import semantics #115377

danielhenrymantilla opened this issue Aug 30, 2023 · 2 comments · Fixed by #115269
Labels
C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@danielhenrymantilla
Copy link
Contributor

danielhenrymantilla commented Aug 30, 2023

image

I tried this code:

use module::*;
mod module {
    pub enum B {}
    impl B { pub const ASSOC: bool = true; } // used to distinguish the `B`s
}

#[derive()]
pub enum B {}
impl B { pub const ASSOC: bool = false; }

fn main() {
    let it = {
        use self::*;
        B::ASSOC
    };
    assert_eq!(
        it,
        {
            use self::*;
            B::ASSOC
        },
    );
}

I expected to see this happen: the assertion passing, since { use self::*; B::ASSOC } should have a consistent value/meaning within main's fn body where no other items are defined.

Instead, this happened: the assertion fails!

Meta

This regressed in 1.52.0

Extra comments

  • The key element playing a role here, beyond the blob imports, is the #[derive()] slapped onto B. This seems to allow for the blob-imported module::B to somehow gain priority over the clearly-defined crate::B type within fn main's blob import.

  • I did not expect the "moving of { use self::*; B::ASSOC } block" to alter this quirk (I was initially writing the MRE as assert_eq!(B::ASSSOC, { use … }) when I ran into this extra bug).

  • Could resolve: Remove artificial import ambiguity errors #112086 be relevant? cc @petrochenkov

  • Initially discovered on Discord by user @kyuuhachi

@rustbot modify labels: +regression-from-stable-to-stable

@danielhenrymantilla danielhenrymantilla added the C-bug Category: This is a bug. label Aug 30, 2023
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 30, 2023
@petrochenkov
Copy link
Contributor

It's not related to #112086, it's related to #56593 and friends.

It's gradually being fixed in #113099 and follow up PRs.
Most of the difficulty in fixing this comes from avoiding breakage, it's massive if everything just starts working correctly.

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 30, 2023
@apiraino apiraino added 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 Aug 30, 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
C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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.

4 participants