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 macro breaks "use" names resolution #58397

Closed
not-fl3 opened this issue Feb 12, 2019 · 2 comments
Closed

Derive macro breaks "use" names resolution #58397

not-fl3 opened this issue Feb 12, 2019 · 2 comments

Comments

@not-fl3
Copy link

not-fl3 commented Feb 12, 2019

Issue topic is probably confusing - I am not sure whats going on here :)

The problem:

mod components {
    use foobar::*;

    #[derive(Clone)]
    pub struct Foo {
        pub bar: Bar,
    }
    impl Foo {
        pub fn new() -> Foo {
            Foo { bar: Bar }
        }
    }
}

fn main() {
    use self::components::*;

    Foo::new();
}

foobar's lib.rs:

#[derive(Clone)]
pub struct Foo;
#[derive(Clone)]
pub struct Bar;

Entire repo: https://github.com/not-fl3/derivebug

This code fails to build with

error[E0433]: failed to resolve: use of undeclared type or module `Foo`
  --> src/main.rs:18:5
   |
18 |     Foo::new();
   |     ^^^ use of undeclared type or module `Foo`

warning: unused import: `self::components::*`
  --> src/main.rs:16:9
   |
16 |     use self::components::*;
   |         ^^^^^^^^^^^^^^^^^^^
   |
   = note: #[warn(unused_imports)] on by default

But works totally fine without derive(Clone) or with use foobar::Bar instead of use foobar::* in components module.

Working code, with "use foobar::Bar"

mod components {
    //use foobar::*;
    use foobar::Bar;

    #[derive(Clone)]
    pub struct Foo {
        pub bar: Bar,
    }
    impl Foo {
        pub fn new() -> Foo {
            Foo { bar: Bar }
        }
    }
}

fn main() {
    use self::components::*;

    Foo::new();
}

Working code, without "derive"

mod components {
    use foobar::*;

    //#[derive(Clone)]
    pub struct Foo {
        pub bar: Bar,
    }
    impl Foo {
        pub fn new() -> Foo {
            Foo { bar: Bar }
        }
    }
}

fn main() {
    use self::components::*;

    Foo::new();
}

Meta

Same both on nighly and stable:

rustc --version --verbose:

rustc 1.32.0 (9fda7c223 2019-01-16)
binary: rustc
commit-hash: 9fda7c2237db910e41d6a712e9a2139b352e558b
commit-date: 2019-01-16
host: x86_64-unknown-linux-gnu
release: 1.32.0
LLVM version: 8.0```

rustc --version --verbose:

rustc 1.33.0-nightly (4c2be9c97 2019-01-22)
binary: rustc
commit-hash: 4c2be9c97fb60a01c545b8e8fa61e4247ae5c9b2
commit-date: 2019-01-22
host: x86_64-unknown-linux-gnu
release: 1.33.0-nightly
LLVM version: 8.0
@petrochenkov
Copy link
Contributor

Probably a duplicate of #56593

@not-fl3
Copy link
Author

not-fl3 commented Feb 12, 2019

Yes, its definitely the same issue!

@not-fl3 not-fl3 closed this as completed Feb 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants