From da831d291e0113f0a7ba244baefea78a897428ba Mon Sep 17 00:00:00 2001 From: Andrew Walbran Date: Tue, 9 Apr 2024 18:14:56 +0100 Subject: [PATCH] Panic if Channel::channel() returns an invalid value. Channel isn't a sealed trait, so we can't assume that the implementation is correct. It's better to panic than have undefined behaviour. --- nrf-hal-common/src/adc.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nrf-hal-common/src/adc.rs b/nrf-hal-common/src/adc.rs index 35cd3b7e..44729bf7 100644 --- a/nrf-hal-common/src/adc.rs +++ b/nrf-hal-common/src/adc.rs @@ -7,7 +7,6 @@ use crate::{ ADC, }, }; -use core::hint::unreachable_unchecked; #[cfg(feature = "embedded-hal-02")] pub trait Channel: embedded_hal_02::adc::Channel {} @@ -83,9 +82,9 @@ impl Adc { .0 .config .modify(|_, w| w.inpsel().supply_two_thirds_prescaling()), - // This can never happen the only analog pins have already been defined - // PAY CLOSE ATTENTION TO ANY CHANGES TO THIS IMPL OR THE `channel_mappings!` MACRO - _ => unsafe { unreachable_unchecked() }, + // This can never happen with the `Channel` implementations provided, as the only analog + // pins have already been covered. + _ => panic!("Invalid channel"), } self.0.events_end.write(|w| unsafe { w.bits(0) });