Skip to content

Commit 72024a8

Browse files
committed
cargo: require 'std' when enabling 'unicode'
The comment in the src/lib.rs diff should explain things for the most part here. The main reason for this commit is to avoid a backcompat hazard after 1.0 is released when and if we want to drop the 'once_cell' dependency.
1 parent 6df1c9d commit 72024a8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ and Unicode support.
143143
* `unicode` - **Enabled** by default. This provides APIs that require sizable
144144
Unicode data compiled into the binary. This includes, but is not limited to,
145145
grapheme/word/sentence segmenters. When this is disabled, basic support such
146-
as UTF-8 decoding is still included.
146+
as UTF-8 decoding is still included. Note that currently, enabling this
147+
feature also requires enabling the `std` feature. It is expected that this
148+
limitation will be lifted at some point.
147149
* `serde` - Enables implementations of serde traits for `BStr`, and also
148150
`BString` when `alloc` is enabled.
149151

src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,30 @@ and Unicode support.
384384
* `unicode` - **Enabled** by default. This provides APIs that require sizable
385385
Unicode data compiled into the binary. This includes, but is not limited to,
386386
grapheme/word/sentence segmenters. When this is disabled, basic support such
387-
as UTF-8 decoding is still included.
387+
as UTF-8 decoding is still included. Note that currently, enabling this
388+
feature also requires enabling the `std` feature. It is expected that this
389+
limitation will be lifted at some point.
388390
* `serde` - Enables implementations of serde traits for `BStr`, and also
389391
`BString` when `alloc` is enabled.
390392
*/
391393

392394
#![cfg_attr(not(any(feature = "std", test)), no_std)]
393395
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
394396

397+
// Why do we do this? Well, in order for us to use once_cell's 'Lazy' type to
398+
// load DFAs, it requires enabling its 'std' feature. Yet, there is really
399+
// nothing about our 'unicode' feature that requires 'std'. We could declare
400+
// that 'unicode = [std, ...]', which would be fine, but once regex-automata
401+
// 0.3 is a thing, I believe we can drop once_cell altogether and thus drop
402+
// the need for 'std' to be enabled when 'unicode' is enabled. But if we make
403+
// 'unicode' also enable 'std', then it would be a breaking change to remove
404+
// 'std' from that list.
405+
//
406+
// So, for right now, we force folks to explicitly say they want 'std' if they
407+
// want 'unicode'. In the future, we should be able to relax this.
408+
#[cfg(all(feature = "unicode", not(feature = "std")))]
409+
compile_error!("enabling 'unicode' requires enabling 'std'");
410+
395411
#[cfg(feature = "alloc")]
396412
extern crate alloc;
397413

0 commit comments

Comments
 (0)