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

Variable named element clash with macro internal #123

Open
wwylele opened this issue Feb 15, 2022 · 0 comments
Open

Variable named element clash with macro internal #123

wwylele opened this issue Feb 15, 2022 · 0 comments

Comments

@wwylele
Copy link

wwylele commented Feb 15, 2022

The relevant code is pretty old, but the problem was only revealed when I did an update recently. I suspect that the migration away from proc_macro_hack or migration to edition 2021 changed this behavior

The following code no longer compiles at some point

fn foo() {
    let element = ("bar", "baz");
    let _: DOMTree<String> = html!(<div>{text!("{}", element.0)}</div>);
}

The error is

error[E0609]: no field `0` on type `typed_html::elements::div<_>`
   --> src\extract\gen_item.rs:455:62
    |
455 |     let _: DOMTree<String> = html!(<div>{text!("{}", element.0)}</div>);
    |                                                              ^ unknown field
    |
    = note: available fields are: `attrs`, `data_attributes`, `events`, `children`

For more information about this error, try `rustc --explain E0609`.

However, simply renaming the variable solves the problem

fn foo() {
    let element2 = ("bar", "baz");
    let _: DOMTree<String> = html!(<div>{text!("{}", element2.0)}</div>);
}

It looks like the first piece of code uses the leaked macro internal variable.

PS: I know this repo isn't actively maintained, and I am fine with this issue not being resolved soon. Just want to open as a reminder (maybe for myself if I get some time to fix it)

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

1 participant