Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Scope expect exemptions to individual expressions

Manav Rathi5beed211c016
diff --git a/rust/bindings/uniffi/ensu/src/assets.rs b/rust/bindings/uniffi/ensu/src/assets.rs
index 0f97a54c65..2aebbec706 100644
--- a/rust/bindings/uniffi/ensu/src/assets.rs
+++ b/rust/bindings/uniffi/ensu/src/assets.rs
@@ -64,11 +64,11 @@ impl From<download::Error> for AssetDownloadError {
}
#[uniffi::export]
-#[expect(
- clippy::expect_used,
- reason = "Unknown model IDs fall back to the built-in catalog"
-)]
pub fn llm_asset(model_id: String) -> Arc<Asset> {
+ #[expect(
+ clippy::expect_used,
+ reason = "Unknown model IDs fall back to the built-in catalog"
+ )]
Asset::new(ente_ensu::model::mobile_llm_asset(&model_id).expect("valid mobile model catalog"))
}
diff --git a/rust/crates/core/src/crypto/hpke.rs b/rust/crates/core/src/crypto/hpke.rs
index d86e8cf04a..6dbf9e073d 100644
--- a/rust/crates/core/src/crypto/hpke.rs
+++ b/rust/crates/core/src/crypto/hpke.rs
@@ -29,11 +29,11 @@ impl PublicKey {
&self.0
}
- #[expect(
- clippy::expect_used,
- reason = "PublicKey construction validates these bytes"
- )]
fn hpke_key(&self) -> <Kem as HpkeKem>::PublicKey {
+ #[expect(
+ clippy::expect_used,
+ reason = "PublicKey construction validates these bytes"
+ )]
<Kem as HpkeKem>::PublicKey::from_bytes(&self.0)
.expect("PublicKey is validated when constructed")
}
@@ -73,11 +73,11 @@ impl SecretKey {
&self.0
}
- #[expect(
- clippy::expect_used,
- reason = "X-Wing accepts every 32-byte private key"
- )]
fn hpke_key(&self) -> <Kem as HpkeKem>::PrivateKey {
+ #[expect(
+ clippy::expect_used,
+ reason = "X-Wing accepts every 32-byte private key"
+ )]
<Kem as HpkeKem>::PrivateKey::from_bytes(&self.0)
.expect("X-Wing accepts every 32-byte private key")
}
diff --git a/rust/crates/ensu/src/config.rs b/rust/crates/ensu/src/config.rs
index e1928bf157..3e1903ab89 100644
--- a/rust/crates/ensu/src/config.rs
+++ b/rust/crates/ensu/src/config.rs
@@ -255,11 +255,11 @@ pub fn resolve_effective_model(
.unwrap_or(policy.default_model)
}
-#[expect(
- clippy::expect_used,
- reason = "Built-in defaults refer to IDs defined in the same catalog"
-)]
fn catalog_preset(catalog: &[ModelPreset], id: &str) -> ModelPreset {
+ #[expect(
+ clippy::expect_used,
+ reason = "Built-in defaults refer to IDs defined in the same catalog"
+ )]
catalog
.iter()
.find(|preset| preset.id == id)
diff --git a/rust/crates/ensu/src/config/knowledge.rs b/rust/crates/ensu/src/config/knowledge.rs
index d4956cba95..38a0757638 100644
--- a/rust/crates/ensu/src/config/knowledge.rs
+++ b/rust/crates/ensu/src/config/knowledge.rs
@@ -96,14 +96,18 @@ pub(crate) fn knowledge_index_contract() -> KnowledgeIndexContract {
}
}
-#[expect(
- clippy::expect_used,
- reason = "The fixed prompt contains both placeholders"
-)]
pub(crate) fn format_knowledge_document_prompt(title: &str, text: &str) -> String {
+ #[expect(
+ clippy::expect_used,
+ reason = "The fixed prompt contains the title placeholder"
+ )]
let (prefix, remainder) = DOCUMENT_PROMPT
.split_once("{title}")
.expect("knowledge document prompt contains a title placeholder");
+ #[expect(
+ clippy::expect_used,
+ reason = "The fixed prompt contains the text placeholder after the title"
+ )]
let (middle, suffix) = remainder
.split_once("{text}")
.expect("knowledge document prompt contains a text placeholder");
diff --git a/rust/crates/ensu/src/llm/generate.rs b/rust/crates/ensu/src/llm/generate.rs
index a9d330e2fa..2d0b44a944 100644
--- a/rust/crates/ensu/src/llm/generate.rs
+++ b/rust/crates/ensu/src/llm/generate.rs
@@ -93,12 +93,12 @@ pub struct ChatRequest {
pub grammar: Option<String>,
}
-#[expect(
- clippy::expect_used,
- reason = "llama.cpp reports insufficient buffer capacity as a negative byte count"
-)]
fn token_piece_bytes(model: &LlamaModel, token: LlamaToken) -> Result<Vec<u8>, TokenToStringError> {
match model.token_to_piece_bytes(token, 8, true, None) {
+ #[expect(
+ clippy::expect_used,
+ reason = "llama.cpp reports insufficient buffer capacity as a negative byte count"
+ )]
Err(TokenToStringError::InsufficientBufferSpace(required)) => model.token_to_piece_bytes(
token,
(-required)
diff --git a/rust/crates/ensu/src/model/mod.rs b/rust/crates/ensu/src/model/mod.rs
index 4a82db3332..5b2cb0c030 100644
--- a/rust/crates/ensu/src/model/mod.rs
+++ b/rust/crates/ensu/src/model/mod.rs
@@ -69,12 +69,12 @@ pub fn desktop_llm_asset(model_id: &str) -> Result<Asset, InvalidPreset> {
llm_asset(&preset)
}
-#[expect(
- clippy::expect_used,
- reason = "The built-in model preset has a valid asset key and checksum"
-)]
pub fn transcription_model_asset() -> Asset {
let preset = config::defaults().transcription_model;
+ #[expect(
+ clippy::expect_used,
+ reason = "The built-in model preset has a valid asset key and checksum"
+ )]
Asset::tar_gz(
model_key(&preset.id),
preset.url,
@@ -84,12 +84,12 @@ pub fn transcription_model_asset() -> Asset {
.expect("transcription asset config")
}
-#[expect(
- clippy::expect_used,
- reason = "The built-in model preset has a valid asset key and checksum"
-)]
pub fn voice_activity_model_asset() -> Asset {
let preset = config::defaults().voice_activity_model;
+ #[expect(
+ clippy::expect_used,
+ reason = "The built-in model preset has a valid asset key and checksum"
+ )]
Asset::files(
model_key(&preset.id),
vec![AssetFile {
@@ -102,12 +102,12 @@ pub fn voice_activity_model_asset() -> Asset {
.expect("voice activity asset config")
}
-#[expect(
- clippy::expect_used,
- reason = "The built-in model preset has a valid asset key and checksum"
-)]
pub fn knowledge_embedding_model_asset() -> Asset {
let embedding = config::knowledge_embedding_config();
+ #[expect(
+ clippy::expect_used,
+ reason = "The built-in model preset has a valid asset key and checksum"
+ )]
Asset::files(
model_key(&embedding.target_id),
vec![AssetFile {
diff --git a/rust/crates/image/src/color_management.rs b/rust/crates/image/src/color_management.rs
index 7c07870db4..ad6fd85e62 100644
--- a/rust/crates/image/src/color_management.rs
+++ b/rust/crates/image/src/color_management.rs
@@ -110,10 +110,6 @@ fn apply_profile_to_image(
}
}
-#[expect(
- clippy::expect_used,
- reason = "Color transforms preserve the source buffer length and dimensions"
-)]
fn transform_buffer<P>(
mut buffer: ImageBuffer<P, Vec<P::Subpixel>>,
source_profile: &ColorProfile,
@@ -127,6 +123,10 @@ where
{
let (width, height) = buffer.dimensions();
match P::Subpixel::transform_to_srgb(buffer.as_mut(), source_profile, encoded_profile, layout) {
+ #[expect(
+ clippy::expect_used,
+ reason = "Color transforms preserve the source buffer length and dimensions"
+ )]
Ok(Some(transformed)) => Ok(into_dynamic(
ImageBuffer::from_raw(width, height, transformed)
.expect("transformed buffer length should match source dimensions"),
diff --git a/rust/crates/location/src/city.rs b/rust/crates/location/src/city.rs
index acfd4f6d3f..a1310793be 100644
--- a/rust/crates/location/src/city.rs
+++ b/rust/crates/location/src/city.rs
@@ -861,25 +861,25 @@ fn string_offset(bytes: &[u8], offset: usize, length: usize) -> crate::Result<us
}
}
-#[expect(
- clippy::expect_used,
- reason = "Index construction validates the string table as UTF-8"
-)]
fn table_entry_u24(bytes: &[u8], offsets: usize, blob: usize, index: usize) -> &str {
let mut reader = ByteReader::at(bytes, offsets + index * NAME_OFFSET_LEN);
let start = reader.u24() as usize;
let end = reader.u24() as usize;
+ #[expect(
+ clippy::expect_used,
+ reason = "Index construction validates the string table as UTF-8"
+ )]
std::str::from_utf8(&bytes[blob + start..blob + end]).expect("validated UTF-8")
}
-#[expect(
- clippy::expect_used,
- reason = "Index construction validates the string table as UTF-8"
-)]
fn table_entry_u32(bytes: &[u8], offsets: usize, blob: usize, index: usize) -> &str {
let mut reader = ByteReader::at(bytes, offsets + index * 4);
let start = reader.u32() as usize;
let end = reader.u32() as usize;
+ #[expect(
+ clippy::expect_used,
+ reason = "Index construction validates the string table as UTF-8"
+ )]
std::str::from_utf8(&bytes[blob + start..blob + end]).expect("validated UTF-8")
}
diff --git a/rust/crates/location/src/dispute.rs b/rust/crates/location/src/dispute.rs
index e41941e055..aefe6c7e6b 100644
--- a/rust/crates/location/src/dispute.rs
+++ b/rust/crates/location/src/dispute.rs
@@ -93,10 +93,6 @@ impl DisputeIndex {
})
}
- #[expect(
- clippy::expect_used,
- reason = "Index construction checks every geometry code against the territory catalog"
- )]
pub(crate) fn lookup_prepared(
&self,
location: PreparedCell,
@@ -107,6 +103,10 @@ impl DisputeIndex {
.into_iter()
.map(|code| DisputeMatch {
index: self,
+ #[expect(
+ clippy::expect_used,
+ reason = "Index construction checks every geometry code against the territory catalog"
+ )]
territory: territory_index_for_code(&self.bytes, self.layout, code)
.expect("geometry was validated against the catalog"),
})
@@ -193,12 +193,12 @@ impl<'a> DisputeMatch<'a> {
self.index.layout.territories + self.territory * TERRITORY_LEN
}
- #[expect(
- clippy::expect_used,
- reason = "Index construction validates the string table as UTF-8"
- )]
fn string(self, start: u16, length: usize) -> &'a str {
let start = self.index.layout.strings + usize::from(start);
+ #[expect(
+ clippy::expect_used,
+ reason = "Index construction validates the string table as UTF-8"
+ )]
str::from_utf8(&self.index.bytes[start..start + length]).expect("validated UTF-8")
}
}
diff --git a/rust/crates/location/src/lib.rs b/rust/crates/location/src/lib.rs
index eda22c90ba..ebd7f1d91f 100644
--- a/rust/crates/location/src/lib.rs
+++ b/rust/crates/location/src/lib.rs
@@ -60,11 +60,11 @@ impl CountryCode {
self.0
}
- #[expect(
- clippy::expect_used,
- reason = "CountryCode construction restricts bytes to ASCII"
- )]
pub fn as_str(&self) -> &str {
+ #[expect(
+ clippy::expect_used,
+ reason = "CountryCode construction restricts bytes to ASCII"
+ )]
std::str::from_utf8(&self.0).expect("country code is ASCII")
}
diff --git a/rust/crates/location/src/urban.rs b/rust/crates/location/src/urban.rs
index b22ad30eb0..f983d80247 100644
--- a/rust/crates/location/src/urban.rs
+++ b/rust/crates/location/src/urban.rs
@@ -218,27 +218,31 @@ impl UrbanCenterIndex {
}
}
- #[expect(
- clippy::expect_used,
- reason = "Index construction validates terminated UTF-8 names"
- )]
fn name(&self, offset: usize) -> &str {
+ #[expect(
+ clippy::expect_used,
+ reason = "Index construction validates name terminators"
+ )]
let end = self.bytes[offset..self.layout.geometry]
.iter()
.position(|&byte| byte == 0)
.map(|length| offset + length)
.expect("validated name terminator");
+ #[expect(
+ clippy::expect_used,
+ reason = "Index construction validates names as UTF-8"
+ )]
std::str::from_utf8(&self.bytes[offset..end]).expect("validated name")
}
- #[expect(
- clippy::expect_used,
- reason = "Index construction validates the country string table as UTF-8"
- )]
fn country(&self, index: usize) -> &str {
let mut reader = ByteReader::at(&self.bytes, self.layout.country_offsets + index * 4);
let start = reader.u32() as usize;
let end = reader.u32() as usize;
+ #[expect(
+ clippy::expect_used,
+ reason = "Index construction validates the country string table as UTF-8"
+ )]
std::str::from_utf8(&self.bytes[self.layout.countries + start..self.layout.countries + end])
.expect("validated country")
}
diff --git a/rust/crates/ml/src/assets.rs b/rust/crates/ml/src/assets.rs
index 41fecc49e7..6672d41838 100644
--- a/rust/crates/ml/src/assets.rs
+++ b/rust/crates/ml/src/assets.rs
@@ -27,12 +27,12 @@ pub struct ClipTextPaths {
pub vocab: PathBuf,
}
-#[expect(
- clippy::expect_used,
- reason = "The built-in model catalog has valid asset keys and checksums"
-)]
fn model_asset(model: Model) -> Asset {
let spec = model_asset_spec(model);
+ #[expect(
+ clippy::expect_used,
+ reason = "The built-in model catalog has valid asset keys and checksums"
+ )]
Asset::files(
model_key(spec.key),
spec.files
@@ -67,17 +67,21 @@ pub fn indexing_model_paths(
model_paths
}
-#[expect(
- clippy::expect_used,
- reason = "The filenames and asset come from the same CLIP catalog entry"
-)]
pub fn clip_text_paths(store: &AssetStore) -> ClipTextPaths {
let asset = clip_text_asset();
let files = model_asset_spec(Model::ClipText).files;
ClipTextPaths {
+ #[expect(
+ clippy::expect_used,
+ reason = "The filename and asset come from the same CLIP catalog entry"
+ )]
model: store
.file_path(&asset, files[0].name)
.expect("CLIP text model file"),
+ #[expect(
+ clippy::expect_used,
+ reason = "The filename and asset come from the same CLIP catalog entry"
+ )]
vocab: store
.file_path(&asset, files[1].name)
.expect("CLIP text vocabulary file"),
@@ -220,12 +224,12 @@ struct ModelAssetFile {
sha256: &'static str,
}
-#[expect(
- clippy::expect_used,
- reason = "The filename and asset come from the same model catalog entry"
-)]
fn model_path(store: &AssetStore, model: Model) -> String {
let asset = model_asset(model);
+ #[expect(
+ clippy::expect_used,
+ reason = "The filename and asset come from the same model catalog entry"
+ )]
store
.file_path(&asset, model_asset_spec(model).files[0].name)
.expect("model file")
diff --git a/rust/crates/ml/src/face/align.rs b/rust/crates/ml/src/face/align.rs
index 05f91ef331..8316b2140e 100644
--- a/rust/crates/ml/src/face/align.rs
+++ b/rust/crates/ml/src/face/align.rs
@@ -72,10 +72,6 @@ pub(crate) fn run_face_alignment(
result
}
-#[expect(
- clippy::expect_used,
- reason = "RGB dimensions and exact buffer length are checked before conversion"
-)]
fn take_rgb_image(decoded: &mut DecodedImage) -> MlResult<RgbImage> {
let expected_len = (decoded.dimensions.width as usize)
.checked_mul(decoded.dimensions.height as usize)
@@ -89,6 +85,10 @@ fn take_rgb_image(decoded: &mut DecodedImage) -> MlResult<RgbImage> {
}
let rgb = std::mem::take(&mut decoded.rgb);
+ #[expect(
+ clippy::expect_used,
+ reason = "RGB dimensions and exact buffer length are checked before conversion"
+ )]
Ok(ImageBuffer::<Rgb<u8>, _>::from_raw(
decoded.dimensions.width,
decoded.dimensions.height,
diff --git a/rust/crates/ml/src/ocr/assets.rs b/rust/crates/ml/src/ocr/assets.rs
index e8f86be5d1..0466e7f6cd 100644
--- a/rust/crates/ml/src/ocr/assets.rs
+++ b/rust/crates/ml/src/ocr/assets.rs
@@ -51,11 +51,11 @@ impl OcrModelFile {
format!("{MODEL_BASE_URL}/{}", self.name)
}
- #[expect(
- clippy::expect_used,
- reason = "The built-in OCR catalog has valid asset keys and checksums"
- )]
fn asset(&self) -> Asset {
+ #[expect(
+ clippy::expect_used,
+ reason = "The built-in OCR catalog has valid asset keys and checksums"
+ )]
Asset::file(
vec![MODELS.to_string(), self.key.to_string()],
AssetFile {
@@ -68,11 +68,11 @@ impl OcrModelFile {
.expect("valid OCR model catalog")
}
- #[expect(
- clippy::expect_used,
- reason = "The filename and asset come from the same OCR catalog entry"
- )]
fn path(&self, store: &AssetStore) -> String {
+ #[expect(
+ clippy::expect_used,
+ reason = "The filename and asset come from the same OCR catalog entry"
+ )]
store
.file_path(&self.asset(), self.name)
.expect("OCR model file")
diff --git a/rust/crates/ml/src/onnx/providers.rs b/rust/crates/ml/src/onnx/providers.rs
index 86b4559c7e..0f85ef0cbf 100644
--- a/rust/crates/ml/src/onnx/providers.rs
+++ b/rust/crates/ml/src/onnx/providers.rs
@@ -339,8 +339,8 @@ fn webgpu_attempt_providers() -> Vec<ExecutionProviderDispatch> {
}
#[cfg(target_os = "android")]
-#[expect(clippy::expect_used, reason = "The fixed thread count is nonzero")]
fn xnnpack_provider() -> ExecutionProviderDispatch {
+ #[expect(clippy::expect_used, reason = "The fixed thread count is nonzero")]
XNNPACK::default()
.with_intra_op_num_threads(NonZeroUsize::new(4).expect("four is non-zero"))
.build()
diff --git a/rust/crates/photos/src/db.rs b/rust/crates/photos/src/db.rs
index f3e26d6e8d..54450b8175 100644
--- a/rust/crates/photos/src/db.rs
+++ b/rust/crates/photos/src/db.rs
@@ -301,12 +301,12 @@ impl Pool {
}
}
- #[expect(
- clippy::expect_used,
- reason = "acquire_reader returns a guard owning a connection"
- )]
fn read<T>(&self, query: impl FnOnce(&mut Connection) -> Result<T>) -> Result<T> {
let mut reader = self.acquire_reader();
+ #[expect(
+ clippy::expect_used,
+ reason = "acquire_reader returns a guard owning a connection"
+ )]
query(
reader
.connection