Skip to content

Commit 0154877

Browse files
committed
async: disable Send lint in async traits
Adds `#[allow(async_fn_in_trait)]` to disable the lint in `async` trait functions recommending `Send` in the return type. Adding the type annotation is currently unstable, has little-to-no utility in current crates using `embedded-hal`, and will break those users. See <#515 (comment)> for details and discussion.
1 parent 8e66252 commit 0154877

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

embedded-hal-async/src/delay.rs

+4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
pub trait DelayUs {
55
/// Pauses execution for at minimum `us` microseconds. Pause can be longer
66
/// if the implementation requires it due to precision/timing issues.
7+
#[allow(async_fn_in_trait)]
78
async fn delay_us(&mut self, us: u32);
89

910
/// Pauses execution for at minimum `ms` milliseconds. Pause can be longer
1011
/// if the implementation requires it due to precision/timing issues.
12+
#[allow(async_fn_in_trait)]
1113
async fn delay_ms(&mut self, ms: u32);
1214
}
1315

@@ -16,11 +18,13 @@ where
1618
T: DelayUs + ?Sized,
1719
{
1820
#[inline]
21+
#[allow(async_fn_in_trait)]
1922
async fn delay_us(&mut self, us: u32) {
2023
T::delay_us(self, us).await;
2124
}
2225

2326
#[inline]
27+
#[allow(async_fn_in_trait)]
2428
async fn delay_ms(&mut self, ms: u32) {
2529
T::delay_ms(self, ms).await;
2630
}

embedded-hal-async/src/digital.rs

+10
Original file line numberDiff line numberDiff line change
@@ -23,53 +23,63 @@ pub trait Wait: embedded_hal::digital::ErrorType {
2323
/// # Note for implementers
2424
/// The pin may have switched back to low before the task was run after
2525
/// being woken. The future should still resolve in that case.
26+
#[allow(async_fn_in_trait)]
2627
async fn wait_for_high(&mut self) -> Result<(), Self::Error>;
2728

2829
/// Wait until the pin is low. If it is already low, return immediately.
2930
///
3031
/// # Note for implementers
3132
/// The pin may have switched back to high before the task was run after
3233
/// being woken. The future should still resolve in that case.
34+
#[allow(async_fn_in_trait)]
3335
async fn wait_for_low(&mut self) -> Result<(), Self::Error>;
3436

3537
/// Wait for the pin to undergo a transition from low to high.
3638
///
3739
/// If the pin is already high, this does *not* return immediately, it'll wait for the
3840
/// pin to go low and then high again.
41+
#[allow(async_fn_in_trait)]
3942
async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error>;
4043

4144
/// Wait for the pin to undergo a transition from high to low.
4245
///
4346
/// If the pin is already low, this does *not* return immediately, it'll wait for the
4447
/// pin to go high and then low again.
48+
#[allow(async_fn_in_trait)]
4549
async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error>;
4650

4751
/// Wait for the pin to undergo any transition, i.e low to high OR high to low.
52+
#[allow(async_fn_in_trait)]
4853
async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error>;
4954
}
5055

5156
impl<T: Wait + ?Sized> Wait for &mut T {
5257
#[inline]
58+
#[allow(async_fn_in_trait)]
5359
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
5460
T::wait_for_high(self).await
5561
}
5662

5763
#[inline]
64+
#[allow(async_fn_in_trait)]
5865
async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
5966
T::wait_for_low(self).await
6067
}
6168

6269
#[inline]
70+
#[allow(async_fn_in_trait)]
6371
async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
6472
T::wait_for_rising_edge(self).await
6573
}
6674

6775
#[inline]
76+
#[allow(async_fn_in_trait)]
6877
async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
6978
T::wait_for_falling_edge(self).await
7079
}
7180

7281
#[inline]
82+
#[allow(async_fn_in_trait)]
7383
async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
7484
T::wait_for_any_edge(self).await
7585
}

embedded-hal-async/src/i2c.rs

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
4242
/// - `NMAK` = master no acknowledge
4343
/// - `SP` = stop condition
4444
#[inline]
45+
#[allow(async_fn_in_trait)]
4546
async fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error> {
4647
self.transaction(address, &mut [Operation::Read(read)])
4748
.await
@@ -64,6 +65,7 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
6465
/// - `Bi` = ith byte of data
6566
/// - `SP` = stop condition
6667
#[inline]
68+
#[allow(async_fn_in_trait)]
6769
async fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error> {
6870
self.transaction(address, &mut [Operation::Write(write)])
6971
.await
@@ -92,6 +94,7 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
9294
/// - `NMAK` = master no acknowledge
9395
/// - `SP` = stop condition
9496
#[inline]
97+
#[allow(async_fn_in_trait)]
9598
async fn write_read(
9699
&mut self,
97100
address: A,
@@ -118,6 +121,7 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
118121
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
119122
/// - `SR` = repeated start condition
120123
/// - `SP` = stop condition
124+
#[allow(async_fn_in_trait)]
121125
async fn transaction(
122126
&mut self,
123127
address: A,
@@ -127,16 +131,19 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
127131

128132
impl<A: AddressMode, T: I2c<A> + ?Sized> I2c<A> for &mut T {
129133
#[inline]
134+
#[allow(async_fn_in_trait)]
130135
async fn read(&mut self, address: A, read: &mut [u8]) -> Result<(), Self::Error> {
131136
T::read(self, address, read).await
132137
}
133138

134139
#[inline]
140+
#[allow(async_fn_in_trait)]
135141
async fn write(&mut self, address: A, write: &[u8]) -> Result<(), Self::Error> {
136142
T::write(self, address, write).await
137143
}
138144

139145
#[inline]
146+
#[allow(async_fn_in_trait)]
140147
async fn write_read(
141148
&mut self,
142149
address: A,
@@ -147,6 +154,7 @@ impl<A: AddressMode, T: I2c<A> + ?Sized> I2c<A> for &mut T {
147154
}
148155

149156
#[inline]
157+
#[allow(async_fn_in_trait)]
150158
async fn transaction(
151159
&mut self,
152160
address: A,

embedded-hal-async/src/spi.rs

+20
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
2626
///
2727
/// On bus errors the implementation should try to deassert CS.
2828
/// If an error occurs while deasserting CS the bus error should take priority as the return value.
29+
#[allow(async_fn_in_trait)]
2930
async fn transaction(
3031
&mut self,
3132
operations: &mut [Operation<'_, Word>],
@@ -37,6 +38,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
3738
///
3839
/// See also: [`SpiDevice::transaction`], [`SpiDevice::read`]
3940
#[inline]
41+
#[allow(async_fn_in_trait)]
4042
async fn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> {
4143
self.transaction(&mut [Operation::Read(buf)]).await
4244
}
@@ -47,6 +49,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
4749
///
4850
/// See also: [`SpiDevice::transaction`], [`SpiDevice::write`]
4951
#[inline]
52+
#[allow(async_fn_in_trait)]
5053
async fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error> {
5154
self.transaction(&mut [Operation::Write(buf)]).await
5255
}
@@ -57,6 +60,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
5760
///
5861
/// See also: [`SpiDevice::transaction`], [`SpiBus::transfer`]
5962
#[inline]
63+
#[allow(async_fn_in_trait)]
6064
async fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error> {
6165
self.transaction(&mut [Operation::Transfer(read, write)])
6266
.await
@@ -68,6 +72,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
6872
///
6973
/// See also: [`SpiDevice::transaction`], [`SpiBus::transfer_in_place`]
7074
#[inline]
75+
#[allow(async_fn_in_trait)]
7176
async fn transfer_in_place(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> {
7277
self.transaction(&mut [Operation::TransferInPlace(buf)])
7378
.await
@@ -76,6 +81,7 @@ pub trait SpiDevice<Word: Copy + 'static = u8>: ErrorType {
7681

7782
impl<Word: Copy + 'static, T: SpiDevice<Word> + ?Sized> SpiDevice<Word> for &mut T {
7883
#[inline]
84+
#[allow(async_fn_in_trait)]
7985
async fn transaction(
8086
&mut self,
8187
operations: &mut [Operation<'_, Word>],
@@ -84,21 +90,25 @@ impl<Word: Copy + 'static, T: SpiDevice<Word> + ?Sized> SpiDevice<Word> for &mut
8490
}
8591

8692
#[inline]
93+
#[allow(async_fn_in_trait)]
8794
async fn read(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> {
8895
T::read(self, buf).await
8996
}
9097

9198
#[inline]
99+
#[allow(async_fn_in_trait)]
92100
async fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error> {
93101
T::write(self, buf).await
94102
}
95103

96104
#[inline]
105+
#[allow(async_fn_in_trait)]
97106
async fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error> {
98107
T::transfer(self, read, write).await
99108
}
100109

101110
#[inline]
111+
#[allow(async_fn_in_trait)]
102112
async fn transfer_in_place(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> {
103113
T::transfer_in_place(self, buf).await
104114
}
@@ -117,12 +127,14 @@ pub trait SpiBus<Word: 'static + Copy = u8>: ErrorType {
117127
///
118128
/// Implementations are allowed to return before the operation is
119129
/// complete. See [the docs on embedded-hal][embedded_hal::spi] for details on flushing.
130+
#[allow(async_fn_in_trait)]
120131
async fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error>;
121132

122133
/// Write `words` to the slave, ignoring all the incoming words.
123134
///
124135
/// Implementations are allowed to return before the operation is
125136
/// complete. See [the docs on embedded-hal][embedded_hal::spi] for details on flushing.
137+
#[allow(async_fn_in_trait)]
126138
async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error>;
127139

128140
/// Write and read simultaneously. `write` is written to the slave on MOSI and
@@ -136,6 +148,7 @@ pub trait SpiBus<Word: 'static + Copy = u8>: ErrorType {
136148
///
137149
/// Implementations are allowed to return before the operation is
138150
/// complete. See [the docs on embedded-hal][embedded_hal::spi] for details on flushing.
151+
#[allow(async_fn_in_trait)]
139152
async fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error>;
140153

141154
/// Write and read simultaneously. The contents of `words` are
@@ -144,36 +157,43 @@ pub trait SpiBus<Word: 'static + Copy = u8>: ErrorType {
144157
///
145158
/// Implementations are allowed to return before the operation is
146159
/// complete. See [the docs on embedded-hal][embedded_hal::spi] for details on flushing.
160+
#[allow(async_fn_in_trait)]
147161
async fn transfer_in_place(&mut self, words: &mut [Word]) -> Result<(), Self::Error>;
148162

149163
/// Wait until all operations have completed and the bus is idle.
150164
///
151165
/// See [the docs on embedded-hal][embedded_hal::spi] for information on flushing.
166+
#[allow(async_fn_in_trait)]
152167
async fn flush(&mut self) -> Result<(), Self::Error>;
153168
}
154169

155170
impl<T: SpiBus<Word> + ?Sized, Word: 'static + Copy> SpiBus<Word> for &mut T {
156171
#[inline]
172+
#[allow(async_fn_in_trait)]
157173
async fn read(&mut self, words: &mut [Word]) -> Result<(), Self::Error> {
158174
T::read(self, words).await
159175
}
160176

161177
#[inline]
178+
#[allow(async_fn_in_trait)]
162179
async fn write(&mut self, words: &[Word]) -> Result<(), Self::Error> {
163180
T::write(self, words).await
164181
}
165182

166183
#[inline]
184+
#[allow(async_fn_in_trait)]
167185
async fn transfer(&mut self, read: &mut [Word], write: &[Word]) -> Result<(), Self::Error> {
168186
T::transfer(self, read, write).await
169187
}
170188

171189
#[inline]
190+
#[allow(async_fn_in_trait)]
172191
async fn transfer_in_place(&mut self, words: &mut [Word]) -> Result<(), Self::Error> {
173192
T::transfer_in_place(self, words).await
174193
}
175194

176195
#[inline]
196+
#[allow(async_fn_in_trait)]
177197
async fn flush(&mut self) -> Result<(), Self::Error> {
178198
T::flush(self).await
179199
}

embedded-io-async/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub trait Read: ErrorType {
4646
/// the hardware with e.g. DMA.
4747
///
4848
/// Implementations should document whether they're actually side-effect-free on cancel or not.
49+
#[allow(async_fn_in_trait)]
4950
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error>;
5051

5152
/// Read the exact number of bytes required to fill `buf`.
@@ -55,6 +56,7 @@ pub trait Read: ErrorType {
5556
///
5657
/// This function is not side-effect-free on cancel (AKA "cancel-safe"), i.e. if you cancel (drop) a returned
5758
/// future that hasn't completed yet, some bytes might have already been read, which will get lost.
59+
#[allow(async_fn_in_trait)]
5860
async fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<(), ReadExactError<Self::Error>> {
5961
while !buf.is_empty() {
6062
match self.read(buf).await {
@@ -82,6 +84,7 @@ pub trait BufRead: ErrorType {
8284
/// If the reader is at end-of-file (EOF), an empty slice is returned. There is no guarantee that a reader at EOF
8385
/// will always be so in the future, for example a reader can stop being at EOF if another process appends
8486
/// more bytes to the underlying file.
87+
#[allow(async_fn_in_trait)]
8588
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error>;
8689

8790
/// Tell this buffer that `amt` bytes have been consumed from the buffer, so they should no longer be returned in calls to `fill_buf`.
@@ -116,9 +119,11 @@ pub trait Write: ErrorType {
116119
/// the hardware with e.g. DMA.
117120
///
118121
/// Implementations should document whether they're actually side-effect-free on cancel or not.
122+
#[allow(async_fn_in_trait)]
119123
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>;
120124

121125
/// Flush this output stream, ensuring that all intermediately buffered contents reach their destination.
126+
#[allow(async_fn_in_trait)]
122127
async fn flush(&mut self) -> Result<(), Self::Error> {
123128
Ok(())
124129
}
@@ -130,6 +135,7 @@ pub trait Write: ErrorType {
130135
///
131136
/// This function is not side-effect-free on cancel (AKA "cancel-safe"), i.e. if you cancel (drop) a returned
132137
/// future that hasn't completed yet, some bytes might have already been written.
138+
#[allow(async_fn_in_trait)]
133139
async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> {
134140
let mut buf = buf;
135141
while !buf.is_empty() {
@@ -148,28 +154,33 @@ pub trait Write: ErrorType {
148154
/// This trait is the `embedded-io-async` equivalent of [`std::io::Seek`].
149155
pub trait Seek: ErrorType {
150156
/// Seek to an offset, in bytes, in a stream.
157+
#[allow(async_fn_in_trait)]
151158
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error>;
152159

153160
/// Rewind to the beginning of a stream.
161+
#[allow(async_fn_in_trait)]
154162
async fn rewind(&mut self) -> Result<(), Self::Error> {
155163
self.seek(SeekFrom::Start(0)).await?;
156164
Ok(())
157165
}
158166

159167
/// Returns the current seek position from the start of the stream.
168+
#[allow(async_fn_in_trait)]
160169
async fn stream_position(&mut self) -> Result<u64, Self::Error> {
161170
self.seek(SeekFrom::Current(0)).await
162171
}
163172
}
164173

165174
impl<T: ?Sized + Read> Read for &mut T {
166175
#[inline]
176+
#[allow(async_fn_in_trait)]
167177
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
168178
T::read(self, buf).await
169179
}
170180
}
171181

172182
impl<T: ?Sized + BufRead> BufRead for &mut T {
183+
#[allow(async_fn_in_trait)]
173184
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
174185
T::fill_buf(self).await
175186
}
@@ -181,18 +192,21 @@ impl<T: ?Sized + BufRead> BufRead for &mut T {
181192

182193
impl<T: ?Sized + Write> Write for &mut T {
183194
#[inline]
195+
#[allow(async_fn_in_trait)]
184196
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
185197
T::write(self, buf).await
186198
}
187199

188200
#[inline]
201+
#[allow(async_fn_in_trait)]
189202
async fn flush(&mut self) -> Result<(), Self::Error> {
190203
T::flush(self).await
191204
}
192205
}
193206

194207
impl<T: ?Sized + Seek> Seek for &mut T {
195208
#[inline]
209+
#[allow(async_fn_in_trait)]
196210
async fn seek(&mut self, pos: SeekFrom) -> Result<u64, Self::Error> {
197211
T::seek(self, pos).await
198212
}

0 commit comments

Comments
 (0)