From 149caa110d8565c147aeca9ecf59d89f1beb5748 Mon Sep 17 00:00:00 2001 From: Dom Dwyer Date: Sun, 6 Apr 2025 23:00:26 +0200 Subject: [PATCH 1/2] refactor: add must_use to event loop handles This helps catch accidental misuse of the event loop subscription API, wherein a subscription is created and then immediately removed due to the returned handle not being retained. --- CHANGELOG.md | 1 + src/eventloop.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8bd043b837..352099f0de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - OTA: Allow specifying image size to speed up erase - Bluetooth: New methods `EspBleGap::start_scanning` and `EspBleGap::stop_scanning` - New example, `bt_ble_gap_scanner` to demonstrate usage of added ble scanning methods +- Add #[must_use] annotations to event loop types with drop handlers. ## [0.51.0] - 2025-01-15 diff --git a/src/eventloop.rs b/src/eventloop.rs index 64cd5685e1d..c8d8a40e6e0 100644 --- a/src/eventloop.rs +++ b/src/eventloop.rs @@ -331,6 +331,7 @@ where } } +#[must_use = "Event subscription is unregistered when handle is dropped"] pub struct EspSubscription<'a, T> where T: EspEventLoopType, @@ -486,6 +487,7 @@ where } } +#[must_use = "Event loop is deleted when handle is dropped"] #[derive(Debug)] struct EventLoopHandle(T) where From 717c0fb4d55adc1419f83f5c0570589b8ce09a6a Mon Sep 17 00:00:00 2001 From: Dom Dwyer Date: Mon, 7 Apr 2025 22:42:22 +0200 Subject: [PATCH 2/2] refactor: remove EventLoopHandle must_use This is non-pub. --- src/eventloop.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/eventloop.rs b/src/eventloop.rs index c8d8a40e6e0..6e054434468 100644 --- a/src/eventloop.rs +++ b/src/eventloop.rs @@ -487,7 +487,6 @@ where } } -#[must_use = "Event loop is deleted when handle is dropped"] #[derive(Debug)] struct EventLoopHandle(T) where