Skip to content

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

Merged
dtolnay merged 2 commits into
serde-rs:masterfrom
dtolnay:withlocal
Oct 22, 2024
Merged

dtolnay merged 2 commits into
serde-rs:masterfrom
dtolnay:withlocal

Conversation

@dtolnay

@dtolnay dtolnay commented Oct 22, 2024

Copy link
Copy Markdown
Member

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
@dtolnay
dtolnay deleted the withlocal branch October 22, 2024 16:41
Comment thread serde_derive/src/de.rs
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
Copy Markdown
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