Mark Unborrow as unsafe to implement

This commit is contained in:
Dario Nieuwenhuis 2021-05-19 23:21:31 +02:00
parent dc67d2f4a4
commit 105c8504b6
10 changed files with 37 additions and 37 deletions

View File

@ -16,7 +16,7 @@ macro_rules! peripherals {
} }
$(#[$cfg])? $(#[$cfg])?
impl embassy::util::Unborrow for $name { unsafe impl embassy::util::Unborrow for $name {
type Target = $name; type Target = $name;
#[inline] #[inline]
unsafe fn unborrow(self) -> $name { unsafe fn unborrow(self) -> $name {
@ -78,9 +78,9 @@ macro_rules! unborrow {
} }
#[macro_export] #[macro_export]
macro_rules! impl_unborrow { macro_rules! unsafe_impl_unborrow {
($type:ident) => { ($type:ident) => {
impl ::embassy::util::Unborrow for $type { unsafe impl ::embassy::util::Unborrow for $type {
type Target = $type; type Target = $type;
#[inline] #[inline]
unsafe fn unborrow(self) -> Self::Target { unsafe fn unborrow(self) -> Self::Target {

View File

@ -210,7 +210,7 @@ pub fn interrupt_declare(item: TokenStream) -> TokenStream {
} }
} }
impl ::embassy::util::Unborrow for #name_interrupt { unsafe impl ::embassy::util::Unborrow for #name_interrupt {
type Target = #name_interrupt; type Target = #name_interrupt;
unsafe fn unborrow(self) -> #name_interrupt { unsafe fn unborrow(self) -> #name_interrupt {
self self

View File

@ -5,7 +5,7 @@ use core::hint::unreachable_unchecked;
use core::marker::PhantomData; use core::marker::PhantomData;
use embassy::util::Unborrow; use embassy::util::Unborrow;
use embassy_extras::{impl_unborrow, unborrow}; use embassy_extras::{unborrow, unsafe_impl_unborrow};
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
use gpio::pin_cnf::DRIVE_A; use gpio::pin_cnf::DRIVE_A;
@ -330,7 +330,7 @@ pub(crate) mod sealed {
pub trait OptionalPin {} pub trait OptionalPin {}
} }
pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized { pub trait Pin: Unborrow<Target = Self> + sealed::Pin + Sized + 'static {
/// Number of the pin within the port (0..31) /// Number of the pin within the port (0..31)
#[inline] #[inline]
fn pin(&self) -> u8 { fn pin(&self) -> u8 {
@ -374,7 +374,7 @@ impl AnyPin {
} }
} }
impl_unborrow!(AnyPin); unsafe_impl_unborrow!(AnyPin);
impl Pin for AnyPin {} impl Pin for AnyPin {}
impl sealed::Pin for AnyPin { impl sealed::Pin for AnyPin {
#[inline] #[inline]
@ -469,7 +469,7 @@ impl<T: Pin> OptionalPin for T {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct NoPin; pub struct NoPin;
impl_unborrow!(NoPin); unsafe_impl_unborrow!(NoPin);
impl sealed::OptionalPin for NoPin {} impl sealed::OptionalPin for NoPin {}
impl OptionalPin for NoPin { impl OptionalPin for NoPin {
type Pin = AnyPin; type Pin = AnyPin;

View File

@ -5,7 +5,7 @@ use core::task::{Context, Poll};
use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::interrupt::{Interrupt, InterruptExt};
use embassy::traits::gpio::{WaitForAnyEdge, WaitForHigh, WaitForLow}; use embassy::traits::gpio::{WaitForAnyEdge, WaitForHigh, WaitForLow};
use embassy::util::AtomicWaker; use embassy::util::AtomicWaker;
use embassy_extras::impl_unborrow; use embassy_extras::unsafe_impl_unborrow;
use embedded_hal::digital::v2::{InputPin, StatefulOutputPin}; use embedded_hal::digital::v2::{InputPin, StatefulOutputPin};
use futures::future::poll_fn; use futures::future::poll_fn;
@ -382,7 +382,7 @@ pub trait Channel: sealed::Channel + Sized {
pub struct AnyChannel { pub struct AnyChannel {
number: u8, number: u8,
} }
impl_unborrow!(AnyChannel); unsafe_impl_unborrow!(AnyChannel);
impl sealed::Channel for AnyChannel {} impl sealed::Channel for AnyChannel {}
impl Channel for AnyChannel { impl Channel for AnyChannel {
fn number(&self) -> usize { fn number(&self) -> usize {

View File

@ -12,7 +12,7 @@
use core::marker::PhantomData; use core::marker::PhantomData;
use core::ptr::NonNull; use core::ptr::NonNull;
use embassy::util::Unborrow; use embassy::util::Unborrow;
use embassy_extras::{impl_unborrow, unborrow}; use embassy_extras::{unborrow, unsafe_impl_unborrow};
use crate::{pac, peripherals}; use crate::{pac, peripherals};
@ -146,7 +146,7 @@ pub trait Group: sealed::Group + Sized {
pub struct AnyChannel { pub struct AnyChannel {
number: u8, number: u8,
} }
impl_unborrow!(AnyChannel); unsafe_impl_unborrow!(AnyChannel);
impl sealed::Channel for AnyChannel {} impl sealed::Channel for AnyChannel {}
impl Channel for AnyChannel { impl Channel for AnyChannel {
fn number(&self) -> usize { fn number(&self) -> usize {
@ -157,7 +157,7 @@ impl Channel for AnyChannel {
pub struct AnyConfigurableChannel { pub struct AnyConfigurableChannel {
number: u8, number: u8,
} }
impl_unborrow!(AnyConfigurableChannel); unsafe_impl_unborrow!(AnyConfigurableChannel);
impl sealed::Channel for AnyConfigurableChannel {} impl sealed::Channel for AnyConfigurableChannel {}
impl sealed::ConfigurableChannel for AnyConfigurableChannel {} impl sealed::ConfigurableChannel for AnyConfigurableChannel {}
impl ConfigurableChannel for AnyConfigurableChannel {} impl ConfigurableChannel for AnyConfigurableChannel {}
@ -226,7 +226,7 @@ impl_channel!(PPI_CH31, 31);
pub struct AnyGroup { pub struct AnyGroup {
number: u8, number: u8,
} }
impl_unborrow!(AnyGroup); unsafe_impl_unborrow!(AnyGroup);
impl sealed::Group for AnyGroup {} impl sealed::Group for AnyGroup {}
impl Group for AnyGroup { impl Group for AnyGroup {
fn number(&self) -> usize { fn number(&self) -> usize {

View File

@ -190,7 +190,7 @@ impl<'d, T: PositivePin> Sample for OneShot<'d, T> {
/// A pin that can be used as the positive end of a ADC differential in the SAADC periperhal. /// A pin that can be used as the positive end of a ADC differential in the SAADC periperhal.
/// ///
/// Currently negative is always shorted to ground (0V). /// Currently negative is always shorted to ground (0V).
pub trait PositivePin { pub trait PositivePin: Unborrow<Target = Self> {
fn channel(&self) -> PositiveChannel; fn channel(&self) -> PositiveChannel;
} }

View File

@ -6,7 +6,7 @@ use crate::pac::SIO;
use crate::peripherals; use crate::peripherals;
use embassy::util::Unborrow; use embassy::util::Unborrow;
use embassy_extras::{impl_unborrow, unborrow}; use embassy_extras::{unborrow, unsafe_impl_unborrow};
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
/// Represents a digital input or output level. /// Represents a digital input or output level.
@ -209,7 +209,7 @@ pub trait Pin: sealed::Pin {
pub struct AnyPin { pub struct AnyPin {
pin_bank: u8, pin_bank: u8,
} }
impl_unborrow!(AnyPin); unsafe_impl_unborrow!(AnyPin);
impl Pin for AnyPin {} impl Pin for AnyPin {}
impl sealed::Pin for AnyPin { impl sealed::Pin for AnyPin {
fn pin_bank(&self) -> u8 { fn pin_bank(&self) -> u8 {

View File

@ -7,7 +7,7 @@ use core::task::{Context, Poll};
use embassy::interrupt::{Interrupt, InterruptExt}; use embassy::interrupt::{Interrupt, InterruptExt};
use embassy::traits::gpio::{WaitForAnyEdge, WaitForFallingEdge, WaitForRisingEdge}; use embassy::traits::gpio::{WaitForAnyEdge, WaitForFallingEdge, WaitForRisingEdge};
use embassy::util::{AtomicWaker, Unborrow}; use embassy::util::{AtomicWaker, Unborrow};
use embassy_extras::impl_unborrow; use embassy_extras::unsafe_impl_unborrow;
use embedded_hal::digital::v2::InputPin; use embedded_hal::digital::v2::InputPin;
use pac::exti::{regs, vals}; use pac::exti::{regs, vals};
@ -214,7 +214,7 @@ pub trait Channel: sealed::Channel + Sized {
pub struct AnyChannel { pub struct AnyChannel {
number: u8, number: u8,
} }
impl_unborrow!(AnyChannel); unsafe_impl_unborrow!(AnyChannel);
impl sealed::Channel for AnyChannel {} impl sealed::Channel for AnyChannel {}
impl Channel for AnyChannel { impl Channel for AnyChannel {
fn number(&self) -> usize { fn number(&self) -> usize {

View File

@ -2,7 +2,7 @@
use core::convert::Infallible; use core::convert::Infallible;
use core::marker::PhantomData; use core::marker::PhantomData;
use embassy::util::Unborrow; use embassy::util::Unborrow;
use embassy_extras::{impl_unborrow, unborrow}; use embassy_extras::{unborrow, unsafe_impl_unborrow};
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin}; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
use crate::pac; use crate::pac;
@ -254,7 +254,7 @@ impl AnyPin {
} }
} }
impl_unborrow!(AnyPin); unsafe_impl_unborrow!(AnyPin);
impl Pin for AnyPin { impl Pin for AnyPin {
type ExtiChannel = crate::exti::AnyChannel; type ExtiChannel = crate::exti::AnyChannel;
} }
@ -297,7 +297,7 @@ impl<T: Pin> OptionalPin for T {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct NoPin; pub struct NoPin;
impl_unborrow!(NoPin); unsafe_impl_unborrow!(NoPin);
impl sealed::OptionalPin for NoPin {} impl sealed::OptionalPin for NoPin {}
impl OptionalPin for NoPin { impl OptionalPin for NoPin {
type Pin = AnyPin; type Pin = AnyPin;

View File

@ -17,12 +17,12 @@ pub use portal::*;
pub use signal::*; pub use signal::*;
pub use waker::*; pub use waker::*;
pub trait Unborrow { pub unsafe trait Unborrow {
type Target; type Target;
unsafe fn unborrow(self) -> Self::Target; unsafe fn unborrow(self) -> Self::Target;
} }
impl<'a, T: Unborrow> Unborrow for &'a mut T { unsafe impl<'a, T: Unborrow> Unborrow for &'a mut T {
type Target = T::Target; type Target = T::Target;
unsafe fn unborrow(self) -> Self::Target { unsafe fn unborrow(self) -> Self::Target {
T::unborrow(core::ptr::read(self)) T::unborrow(core::ptr::read(self))
@ -33,9 +33,9 @@ pub trait Steal {
unsafe fn steal() -> Self; unsafe fn steal() -> Self;
} }
macro_rules! impl_unborrow_tuples { macro_rules! unsafe_impl_unborrow_tuples {
($($t:ident),+) => { ($($t:ident),+) => {
impl<$($t),+> Unborrow for ($($t),+) unsafe impl<$($t),+> Unborrow for ($($t),+)
where where
$( $(
$t: Unborrow<Target = $t> $t: Unborrow<Target = $t>
@ -51,14 +51,14 @@ macro_rules! impl_unborrow_tuples {
}; };
} }
impl_unborrow_tuples!(A, B); unsafe_impl_unborrow_tuples!(A, B);
impl_unborrow_tuples!(A, B, C); unsafe_impl_unborrow_tuples!(A, B, C);
impl_unborrow_tuples!(A, B, C, D); unsafe_impl_unborrow_tuples!(A, B, C, D);
impl_unborrow_tuples!(A, B, C, D, E); unsafe_impl_unborrow_tuples!(A, B, C, D, E);
impl_unborrow_tuples!(A, B, C, D, E, F); unsafe_impl_unborrow_tuples!(A, B, C, D, E, F);
impl_unborrow_tuples!(A, B, C, D, E, F, G); unsafe_impl_unborrow_tuples!(A, B, C, D, E, F, G);
impl_unborrow_tuples!(A, B, C, D, E, F, G, H); unsafe_impl_unborrow_tuples!(A, B, C, D, E, F, G, H);
impl_unborrow_tuples!(A, B, C, D, E, F, G, H, I); unsafe_impl_unborrow_tuples!(A, B, C, D, E, F, G, H, I);
impl_unborrow_tuples!(A, B, C, D, E, F, G, H, I, J); unsafe_impl_unborrow_tuples!(A, B, C, D, E, F, G, H, I, J);
impl_unborrow_tuples!(A, B, C, D, E, F, G, H, I, J, K); unsafe_impl_unborrow_tuples!(A, B, C, D, E, F, G, H, I, J, K);
impl_unborrow_tuples!(A, B, C, D, E, F, G, H, I, J, K, L); unsafe_impl_unborrow_tuples!(A, B, C, D, E, F, G, H, I, J, K, L);