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

resolve failed for macro-2.0 #114289

Closed
bvanjoi opened this issue Jul 31, 2023 · 3 comments
Closed

resolve failed for macro-2.0 #114289

bvanjoi opened this issue Jul 31, 2023 · 3 comments
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. F-decl_macro `#![feature(decl_macro)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bvanjoi
Copy link
Contributor

bvanjoi commented Jul 31, 2023

I tried this code:

#![feature(decl_macro)]
macro_rules! m {
    ($i:ident) => {
        mod $i {
            pub struct A;
        }
    }
}

m!(x);

fn main() {
    let a: x::A = x::A;
}

I expected to see this happen: compile pass

Instead, this happened: compile failed and report: "error[E0412]: cannot find type A in module x"

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (32303b219 2023-07-29)
binary: rustc
commit-hash: 32303b219d4dffa447aa606bc11c7a648f44a862
commit-date: 2023-07-29
host: aarch64-apple-darwin
release: 1.73.0-nightly
LLVM version: 16.0.5
@bvanjoi bvanjoi added the C-bug Category: This is a bug. label Jul 31, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 31, 2023
@ehuss
Copy link
Contributor

ehuss commented Jul 31, 2023

Thanks for the report! I believe this is the same as #91249. The identifiers in the macro have def-site hygiene, which makes them unavailable at the call-site. decl_macros are still unfinished, and I believe controlling hygiene is one of the things that still needs some work.

@ScottLL
Copy link

ScottLL commented Jul 31, 2023

Add the macro 'm!(x)' to the code which will declare the type 'x::A'. This should fix the error encountered.

@Noratrieb Noratrieb added A-macros-2.0 Area: Declarative macros 2.0 (#39412) F-decl_macro `#![feature(decl_macro)]` 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 3, 2023
@fmease
Copy link
Member

fmease commented Oct 2, 2023

Your code actually compiles, you'd need to replace macro_rules! with macro to get the error you mentioned.

In any case, as ehuss said, macros 2.0 employ def-site hygiene. Closing as duplicate of #91249.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros-2.0 Area: Declarative macros 2.0 (#39412) C-bug Category: This is a bug. F-decl_macro `#![feature(decl_macro)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants