Open adamgreig opened 1 year ago
Yes I've been stung by this too after the change 😅
I think using compile_error!()
could be a good idea, but how would we make that work in a good way so that critical-section
doesn't become a needed dependency? compile_error!()
causes a compile error whenever it is present anywhere as a result of a macro or normal source generation, i.e simply having fn foo() {compile_error!()}
causes a compile time error, even if it's never used in a binary
I think having it be a missing symbol is the better alternative, but perhaps there is another way to solve it.
I ran into this issue recently, and I noticed that our pac (without critical-section) is missing take()
for Peripherals
but take()
is present for CorePeripherals
. Should this be considered a bug? In my mind CorePeripherals
and Peripherals
should behave in the exact same way.
Nevermind, I looked through the code and the impl Peripherals
for CorePeripherals
comes from the cortex-m
crate.
So, it might be somewhat inconsistent but it's not really connected to svd2rust
specifically.
Currently the
Peripherals::take()
method is gated behind thecritical-section
optional dependency (and thus feature). Without the feature enabled, the method isn't available, because it requires thecritical-section
crate and we wanted to make that dependency optional (#651).However it turns out if you call
take()
on a struct that doesn't have that method, Rust thinks you wanted to call the method on theIterator
trait that's imported by default, and then you get a pretty confusing error message aboutPeripherals
not implementingIterator
(example):This seems to really throw people off because there's no indication that
take()
didn't exist or was feature-gated. I wonder if we should either...take()
; it should build fine and only error about a missing c-s implementation iftake()
is actually called, in which case at least the error message is better, ortake()
, but if thecritical-section
feature is not enabled, usecompile_error!()
to emit a custom compiler error instead of the very confusing one we currently get.