Skip to content

Commit af8ebdc

Browse files
refactor: enable missing_panics_doc clippy lint (#1006)
> Checks the doc comments of publicly visible functions that may panic and warns if there is no # Panics section. Co-authored-by: Benoît Cortier <3809077+CBenoit@users.noreply.github.com>
1 parent ce298d1 commit af8ebdc

File tree

21 files changed

+73
-18
lines changed

21 files changed

+73
-18
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ same_name_method = "warn"
115115
string_slice = "warn"
116116
suspicious_xor_used_as_pow = "warn"
117117
unused_result_ok = "warn"
118+
missing_panics_doc = "warn"
118119

119120
# == Style, readability == #
120121
semicolon_outside_block = "warn" # With semicolon-outside-block-ignore-multiline = true

crates/ironrdp-acceptor/src/connection.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ impl Acceptor {
123123
}
124124
}
125125

126+
/// # Panics
127+
///
128+
/// Panics if state is not [AcceptorState::SecurityUpgrade].
126129
pub fn mark_security_upgrade_as_done(&mut self) {
127130
assert!(self.reached_security_upgrade().is_some());
128131
self.step(&[], &mut WriteBuf::new()).expect("transition to next state");
@@ -133,6 +136,9 @@ impl Acceptor {
133136
matches!(self.state, AcceptorState::Credssp { .. })
134137
}
135138

139+
/// # Panics
140+
///
141+
/// Panics if state is not [AcceptorState::Credssp].
136142
pub fn mark_credssp_as_done(&mut self) {
137143
assert!(self.should_perform_credssp());
138144
let res = self.step(&[], &mut WriteBuf::new()).expect("transition to next state");

crates/ironrdp-async/src/connector.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ where
3030
Ok(ShouldUpgrade)
3131
}
3232

33+
/// # Panics
34+
///
35+
/// Panics if connector state is not [ClientConnectorState::EnhancedSecurityUpgrade].
3336
pub fn skip_connect_begin(connector: &mut ClientConnector) -> ShouldUpgrade {
3437
assert!(connector.should_perform_security_upgrade());
3538
ShouldUpgrade

crates/ironrdp-async/src/framed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ where
115115
if self.buf.len() >= length {
116116
return Ok(self.buf.split_to(length));
117117
} else {
118+
#[expect(clippy::missing_panics_doc, reason = "unreachable panic (checked integer underflow)")]
118119
self.buf
119120
.reserve(length.checked_sub(self.buf.len()).expect("length > self.buf.len()"));
120121
}

crates/ironrdp-bench/benches/bench.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![expect(clippy::missing_panics_doc, reason = "panics in benches are allowed")]
2+
13
use core::num::{NonZeroU16, NonZeroUsize};
24

35
use criterion::{criterion_group, criterion_main, Criterion};

crates/ironrdp-blocking/src/connector.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ where
3232
Ok(ShouldUpgrade)
3333
}
3434

35+
/// # Panics
36+
///
37+
/// Panics if connector state is not [ClientConnectorState::EnhancedSecurityUpgrade].
3538
pub fn skip_connect_begin(connector: &mut ClientConnector) -> ShouldUpgrade {
3639
assert!(connector.should_perform_security_upgrade());
3740
ShouldUpgrade

crates/ironrdp-blocking/src/framed.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ where
5151
if self.buf.len() >= length {
5252
return Ok(self.buf.split_to(length));
5353
} else {
54+
#[expect(clippy::missing_panics_doc, reason = "unreachable panic (checked underflow)")]
5455
self.buf
5556
.reserve(length.checked_sub(self.buf.len()).expect("length > self.buf.len()"));
5657
}

crates/ironrdp-cliprdr/src/pdu/file_contents.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,13 @@ impl<'a> FileContentsResponse<'a> {
9494

9595
/// Read data as u64 size value
9696
pub fn data_as_size(&self) -> DecodeResult<u64> {
97-
if self.data.len() != 8 {
98-
return Err(invalid_field_err!(
99-
"requestedFileContentsData",
100-
"Invalid data size for u64 size"
101-
));
102-
}
97+
let chunk = self
98+
.data
99+
.as_ref()
100+
.try_into()
101+
.map_err(|_| invalid_field_err!("requestedFileContentsData", "not enough bytes for u64 size"))?;
103102

104-
Ok(u64::from_le_bytes(
105-
self.data
106-
.as_ref()
107-
.try_into()
108-
.expect("data contains exactly eight u8 elements"),
109-
))
103+
Ok(u64::from_le_bytes(chunk))
110104
}
111105
}
112106

crates/ironrdp-connector/src/connection.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ impl ClientConnector {
176176
matches!(self.state, ClientConnectorState::EnhancedSecurityUpgrade { .. })
177177
}
178178

179+
/// # Panics
180+
///
181+
/// Panics if state is not [ClientConnectorState::EnhancedSecurityUpgrade].
179182
pub fn mark_security_upgrade_as_done(&mut self) {
180183
assert!(self.should_perform_security_upgrade());
181184
self.step(&[], &mut WriteBuf::new()).expect("transition to next state");
@@ -186,6 +189,9 @@ impl ClientConnector {
186189
matches!(self.state, ClientConnectorState::Credssp { .. })
187190
}
188191

192+
/// # Panics
193+
///
194+
/// Panics if state is not [ClientConnectorState::Credssp].
189195
pub fn mark_credssp_as_done(&mut self) {
190196
assert!(self.should_perform_credssp());
191197
let res = self.step(&[], &mut WriteBuf::new()).expect("transition to next state");

crates/ironrdp-dvc/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ pub fn encode_dvc_messages(
7373

7474
while off < total_length {
7575
let first = off == 0;
76+
77+
#[expect(clippy::missing_panics_doc, reason = "unreachable panic (checked underflow)")]
7678
let remaining_length = total_length.checked_sub(off).expect("never overflow");
7779
let size = core::cmp::min(remaining_length, DrdynvcDataPdu::MAX_DATA_SIZE);
7880
let end = off

0 commit comments

Comments
 (0)