Skip to content

Commit ad945a9

Browse files
committed
Fix UI tests, build on MSRV
1 parent b2b602a commit ad945a9

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

time-macros/src/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,17 @@ enum FormatDescriptionVersion {
7575
fn parse_format_description_version<const NO_EQUALS_IS_MOD_NAME: bool>(
7676
iter: &mut PeekableTokenStreamIter,
7777
) -> Result<Option<FormatDescriptionVersion>, Error> {
78-
let version_ident = match iter.peek().ok_or(Error::UnexpectedEndOfInput)? {
78+
let end_of_input_err = || {
79+
if NO_EQUALS_IS_MOD_NAME {
80+
Error::UnexpectedEndOfInput
81+
} else {
82+
Error::ExpectedString {
83+
span_start: None,
84+
span_end: None,
85+
}
86+
}
87+
};
88+
let version_ident = match iter.peek().ok_or_else(end_of_input_err)? {
7989
version @ TokenTree::Ident(ident) if ident.to_string() == "version" => {
8090
let version_ident = version.clone();
8191
iter.next(); // consume `version`

time/src/internal_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ macro_rules! div_floor {
6363
// which is all-ones iff the signs differ, and 0 otherwise. Then by
6464
// adding this mask (which corresponds to the signed value -1), we
6565
// get our correction.
66-
let correction = (this ^ rhs) >> (::core::mem::size_of_val(&this) * 8 - 1);
66+
let correction = (this ^ rhs) >> ($crate::size_of_val(&this) * 8 - 1);
6767
if r != 0 {
6868
d + correction
6969
} else {

time/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,12 @@ pub type Result<T> = core::result::Result<T, Error>;
141141
const fn expect_failed(message: &str) -> ! {
142142
panic!("{}", message)
143143
}
144+
145+
/// Returns the size of the pointed-to value in bytes.
146+
///
147+
/// This is a `const fn` in the standard library starting in Rust 1.85. When MSRV is at least that,
148+
/// this can be removed.
149+
#[allow(unused_qualifications)] // added to prelude after MSRV
150+
const fn size_of_val<T>(_: &T) -> usize {
151+
core::mem::size_of::<T>()
152+
}

time/src/serde/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
5353
)]
5454
/// This puts a module named `mod_name` in the current scope that can be used to format `Date`
5555
/// structs. A submodule (`mod_name::option`) is also generated for `Option<Date>`. Both
56-
/// modules are only visible in the current scope.
56+
/// modules are only visible in the current scope by default. To increase visibility, you can
57+
/// specify `pub`, `pub(crate)`, or similar before the module name:
58+
/// `serde::format_description!(pub mod_name, Date, FORMAT)`.
5759
///
5860
/// The returned `Option` will contain a deserialized value if present and `None` if the field
5961
/// is present but the value is `null` (or the equivalent in other formats). To return `None`

0 commit comments

Comments
 (0)