docs(comments): rewrite comments across all crates to the guidelines
Sweep every first-party crate source (1956 .rs files) to the project comment guidelines: delete redundant restatements, decorative banners, change narration, and end-of-line comments; keep and tighten the crucial ones (invariants, bug rationale, SAFETY blocks, ported-source attribution). No functional code changed. Every edit is proven comment-only against the prior tree by a comment-stripping lexer (string/char/raw-string aware) plus a separate doctest-fence check. Where removing a comment made rustfmt or clippy want to re-lay-out adjacent code, the minimal triggering comment is restored so code tokens stay byte-identical. Gates green: cargo fmt --all --check (0 diffs), cargo check and cargo clippy --workspace --all-targets (0 warnings). Adds scripts/check_codegen_comment_guidelines.py — the enforcement gate for these guidelines (flags banners, end-of-line comments, change narration, and commented-out code).
This commit is contained in:
1 parent
ff0fb56c67
commit
a02b555e66
1458 files changed
+10729
-21750
No files matched your search
@@ -1,8 +1,6 @@
|
||||
//! Windows system sleep/wake via `PowerRegisterSuspendResumeNotification`
|
||||
//! with a `DEVICE_NOTIFY_CALLBACK` recipient — no hidden window or message
|
||||
//! loop required (Windows 8+).
|
||||
//!
|
||||
//! NOTE: this module only compiles when targeting Windows.
|
||||
|
||||
use std::os::raw::c_void;
|
||||
|
||||
@@ -29,8 +27,6 @@ struct Context {
|
||||
}
|
||||
|
||||
pub(crate) struct Listener {
|
||||
// Registration handle from `PowerRegisterSuspendResumeNotification`
|
||||
// (a `*mut c_void`; cast to `HPOWERNOTIFY` for unregister).
|
||||
handle: *mut c_void,
|
||||
// Kept alive (and freed in `Drop`) because the OS holds a raw pointer to it.
|
||||
ctx: *mut Context,
|
||||
@@ -70,6 +66,8 @@ impl Listener {
|
||||
|
||||
impl Drop for Listener {
|
||||
fn drop(&mut self) {
|
||||
// SAFETY: unregistering first guarantees the OS can no longer invoke
|
||||
// the callback, so freeing `ctx` afterwards cannot race a live call.
|
||||
unsafe {
|
||||
PowerUnregisterSuspendResumeNotification(self.handle as HPOWERNOTIFY);
|
||||
drop(Box::from_raw(self.ctx));
|
||||
@@ -82,14 +80,14 @@ unsafe extern "system" fn power_callback(
|
||||
event_type: u32,
|
||||
_setting: *const c_void,
|
||||
) -> u32 {
|
||||
// Safe: `context` is the live `Context` we registered with.
|
||||
// SAFETY: `context` is the `Context` pointer we registered with, and the
|
||||
// registration is unregistered before that box is freed.
|
||||
let ctx = unsafe { &*(context as *const Context) };
|
||||
match event_type {
|
||||
PBT_APMSUSPEND => (ctx.callback)(PowerEvent::WillSleep),
|
||||
// A single resume can deliver both PBT_APMRESUMEAUTOMATIC and
|
||||
// PBT_APMRESUMESUSPEND, so `DidWake` may fire twice per wake. That is
|
||||
// fine and intentional: lowering the sleep gate is idempotent, so a
|
||||
// duplicate wake is harmless — do not try to "dedupe" this later.
|
||||
// PBT_APMRESUMESUSPEND, so `DidWake` fires twice per wake. Intentional:
|
||||
// lowering the sleep gate is idempotent, so do not "dedupe" this.
|
||||
PBT_APMRESUMEAUTOMATIC | PBT_APMRESUMESUSPEND => (ctx.callback)(PowerEvent::DidWake),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user