Skip to content

Commit 6f00e7e

Browse files
committed
id: rustfmt meta_client.rs and drop expect() in tags search parser (#2151)
Main-red breakage inherited by every PR: cargo-fmt/rustfmt/treefmt failed on meta_client.rs capped_response_error formatting, and clippy-lint hard-errored on clippy::expect_used at the two char-boundary expects in parse_search_query. The expects become let-else breaks (the loops guard on i < input.len(), so next() is always Some; no behaviour change — 68 tags tests pass) and meta_client.rs is reformatted. No other files touched.
1 parent 5a34fa7 commit 6f00e7e

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎pkgs/id/src/meta_client.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ pub fn expect_ok(resp: MetaResponse) -> Result<MetaResponse> {
5353
/// limit instead. Any other read failure passes through unchanged.
5454
pub fn capped_response_error(err: ReadToEndError) -> anyhow::Error {
5555
match err {
56-
ReadToEndError::TooLong => anyhow::anyhow!(
57-
"response too large: exceeds the {MAX_RESPONSE_BYTES}-byte limit"
58-
),
56+
ReadToEndError::TooLong => {
57+
anyhow::anyhow!("response too large: exceeds the {MAX_RESPONSE_BYTES}-byte limit")
58+
}
5959
other => other.into(),
6060
}
6161
}

‎pkgs/id/src/tags.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,14 +1474,18 @@ pub fn parse_search_query(input: &str) -> Vec<SearchTerm> {
14741474

14751475
// Byte index into `input`. It only ever advances by whole chars, so it
14761476
// always rests on a char boundary and slicing stays valid even when a
1477-
// separator is a multi-byte whitespace char such as NBSP (U+00A0).
1477+
// separator is a multi-byte whitespace char such as NBSP (U+00A0). The
1478+
// loops below guard on `i < input.len()`, so `chars().next()` is always
1479+
// `Some` there; the let-else form keeps that invariant panic-free.
14781480
let mut i = 0;
14791481

14801482
while i < input.len() {
14811483
// Skip whitespace: any `char::is_whitespace` char separates terms,
14821484
// not only the ASCII space.
14831485
while i < input.len() {
1484-
let ch = input[i..].chars().next().expect("i is a char boundary");
1486+
let Some(ch) = input[i..].chars().next() else {
1487+
break;
1488+
};
14851489
if !ch.is_whitespace() {
14861490
break;
14871491
}
@@ -1496,7 +1500,9 @@ pub fn parse_search_query(input: &str) -> Vec<SearchTerm> {
14961500
let start = i;
14971501
let mut in_quotes = false;
14981502
while i < input.len() {
1499-
let ch = input[i..].chars().next().expect("i is a char boundary");
1503+
let Some(ch) = input[i..].chars().next() else {
1504+
break;
1505+
};
15001506
if ch == '"' {
15011507
in_quotes = !in_quotes;
15021508
i += 1;

0 commit comments

Comments
 (0)