From 05769e3f3c9e669f33243fa3a4630b745363d448 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Wed, 10 Jul 2024 10:33:02 -0700 Subject: [PATCH] Fix warnings when building with all-targets, no-default-features (#5212) --- components/casemap/benches/casemap.rs | 5 ++++- components/list/src/lib.rs | 2 +- ffi/capi/src/lib.rs | 2 +- utils/writeable/benches/writeable.rs | 5 +++++ utils/zerotrie/benches/overview.rs | 3 +++ utils/zerovec/benches/zeromap.rs | 1 + 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/components/casemap/benches/casemap.rs b/components/casemap/benches/casemap.rs index b184578afde..cfe97e5bb13 100644 --- a/components/casemap/benches/casemap.rs +++ b/components/casemap/benches/casemap.rs @@ -5,6 +5,7 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use icu_casemap::CaseMapper; use icu_locale_core::langid; +#[cfg(feature = "bench")] use icu_normalizer::DecomposingNormalizer; const TEST_STRING_EN: &str = "One of the key design principles of ICU4X is to make locale data small and portable, allowing it to be pulled from multiple sources depending on the needs of the application. This document explains how that goal can be achieved."; @@ -12,6 +13,7 @@ const TEST_STRING_EN: &str = "One of the key design principles of ICU4X is to ma // First 50 lines of the Iliad, in precomposed Greek // (The Iliad is thousands of years old and public domain) // Sources can be found in https://www.perseus.tufts.edu/hopper/text?doc=Perseus:text:1999.01.0133 or https://www.sacred-texts.com/cla/homer/greek/ili01.htm +#[cfg(feature = "bench")] const ILIAD: &str = include_str!("data/Iliad.txt"); fn overview_bench(c: &mut Criterion) { @@ -48,9 +50,10 @@ fn overview_bench(c: &mut Criterion) { }); }); } -fn greek_uppercasing(c: &mut Criterion) { +fn greek_uppercasing(_c: &mut Criterion) { #[cfg(feature = "bench")] { + let c = _c; let casemapper = CaseMapper::new(); let root = langid!("und"); let el = langid!("el"); diff --git a/components/list/src/lib.rs b/components/list/src/lib.rs index 721cab827d3..b57e302a7d7 100644 --- a/components/list/src/lib.rs +++ b/components/list/src/lib.rs @@ -72,7 +72,7 @@ //! Note: this last example is not fully internationalized. See [icu4x/2192](https://github.com/unicode-org/icu4x/issues/2192) //! for full unit handling. -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(any(test, feature = "std")), no_std)] #![cfg_attr( not(test), deny( diff --git a/ffi/capi/src/lib.rs b/ffi/capi/src/lib.rs index 181417856e6..af942aa45df 100644 --- a/ffi/capi/src/lib.rs +++ b/ffi/capi/src/lib.rs @@ -3,7 +3,7 @@ // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). // https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations -#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(any(test, feature = "std")), no_std)] #![cfg_attr( not(test), deny( diff --git a/utils/writeable/benches/writeable.rs b/utils/writeable/benches/writeable.rs index e2696a67720..d8077020f1c 100644 --- a/utils/writeable/benches/writeable.rs +++ b/utils/writeable/benches/writeable.rs @@ -25,10 +25,12 @@ impl Writeable for WriteableMessage<'_> { writeable::impl_display_with_writeable!(WriteableMessage<'_>); /// A sample type implementing Display +#[cfg(feature = "bench")] struct DisplayMessage<'s> { message: &'s str, } +#[cfg(feature = "bench")] impl fmt::Display for DisplayMessage<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str(self.message) @@ -36,6 +38,7 @@ impl fmt::Display for DisplayMessage<'_> { } /// A sample type that contains multiple fields +#[cfg(feature = "bench")] struct ComplexWriteable<'a> { prefix: &'a str, n0: usize, @@ -44,6 +47,7 @@ struct ComplexWriteable<'a> { suffix: &'a str, } +#[cfg(feature = "bench")] impl Writeable for ComplexWriteable<'_> { fn write_to(&self, sink: &mut W) -> fmt::Result { self.prefix.write_to(sink)?; @@ -63,6 +67,7 @@ impl Writeable for ComplexWriteable<'_> { } } +#[cfg(feature = "bench")] writeable::impl_display_with_writeable!(ComplexWriteable<'_>); const SHORT_STR: &str = "short"; diff --git a/utils/zerotrie/benches/overview.rs b/utils/zerotrie/benches/overview.rs index ca6623818f5..832274378fa 100644 --- a/utils/zerotrie/benches/overview.rs +++ b/utils/zerotrie/benches/overview.rs @@ -4,11 +4,14 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use litemap::LiteMap; +#[cfg(feature = "bench")] use std::collections::HashMap; use zerotrie::ZeroTrieExtendedCapacity; use zerotrie::ZeroTriePerfectHash; use zerotrie::ZeroTrieSimpleAscii; +#[cfg(feature = "bench")] use zerovec::ZeroHashMap; +#[cfg(feature = "bench")] use zerovec::ZeroMap; mod testdata { diff --git a/utils/zerovec/benches/zeromap.rs b/utils/zerovec/benches/zeromap.rs index ac93efdb35f..9ca42f0f353 100644 --- a/utils/zerovec/benches/zeromap.rs +++ b/utils/zerovec/benches/zeromap.rs @@ -311,6 +311,7 @@ fn bench_deserialize_zerohashmap(c: &mut Criterion) { }); } +#[cfg(feature = "bench")] fn bench_deserialize_large_zerohashmap(c: &mut Criterion) { let buf = large_zerohashmap_postcard_bytes(); c.bench_function("zerohashmap/deserialize/large", |b| {