Skip to content

decl_macro. no field 0 on type. a field with a similar name exists: 0 #116334

Closed
@ple1n

Description

@ple1n

I tried this code:

https://github.com/planetoryd/rust_bug_missing_field

#![feature(decl_macro)]

make_struct!(Uh);

macro make_struct ($id:ident) {
    pub struct $id(pub i32);
}

fn main() {
    let k = Uh(2);
    println!("{}", k.0);
}

The equivalent code without macro works.

hash@hash-pc /s/e/missing_field (master)> cargo b
   Compiling missing_field v0.1.0 (/space/experim/missing_field)
error[E0609]: no field `0` on type `Uh`
  --> src/main.rs:11:22
   |
11 |     println!("{}", k.0);
   |                      ^ help: a field with a similar name exists: `0`

For more information about this error, try `rustc --explain E0609`.
error: could not compile `missing_field` (bin "missing_field") due to previous error
warning: build failed, waiting for other jobs to finish...

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (e0d7ed1f4 2023-10-01)
binary: rustc
commit-hash: e0d7ed1f453fb54578cc96dfea859b0e7be15016
commit-date: 2023-10-01
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: **17.0.2**

Metadata

Metadata

Assignees

Labels

A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)A-diagnosticsArea: Messages for errors, warnings, and lintsA-hygieneArea: Macro hygieneD-confusingDiagnostics: Confusing error or lint that should be reworked.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.F-decl_macro`#![feature(decl_macro)]`T-compilerRelevant to the compiler 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