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

Fix hygiene of macro-generated local variable accesses in serde(with) wrappers #2845

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Oct 22, 2024

Fixes #2844.

    error[E0424]: expected value, found module `self`
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    5  |         #[derive(Serialize, Deserialize)]
       |                  --------- this function has a `self` parameter, but a macro invocation can only access identifiers it receives from parameters
    ...
    13 | declare_in_macro!("with");
       |                   ^^^^^^ `self` value is a keyword only available in methods with a `self` parameter

    error[E0425]: cannot find value `__s` in this scope
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    13 | declare_in_macro!("with");
       |                   ^^^^^^ not found in this scope

    error[E0425]: cannot find value `__deserializer` in this scope
      --> test_suite/tests/regression/issue2844.rs:13:19
       |
    13 | declare_in_macro!("with");
       |                   ^^^^^^ not found in this scope
@dtolnay dtolnay merged commit 1ac054b into serde-rs:master Oct 22, 2024
15 checks passed
@dtolnay dtolnay deleted the withlocal branch October 22, 2024 16:41
@@ -2882,13 +2882,14 @@ fn wrap_deserialize_with(
let (de_impl_generics, de_ty_generics, ty_generics, where_clause) =
split_with_de_lifetime(params);
let delife = params.borrowed.de_lifetime();
let deserializer_var = quote!(__deserializer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it would be useful to explain why this line (and in other similar places) placed in it's own TokenStream so this part was not accidentally optimized (yes, new tests will catch that, but this can create unnecessary friction for developers whos not aware of that problem). Even reference to GitHub issue with very short comment will be enougth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

serde 1.0.211 breaks with = "" inside of macros
2 participants