Skip to content

Wildcard import fails to resolve if a derive is present #56593

Closed
@ennis

Description

@ennis

The following snippet fails to compile with the error [E0412]: cannot find type Foo in this scope

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

struct Foo;          // line 1

mod foo {
    use super::*;    // line 4
    
    // Commenting out the Debug derive makes it work
    #[derive(Debug)] // line 7
    pub struct Foo;
}

mod bar {
    use super::foo::*;
    
    fn bar(_: Foo) {}
}

Expected result: code compiles without issues

I can get it to compile by doing one of those:

  • by removing use super::* on line 4
  • by commenting #[derive(Debug)] at line 7
  • by renaming struct Foo on line 1 to Foo2
  • and curiously, by copy-pasting the generated Debug impl obtained with --pretty=expanded instead of using #[derive(Debug)]

The same issue happens with other derives (Clone,Eq,etc.). Seems like #[derive()] is confused when an item with the same name is visible?

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions