rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
688 stars 149 forks source link

function with reserved keyword generated #585

Closed tiagomanczak closed 2 years ago

tiagomanczak commented 2 years ago

A specific SFR of the microcontroller has a field which can assume a value descrived by the name DYN. When generation the functions for the field writer for the variant DYN svd2rust generated the following code

pub fn dyn(self) -> &'a mut W {
        self.variant(PAD_FRC_A::DYN)
    }

So during the build I got

error: expected identifier, found keyword `dyn`

Had to scape manually the function name. Please see raw_identifiers for more information.

pub fn r#dyn(self) -> &'a mut W {
        self.variant(PAD_FRC_A::DYN)
    }

Would it be possible to include this as a feature to escape automatically identifiers which match rust's keywords?

Emilgardis commented 2 years ago

we already do this, but dyn is not added to the list

https://github.com/rust-embedded/svd2rust/blob/7264731e4796c3b39a302fae89eab36d33a5008d/src/util.rs#L150-L164

feel free to submit a pr :)

tiagomanczak commented 2 years ago

Nice. Thanks for the quick response. I will create the PR and close this issue as soon as it is merged. :)

Emilgardis commented 2 years ago

Awesome :D

Quick tip for you if you did not know already, if the PR had the text

Fixes #585

This issue would be marked as closed automagically, see this doc