common/peripheral: do not require mut in PeripheralRef clone_unchecked.

This commit is contained in:
Dario Nieuwenhuis
2023-04-11 23:00:14 +02:00
parent 5c42ca13bd
commit 9a677ab618
11 changed files with 16 additions and 17 deletions

View File

@ -180,7 +180,7 @@ fn main() {
#[cfg(flash)]
impl<'d> FlashLayout<'d> {
pub(crate) fn new(mut p: embassy_hal_common::PeripheralRef<'d, crate::peripherals::FLASH>) -> Self {
pub(crate) fn new(p: embassy_hal_common::PeripheralRef<'d, crate::peripherals::FLASH>) -> Self {
Self {
#(#inits),*
}

View File

@ -33,8 +33,7 @@ impl<'d> Flash<'d> {
}
pub(crate) fn release(self) -> PeripheralRef<'d, crate::peripherals::FLASH> {
let mut flash = self;
unsafe { flash.inner.clone_unchecked() }
unsafe { self.inner.clone_unchecked() }
}
}

View File

@ -67,7 +67,7 @@ mod alt_regions {
// SAFETY: We never expose the cloned peripheral references, and their instance is not public.
// Also, all flash region operations are protected with a cs.
let mut p = self.release();
let p = self.release();
AltFlashLayout {
bank1_region1: Bank1Region1(&BANK1_REGION1, unsafe { p.clone_unchecked() }),
bank1_region2: Bank1Region2(&BANK1_REGION2, unsafe { p.clone_unchecked() }),

View File

@ -29,7 +29,7 @@ impl<'d, T: Pin> Flex<'d, T> {
}
#[inline]
pub fn degrade(mut self) -> Flex<'d, AnyPin> {
pub fn degrade(self) -> Flex<'d, AnyPin> {
// Safety: We are about to drop the other copy of this pin, so
// this clone is safe.
let pin = unsafe { self.pin.clone_unchecked() };