rtic icon indicating copy to clipboard operation
rtic copied to clipboard

Cfg blocks in Shared Resource fields

Open David-OConnor opened this issue 3 years ago • 1 comments

Code to replicate:

    #[shared]
    struct Shared {
        #[cfg(feature = "h7")]
        uart_elrs: Usart<USART7>,
        #[cfg(feature = "g4")]
        uart_elrs: Usart<USART3>
    }

Error:

error: this resource is listed more than once
   --> src\main.rs:310:9
    |
310 |         uart_elrs: Usart<USART3>,
    |         ^^^^^^^^^

For normal struct fields, the syntax I posted is valid. I suspect this has to do with RTIC being macro-based.

For the specific code I mentioned, you could workaround it by feature-gating an alias for USARTx, but ideally, the RTIC macros wouldn't inhibit the above behavior.

David-OConnor avatar Jul 09 '22 17:07 David-OConnor

Indeed, it's a long standing issue to have cfg support. In a nutshell the issue is that we can't analyze if the cfg is active or not, so we need to generate code assuming both are active. This causes clashes in many cases, as you have noticed.

So the general recommendation for now is, don't use cfg in RTIC. Instead, move the cfg to a user type wrapping the thing you want to have in RTIC.

korken89 avatar Aug 02 '22 12:08 korken89

Closing, feel free to reopen if you have more questions.

korken89 avatar Sep 21 '22 18:09 korken89

Why is it closed / 'closed as completed'? Is this a won't-fix?

David-OConnor avatar Sep 21 '22 19:09 David-OConnor