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

Derive breaks visibility order #61520

Closed
kurnevsky opened this issue Jun 4, 2019 · 4 comments
Closed

Derive breaks visibility order #61520

kurnevsky opened this issue Jun 4, 2019 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@kurnevsky
Copy link

kurnevsky commented Jun 4, 2019

Compilation of the following example depends on the derive existence. It will compile without it and will break with it. Also it will work with derive if use crate::b::*; is replaced by use crate::b::{*, A}; inside c mod.

mod a {
    pub struct A;
}

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

    #[derive(Clone)]
    struct A;

    fn f(a: A) {}

    mod c {
        use crate::b::*;

        fn x() {
            f(A)
        }
    }
}

fn main() { }
   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
  --> src/main.rs:17:15
   |
17 |             f(A)
   |               ^ expected struct `b::A`, found struct `a::A`
   |
   = note: expected type `b::A`
              found type `a::A`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Playground:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=5e896cad4b839beefe6ff7cc5bf491f0

@jonas-schievink jonas-schievink added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jun 4, 2019
@treere
Copy link

treere commented Jun 8, 2019

Just to be sure I tested this code with a custom (and empty) derive macro.
The error is the same.

@petrochenkov
Copy link
Contributor

Looks very similar to #56593

@treere
Copy link

treere commented Jun 22, 2019

Same error with a normal macro:

macro_rules! a {
    () => {
        struct A;
    }
}
mod a {
    pub struct A;
}

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

    a!();

    fn f(a: A) {}

    mod c {
        use crate::b::*;

        fn x() {
            f(A)
        }
    }
}

fn main() { }

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=c12c524522f850a1c7aa19b52db060ae

(it is better to add here or open a new issue?)

@dtolnay
Copy link
Member

dtolnay commented Dec 29, 2020

Closing as a duplicate of #56593.

@dtolnay dtolnay closed this as completed Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants