Skip to content

Commit 7f46c8b

Browse files
committed
refactor: depopulate unreachable!() messages
This _should_ shrink the binary size by reducing panic info.
1 parent 45573e6 commit 7f46c8b

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/ambiguous/domain_or_tagged_ref.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,13 @@ impl<'src> DomainOrRefSpan<'src> {
169169
}
170170
}
171171
}
172-
_ => unreachable!(
173-
"PortOrTagSpan::new() only terminates successfully at '/', '@', or EOF"
174-
),
172+
_ => unreachable!(), //PortOrTagSpan::new() only terminates successfully at '/', '@', or EOF
175173
}
176174
}
177175
}
178176

179177
#[cfg(test)]
178+
#[allow(clippy::indexing_slicing)]
180179
mod tests {
181180
use super::*;
182181
use crate::span::Lengthy;

src/ambiguous/host_or_path.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'src> HostOrPathSpan<'src> {
319319
use Kind::*;
320320
let decider = self.2;
321321
match (self.kind(), target_kind) {
322-
(_, Any) => unreachable!("calls to .narrow() must narrow, not broaden"),
322+
(_, Any) => unreachable!(), // calls to .narrow() must narrow, not broaden
323323
(Path, HostOrPath) | (Host, HostOrPath) => Ok(self),
324324
(Any, _) | (HostOrPath, Path) | (HostOrPath, Host) => {
325325
Ok(Self(self.0, target_kind, decider))
@@ -336,7 +336,8 @@ impl<'src> HostOrPathSpan<'src> {
336336
#[allow(
337337
clippy::cast_possible_truncation,
338338
clippy::arithmetic_side_effects,
339-
clippy::unwrap_used
339+
clippy::unwrap_used,
340+
clippy::indexing_slicing
340341
)]
341342
mod tests {
342343
use super::*;

src/digest/algorithm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ impl<'src> Algorithm<'src> {
136136
Some(b'a'..=b'z') => {}
137137
Some(b'0'..=b'9') => return Compliance::Oci,
138138
Some(b'A'..=b'Z') => return Compliance::Distribution,
139-
_ => unreachable!("by construction, an Algorithm may contain only [a-zA-Z0-9]"),
139+
_ => unreachable!(), // by construction, an Algorithm may contain only [a-zA-Z0-9]
140140
};
141141
for c in bytes {
142142
match c {
143143
b'a'..=b'z' | b'0'..=b'9' => {}
144144
b'A'..=b'Z' => return Compliance::Distribution,
145-
_ => unreachable!("by construction, an Algorithm may contain only [a-zA-Z0-9]"),
145+
_ => unreachable!(), // by construction, an Algorithm may contain only [a-zA-Z0-9]
146146
}
147147
}
148148
Compliance::Universal

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#![warn(missing_docs)]
77
#![warn(clippy::arithmetic_side_effects)]
88
#![warn(clippy::index_refutable_slice)]
9-
// #![warn(clippy::indexing_slicing)]
109
#![warn(clippy::doc_markdown)]
1110
#![warn(clippy::trivially_copy_pass_by_ref)] // TODO: consider inlining
1211
#![deny(clippy::cast_possible_truncation)]
@@ -29,7 +28,9 @@
2928
#![warn(clippy::try_err)]
3029
#![warn(clippy::todo)]
3130
#![warn(clippy::redundant_clone)]
32-
// #![warn(clippy::or_fun_call)] warns about ok_or(Error::at(...))
31+
// #![warn(clippy::unreachable)] // used too often to enable
32+
// #![warn(clippy::indexing_slicing)] // used too often to enable
33+
// #![warn(clippy::or_fun_call)] // warns about ok_or(Error::at(...))
3334
pub(crate) mod ambiguous;
3435
pub mod digest;
3536
pub mod err;
@@ -98,9 +99,8 @@ impl<'src> RefSpan<'src> {
9899
}),
99100
Some(b'@') | Some(b':') | None => match prefix {
100101
DomainOrRefSpan::TaggedRef((name, _)) => Ok(name),
101-
DomainOrRefSpan::Domain(_) => {
102-
unreachable!("if the left segment peeked an '@', it would parse as a TaggedRef")
103-
}
102+
DomainOrRefSpan::Domain(_) => unreachable!(),
103+
// ^ if the left segment peeked an '@', it would parse as a TaggedRef
104104
},
105105
Some(_) => Error::at(index, err::Kind::PathInvalidChar).into(),
106106
}?; // TODO: check correctness

src/name/domain/host.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ impl<'src> TryFrom<HostOrPathSpan<'src>> for HostSpan<'src> {
8282
let kind = match ambiguous.kind() {
8383
HostKind::Host | HostKind::HostOrPath => Ok(Kind::Name),
8484
HostKind::IpV6 => Ok(Kind::Ipv6),
85-
HostKind::Path => ambiguous.narrow(HostKind::Host).map(|_| unreachable!()),
86-
HostKind::Any => unreachable!("HostKind::Any should have been disambiguated"),
85+
HostKind::Path => ambiguous.narrow(HostKind::Host).map(|_| unreachable!()), // just to unwrap the error
86+
HostKind::Any => unreachable!(), // HostKind::Any should have been disambiguated
8787
}?;
8888
Ok(Self(Length::from_nonzero(ambiguous.short_len()), kind))
8989
}

src/name/domain/ipv6.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'src> Ipv6Span<'src> {
175175
}
176176
}
177177
7 => Ok(Self(ShortLength::from_nonzero(index))),
178-
_ => unreachable!("group_count <= 7 enforced by checks on state.increment_group()"),
178+
_ => unreachable!(), // group_count <= 7 enforced by checks on state.increment_group()
179179
}
180180
}
181181
}

0 commit comments

Comments
 (0)