Do not use cfg_if for embedded-hal-async feature gates.

Old code used `cfg_if!` because rustc still parses code inside disabled cfg's, and Rust stable at that time couldn't parse the new GAT where-clause location. This is not the case anymore.
This commit is contained in:
Dario Nieuwenhuis 2022-08-31 02:46:52 +02:00
parent fe08bdf0d8
commit 8ba421f324
10 changed files with 380 additions and 378 deletions

View File

@ -469,10 +469,12 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { mod eha {
use futures::FutureExt; use futures::FutureExt;
use super::*;
impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for Input<'d, T> { impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for Input<'d, T> {
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
@ -536,5 +538,4 @@ cfg_if::cfg_if! {
self.wait_for_any_edge().map(Ok) self.wait_for_any_edge().map(Ok)
} }
} }
}
} }

View File

@ -475,10 +475,12 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { mod eha {
use core::future::Future; use core::future::Future;
use super::*;
impl<'d, T: Instance> embedded_hal_async::spi::SpiBusFlush for Spim<'d, T> { impl<'d, T: Instance> embedded_hal_async::spi::SpiBusFlush for Spim<'d, T> {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
@ -512,14 +514,10 @@ cfg_if::cfg_if! {
type TransferInPlaceFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type TransferInPlaceFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn transfer_in_place<'a>( fn transfer_in_place<'a>(&'a mut self, words: &'a mut [u8]) -> Self::TransferInPlaceFuture<'a> {
&'a mut self,
words: &'a mut [u8],
) -> Self::TransferInPlaceFuture<'a> {
self.transfer_in_place(words) self.transfer_in_place(words)
} }
} }
}
} }
impl<'d, T: Instance> SetConfig for Spim<'d, T> { impl<'d, T: Instance> SetConfig for Spim<'d, T> {

View File

@ -838,8 +838,9 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { mod eha {
use super::*;
impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> { impl<'d, T: Instance> embedded_hal_async::i2c::I2c for Twim<'d, T> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
@ -876,7 +877,6 @@ cfg_if::cfg_if! {
async move { todo!() } async move { todo!() }
} }
} }
}
} }
impl<'d, T: Instance> SetConfig for Twim<'d, T> { impl<'d, T: Instance> SetConfig for Twim<'d, T> {

View File

@ -1073,10 +1073,16 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(
if #[cfg(all(feature = "unstable-traits", feature = "nightly", feature = "_todo_embedded_hal_serial"))] { feature = "unstable-traits",
feature = "nightly",
feature = "_todo_embedded_hal_serial"
))]
mod eha {
use core::future::Future; use core::future::Future;
use super::*;
impl<'d, T: Instance> embedded_hal_async::serial::Read for Uarte<'d, T> { impl<'d, T: Instance> embedded_hal_async::serial::Read for Uarte<'d, T> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
@ -1121,9 +1127,7 @@ cfg_if::cfg_if! {
} }
} }
impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Read impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Read for UarteWithIdle<'d, U, T> {
for UarteWithIdle<'d, U, T>
{
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { fn read<'a>(&'a mut self, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
@ -1131,9 +1135,7 @@ cfg_if::cfg_if! {
} }
} }
impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Write impl<'d, U: Instance, T: TimerInstance> embedded_hal_async::serial::Write for UarteWithIdle<'d, U, T> {
for UarteWithIdle<'d, U, T>
{
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> { fn write<'a>(&'a mut self, buffer: &'a [u8]) -> Self::WriteFuture<'a> {
@ -1146,5 +1148,4 @@ cfg_if::cfg_if! {
async move { Ok(()) } async move { Ok(()) }
} }
} }
}
} }

View File

@ -477,12 +477,17 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(
if #[cfg(all(feature = "unstable-traits", feature = "nightly", feature = "_todo_embedded_hal_serial"))] { feature = "unstable-traits",
feature = "nightly",
feature = "_todo_embedded_hal_serial"
))]
mod eha {
use core::future::Future; use core::future::Future;
impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Write for UartTx<'d, T, M> use super::*;
{
impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Write for UartTx<'d, T, M> {
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> { fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
@ -496,8 +501,7 @@ cfg_if::cfg_if! {
} }
} }
impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Read for UartRx<'d, T, M> impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Read for UartRx<'d, T, M> {
{
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
@ -505,8 +509,7 @@ cfg_if::cfg_if! {
} }
} }
impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Write for Uart<'d, T, M> impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Write for Uart<'d, T, M> {
{
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> { fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
@ -520,15 +523,13 @@ cfg_if::cfg_if! {
} }
} }
impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Read for Uart<'d, T, M> impl<'d, T: Instance, M: Mode> embedded_hal_async::serial::Read for Uart<'d, T, M> {
{
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
self.read(buf) self.read(buf)
} }
} }
}
} }
mod sealed { mod sealed {

View File

@ -165,10 +165,12 @@ mod eh1 {
} }
} }
} }
cfg_if::cfg_if! { #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { mod eha {
use futures::FutureExt; use futures::FutureExt;
use super::*;
impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> { impl<'d, T: GpioPin> embedded_hal_async::digital::Wait for ExtiInput<'d, T> {
type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type WaitForHighFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
@ -200,7 +202,6 @@ cfg_if::cfg_if! {
self.wait_for_any_edge().map(Ok) self.wait_for_any_edge().map(Ok)
} }
} }
}
} }
struct ExtiInputFuture<'a> { struct ExtiInputFuture<'a> {

View File

@ -927,14 +927,14 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { mod eha {
use super::{RxDma, TxDma};
use core::future::Future; use core::future::Future;
impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c use super::super::{RxDma, TxDma};
for I2c<'d, T, TXDMA, RXDMA> use super::*;
{
impl<'d, T: Instance, TXDMA: TxDma<T>, RXDMA: RxDma<T>> embedded_hal_async::i2c::I2c for I2c<'d, T, TXDMA, RXDMA> {
type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
@ -968,7 +968,6 @@ cfg_if::cfg_if! {
async move { todo!() } async move { todo!() }
} }
} }
}
} }
impl<'d, T: Instance> SetConfig for I2c<'d, T> { impl<'d, T: Instance> SetConfig for I2c<'d, T> {

View File

@ -870,9 +870,11 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { mod eha {
use core::future::Future; use core::future::Future;
use super::*;
impl<'d, T: Instance, Tx, Rx> embedded_hal_async::spi::SpiBusFlush for Spi<'d, T, Tx, Rx> { impl<'d, T: Instance, Tx, Rx> embedded_hal_async::spi::SpiBusFlush for Spi<'d, T, Tx, Rx> {
type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type FlushFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
@ -881,9 +883,7 @@ cfg_if::cfg_if! {
} }
} }
impl<'d, T: Instance, Tx: TxDma<T>, Rx, W: Word> embedded_hal_async::spi::SpiBusWrite<W> impl<'d, T: Instance, Tx: TxDma<T>, Rx, W: Word> embedded_hal_async::spi::SpiBusWrite<W> for Spi<'d, T, Tx, Rx> {
for Spi<'d, T, Tx, Rx>
{
type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn write<'a>(&'a mut self, data: &'a [W]) -> Self::WriteFuture<'a> { fn write<'a>(&'a mut self, data: &'a [W]) -> Self::WriteFuture<'a> {
@ -901,9 +901,7 @@ cfg_if::cfg_if! {
} }
} }
impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBus<W> impl<'d, T: Instance, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> embedded_hal_async::spi::SpiBus<W> for Spi<'d, T, Tx, Rx> {
for Spi<'d, T, Tx, Rx>
{
type TransferFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type TransferFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn transfer<'a>(&'a mut self, rx: &'a mut [W], tx: &'a [W]) -> Self::TransferFuture<'a> { fn transfer<'a>(&'a mut self, rx: &'a mut [W], tx: &'a [W]) -> Self::TransferFuture<'a> {
@ -912,14 +910,10 @@ cfg_if::cfg_if! {
type TransferInPlaceFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a; type TransferInPlaceFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a where Self: 'a;
fn transfer_in_place<'a>( fn transfer_in_place<'a>(&'a mut self, words: &'a mut [W]) -> Self::TransferInPlaceFuture<'a> {
&'a mut self,
words: &'a mut [W],
) -> Self::TransferInPlaceFuture<'a> {
self.transfer_in_place(words) self.transfer_in_place(words)
} }
} }
}
} }
pub(crate) mod sealed { pub(crate) mod sealed {

View File

@ -361,10 +361,16 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(
if #[cfg(all(feature = "unstable-traits", feature = "nightly", feature = "_todo_embedded_hal_serial"))] { feature = "unstable-traits",
feature = "nightly",
feature = "_todo_embedded_hal_serial"
))]
mod eha {
use core::future::Future; use core::future::Future;
use super::*;
impl<'d, T: BasicInstance, TxDma> embedded_hal_async::serial::Write for UartTx<'d, T, TxDma> impl<'d, T: BasicInstance, TxDma> embedded_hal_async::serial::Write for UartTx<'d, T, TxDma>
where where
TxDma: crate::usart::TxDma<T>, TxDma: crate::usart::TxDma<T>,
@ -420,7 +426,6 @@ cfg_if::cfg_if! {
self.read(buf) self.read(buf)
} }
} }
}
} }
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]

View File

@ -31,12 +31,15 @@ mod eh1 {
} }
} }
cfg_if::cfg_if! { #[cfg(all(feature = "unstable-traits", feature = "nightly"))]
if #[cfg(all(feature = "unstable-traits", feature = "nightly"))] { mod eha {
use crate::Timer;
use core::future::Future; use core::future::Future;
use futures_util::FutureExt; use futures_util::FutureExt;
use super::*;
use crate::Timer;
impl embedded_hal_async::delay::DelayUs for Delay { impl embedded_hal_async::delay::DelayUs for Delay {
type Error = core::convert::Infallible; type Error = core::convert::Infallible;
@ -52,7 +55,6 @@ cfg_if::cfg_if! {
Timer::after(Duration::from_millis(millis as _)).map(Ok) Timer::after(Duration::from_millis(millis as _)).map(Ok)
} }
} }
}
} }
mod eh02 { mod eh02 {