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

Use #[automatically_derived] in all generated code #814

Closed
clechasseur opened this issue Dec 26, 2024 · 4 comments
Closed

Use #[automatically_derived] in all generated code #814

clechasseur opened this issue Dec 26, 2024 · 4 comments

Comments

@clechasseur
Copy link

I am using serde_with in a small project and am seeing missing line coverage in my code coverage report, pointing to my #[derive] directives. Apparently, this can be avoided by adding the #[automatically_derived] attribute to generated code.

I've done a quick search in this repository and it seems to be used already for some generated code, so I can only assume there are places it isn't used yet (I'm not very familiar with derive macro implementation so I can't be certain 🙂).

Here's an example of how I use serde_with:

https://github.com/clechasseur/aoc_leaderbot/blob/fa643db51d692821b01c9094007f2434b1ecc371/aoc_leaderboard/src/aoc.rs#L40

This is not high-priority for me as I am just poking around a toy project, but I thought I'd report it in any case. If I can be of further assistance, don't hesitate to ask.

@clechasseur
Copy link
Author

Hmm, I just noticed that the highlighted line is the one with the #[derive], but #[serde_as] is not a derive macro. So perhaps the problem lies elsewhere. You can see the highlighted line here:

https://app.codecov.io/gh/clechasseur/aoc_leaderbot/pull/3/blob/aoc_leaderboard/src/aoc.rs#L22

It seems to highlight Deserialize, but the weird thing is that I have other structs that derive Deserialize but don't use #[serde_as] and they're not tagged as uncovered.

@jonasbb
Copy link
Owner

jonasbb commented Jan 1, 2025

I don't think this is a problem with serde_with. I modified one of your other structs to use the serde(with="...") attribute, without anything from serde_with. Here is the addition of with="PuzzleCompletionInfo". I see a miss in the Deserialize derive here as well.

/// Information about the completion of a day in an [Advent of Code] event.
///
/// [Advent of Code]: https://adventofcode.com/
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct CompletionDayLevel {
    /// Info about the completion of the day's part 1.
    #[serde(rename = "1", with="PuzzleCompletionInfo")]
    pub part_1: PuzzleCompletionInfo,

    /// Info about the completion of the day's part 2.
    ///
    /// Can be [`None`] if user has not yet solved part 2.
    #[serde(rename = "2", default, skip_serializing_if = "Option::is_none")]
    pub part_2: Option<PuzzleCompletionInfo>,
}

As such, I think this is an issue with the normal serde derives. I took a quick look at serde, but didn't find a missing #[automatically_derived] there either, but opening an issue might be worth it.

@clechasseur
Copy link
Author

Thank you, and sorry if I entered the issue in the wrong project; debugging code coverage in macro-generated code is non-trivial and I guess I didn't put the finger on the right problem. I'll try to come up with a more minimal repro and look at the serde crate itself. Feel free to close this issue.

@jonasbb
Copy link
Owner

jonasbb commented Jan 1, 2025

No problem, such a debugging challenge is nice once in a while :) There was some recent stuff in the serde repo about the Deserialize derive and llvm-cov: serde-rs/serde#2866 and serde-rs/serde#2868. Both should be included in v1.0.216 of serde, which you seem to use.

@jonasbb jonasbb closed this as completed Jan 1, 2025
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

2 participants