Skip to content

Commit

Permalink
Use let-else directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Apr 18, 2023
1 parent fadac54 commit eb55be2
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 365 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
strategy:
matrix:
rust:
- { version: "1.63.0", name: MSRV }
- { version: "1.65.0", name: MSRV }
- { version: stable, name: stable }
kind:
- name: no_std
Expand Down Expand Up @@ -153,7 +153,7 @@ jobs:
strategy:
matrix:
rust:
- { version: "1.63.0", name: MSRV }
- { version: "1.65.0", name: MSRV }
- { version: stable, name: stable }
os:
- { name: Ubuntu, value: ubuntu-20.04 }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/powerset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
strategy:
matrix:
rust:
- { version: "1.63.0", name: MSRV }
- { version: "1.65.0", name: MSRV }
- { version: stable, name: stable }
kind:
- name: no_std
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# time

[![minimum rustc: 1.63](https://img.shields.io/badge/minimum%20rustc-1.63-yellowgreen?logo=rust&style=flat-square)](https://www.whatrustisit.com)
[![minimum rustc: 1.65](https://img.shields.io/badge/minimum%20rustc-1.65-yellowgreen?logo=rust&style=flat-square)](https://www.whatrustisit.com)
[![version](https://img.shields.io/crates/v/time?color=blue&logo=rust&style=flat-square)](https://crates.io/crates/time)
[![build status](https://img.shields.io/github/actions/workflow/status/time-rs/time/build.yaml?branch=main&style=flat-square)](https://github.com/time-rs/time/actions)
[![codecov](https://codecov.io/gh/time-rs/time/branch/main/graph/badge.svg?token=yt4XSmQNKQ)](https://codecov.io/gh/time-rs/time)
Expand Down
2 changes: 1 addition & 1 deletion time-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "time-core"
version = "0.1.0"
authors = ["Jacob Pratt <open-source@jhpratt.dev>", "Time contributors"]
edition = "2021"
rust-version = "1.63.0"
rust-version = "1.65.0"
repository = "https://github.com/time-rs/time"
keywords = ["date", "time", "calendar", "duration"]
categories = ["date-and-time"]
Expand Down
2 changes: 1 addition & 1 deletion time-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "time-macros"
version = "0.2.8"
authors = ["Jacob Pratt <open-source@jhpratt.dev>", "Time contributors"]
edition = "2021"
rust-version = "1.63.0"
rust-version = "1.65.0"
repository = "https://github.com/time-rs/time"
keywords = ["date", "time", "calendar", "duration"]
categories = ["date-and-time"]
Expand Down
42 changes: 21 additions & 21 deletions time-macros/src/format_description/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,24 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons
) -> Result<Item<'a>, Error> {
let leading_whitespace = tokens.next_if_whitespace();

guard!(let Some(name) = tokens.next_if_not_whitespace() else {
let Some(name) = tokens.next_if_not_whitespace() else {
let span = match leading_whitespace {
Some(Spanned { value: _, span }) => span,
None => opening_bracket.to(opening_bracket),
};
return Err(span.error("expected component name"));
});
};

if *name == b"optional" {
guard!(let Some(whitespace) = tokens.next_if_whitespace() else {
let Some(whitespace) = tokens.next_if_whitespace() else {
return Err(name.span.error("expected whitespace after `optional`"));
});
};

let nested = parse_nested::<_, VERSION>(whitespace.span.end, tokens)?;

guard!(let Some(closing_bracket) = tokens.next_if_closing_bracket() else {
let Some(closing_bracket) = tokens.next_if_closing_bracket() else {
return Err(opening_bracket.error("unclosed bracket"));
});
};

return Ok(Item::Optional {
opening_bracket,
Expand All @@ -157,18 +157,18 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons
}

if *name == b"first" {
guard!(let Some(whitespace) = tokens.next_if_whitespace() else {
let Some(whitespace) = tokens.next_if_whitespace() else {
return Err(name.span.error("expected whitespace after `first`"));
});
};

let mut nested_format_descriptions = Vec::new();
while let Ok(description) = parse_nested::<_, VERSION>(whitespace.span.end, tokens) {
nested_format_descriptions.push(description);
}

guard!(let Some(closing_bracket) = tokens.next_if_closing_bracket() else {
let Some(closing_bracket) = tokens.next_if_closing_bracket() else {
return Err(opening_bracket.error("unclosed bracket"));
});
};

return Ok(Item::First {
opening_bracket,
Expand All @@ -182,21 +182,21 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons

let mut modifiers = Vec::new();
let trailing_whitespace = loop {
guard!(let Some(whitespace) = tokens.next_if_whitespace() else { break None });
let Some(whitespace) = tokens.next_if_whitespace() else { break None };

if let Some(location) = tokens.next_if_opening_bracket() {
return Err(location
.to(location)
.error("modifier must be of the form `key:value`"));
}

guard!(let Some(Spanned { value, span }) = tokens.next_if_not_whitespace() else {
let Some(Spanned { value, span }) = tokens.next_if_not_whitespace() else {
break Some(whitespace);
});
};

guard!(let Some(colon_index) = value.iter().position(|&b| b == b':') else {
let Some(colon_index) = value.iter().position(|&b| b == b':') else {
return Err(span.error("modifier must be of the form `key:value`"));
});
};
let key = &value[..colon_index];
let value = &value[colon_index + 1..];

Expand All @@ -215,9 +215,9 @@ fn parse_component<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, cons
});
};

guard!(let Some(closing_bracket) = tokens.next_if_closing_bracket() else {
let Some(closing_bracket) = tokens.next_if_closing_bracket() else {
return Err(opening_bracket.error("unclosed bracket"));
});
};

Ok(Item::Component {
_opening_bracket: unused(opening_bracket),
Expand All @@ -233,13 +233,13 @@ fn parse_nested<'a, I: Iterator<Item = Result<lexer::Token<'a>, Error>>, const V
last_location: Location,
tokens: &mut lexer::Lexed<I>,
) -> Result<NestedFormatDescription<'a>, Error> {
guard!(let Some(opening_bracket) = tokens.next_if_opening_bracket() else {
let Some(opening_bracket) = tokens.next_if_opening_bracket() else {
return Err(last_location.error("expected opening bracket"));
});
};
let items = parse_inner::<_, true, VERSION>(tokens).collect::<Result<_, _>>()?;
guard!(let Some(closing_bracket) = tokens.next_if_closing_bracket() else {
let Some(closing_bracket) = tokens.next_if_closing_bracket() else {
return Err(opening_bracket.error("unclosed bracket"));
});
};
let trailing_whitespace = tokens.next_if_whitespace();

Ok(NestedFormatDescription {
Expand Down
3 changes: 0 additions & 3 deletions time-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ macro_rules! bug {

#[macro_use]
mod quote;
#[cfg(any(feature = "formatting", feature = "parsing"))]
#[macro_use]
mod shim;

mod date;
mod datetime;
Expand Down
117 changes: 0 additions & 117 deletions time-macros/src/shim.rs

This file was deleted.

2 changes: 1 addition & 1 deletion time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "time"
version = "0.3.20"
authors = ["Jacob Pratt <open-source@jhpratt.dev>", "Time contributors"]
edition = "2021"
rust-version = "1.63.0"
rust-version = "1.65.0"
repository = "https://github.com/time-rs/time"
homepage = "https://time-rs.github.io"
keywords = ["date", "time", "calendar", "duration"]
Expand Down
6 changes: 3 additions & 3 deletions time/src/date_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,10 @@ impl<O: MaybeOffset> DateTime<O> {
/// Equivalent to `.to_offset(UtcOffset::UTC)`, but returning the year, ordinal, and time. This
/// avoids constructing an invalid [`Date`] if the new value is out of range.
pub(crate) const fn to_offset_raw(self, offset: UtcOffset) -> (i32, u16, Time) {
guard!(let Some(from) = maybe_offset_as_offset_opt::<O>(self.offset) else {
let Some(from) = maybe_offset_as_offset_opt::<O>(self.offset) else {
// No adjustment is needed because there is no offset.
return (self.year(), self.ordinal(), self.time);
});
};
let to = offset;

// Fast path for when no conversion is necessary.
Expand Down Expand Up @@ -810,7 +810,7 @@ impl<O: MaybeOffset> DateTime<O> {
}

let (year, ordinal, time) = self.to_offset_raw(UtcOffset::UTC);
guard!(let Ok(date) = Date::from_ordinal_date(year, ordinal) else { return false });
let Ok(date) = Date::from_ordinal_date(year, ordinal) else { return false };

time.hour() == 23
&& time.minute() == 59
Expand Down
Loading

0 comments on commit eb55be2

Please sign in to comment.