Skip to content

Declaring modules inside decl macros 2.0 #46342

Closed
@valff

Description

@valff

Not sure if it is a bug or confusing error messages. Consider the following code:
Playground

#![feature(decl_macro)]

macro impl_mod($name:ident) {
  pub mod $name {
    pub struct Bar;
  }
}

impl_mod!(foo);

use foo::Bar;

fn main() {}

Output:

error[E0432]: unresolved import `foo::Bar`
  --> src/main.rs:11:5
   |
11 | use foo::Bar;
   |     ^^^^^^^^ no `Bar` in `foo`. Did you mean to use `Bar`?

warning: unused import: `foo::Bar`
  --> src/main.rs:11:5
   |
11 | use foo::Bar;
   |     ^^^^^^^^
   |
   = note: #[warn(unused_imports)] on by default

What is confusing:

  1. So is it unresolved or resolved and unused?
  2. "no 'Bar'. did you mean 'Bar'?" - feels like a bug.
  3. Path foo is accessible, why then foo::Bar not?

rustc --version --verbose:

rustc 1.24.0-nightly (560a5da9f 2017-11-27)
binary: rustc
commit-hash: 560a5da9f1cc7f67d2fc372925aef18c96c82629
commit-date: 2017-11-27
host: x86_64-unknown-linux-gnu
release: 1.24.0-nightly
LLVM version: 4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-bugCategory: This is a bug.F-decl_macro`#![feature(decl_macro)]`T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions