Skip to content

Commit

Permalink
msrv: bump to Rust 1.65
Browse files Browse the repository at this point in the history
This MSRV bump is mostly motivated by "good sense," and in particular,
Rust 1.65 means we can use 'let ... else'. We don't actually start
peppering the code with 'let ... else' just yet, but we fix a few
outstanding small issues and update our Rust version everywhere.

Also, Rust 1.65 is about a year old at time of writing. Let's keep the
trains moving.
  • Loading branch information
BurntSushi committed Oct 9, 2023
1 parent 2f824f8 commit daec17a
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.60.0
toolchain: 1.65.0
# The memchr 2.6 release purportedly bumped its MSRV to Rust 1.60, but it
# turned out that on aarch64, it was using something that wasn't stabilized
# until Rust 1.61[1]. (This was an oversight on my part. I had previously
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["text-processing"]
autotests = false
exclude = ["/scripts/*", "/.github/*"]
edition = "2021"
rust-version = "1.60.0"
rust-version = "1.65"

[workspace]
members = [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ goes into more depth.

### Minimum Rust version policy

This crate's minimum supported `rustc` version is `1.60.0`.
This crate's minimum supported `rustc` version is `1.65.0`.

The policy is that the minimum Rust version required to use this crate can be
increased in minor version updates. For example, if regex 1.0 requires Rust
Expand Down
1 change: 1 addition & 0 deletions regex-automata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0"
categories = ["text-processing"]
edition = "2021"
autoexamples = false
rust-version = "1.65"

[lib]
bench = false
Expand Down
6 changes: 1 addition & 5 deletions regex-automata/src/util/lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,7 @@ mod lazy {
// SAFETY: state is DONE if and only if data has been fully
// initialized. At which point, it is safe to drop.
unsafe {
// MSRV(1.60): Use assume_init_drop. The below is how
// assume_init_drop is implemented.
core::ptr::drop_in_place(
(*self.data.as_ptr()).as_mut_ptr(),
)
self.data.get_mut().assume_init_drop();
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions regex-automata/src/util/look.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1651,8 +1651,7 @@ mod is_word_char {
fn is_word_character(c: char) -> bool {
use crate::util::{unicode_data::perl_word::PERL_WORD, utf8};

// MSRV(1.59): Use 'u8::try_from(c)' instead.
if u8::try_from(u32::from(c)).map_or(false, utf8::is_word_byte) {
if u8::try_from(c).map_or(false, utf8::is_word_byte) {
return true;
}
PERL_WORD
Expand Down
21 changes: 16 additions & 5 deletions regex-automata/src/util/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,22 @@ mod inner {
/// Create a new pool. The given closure is used to create values in
/// the pool when necessary.
pub(super) fn new(create: F) -> Pool<T, F> {
// MSRV(1.63): Mark this function as 'const'. I've arranged the
// code such that it should "just work." Then mark the public
// 'Pool::new' method as 'const' too. (The alloc-only Pool::new
// is already 'const', so that should "just work" too.) The only
// thing we're waiting for is Mutex::new to be const.
// FIXME: Now that we require 1.65+, Mutex::new is available as
// const... So we can almost mark this function as const. But of
// course, we're creating a Vec of stacks below (we didn't when I
// originally wrote this code). It seems like the best way to work
// around this would be to use a `[Stack; MAX_POOL_STACKS]` instead
// of a `Vec<Stack>`. I refrained from making this change at time
// of writing (2023/10/08) because I was making a lot of other
// changes at the same time and wanted to do this more carefully.
// Namely, because of the cache line optimization, that `[Stack;
// MAX_POOL_STACKS]` would be quite big. It's unclear how bad (if
// at all) that would be.
//
// Another choice would be to lazily allocate the stacks, but...
// I'm not so sure about that. Seems like a fair bit of complexity?
//
// Maybe there's a simple solution I'm missing.
let mut stacks = Vec::with_capacity(MAX_POOL_STACKS);
for _ in 0..stacks.capacity() {
stacks.push(CacheLine(Mutex::new(vec![])));
Expand Down
1 change: 1 addition & 0 deletions regex-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ license = "MIT OR Apache-2.0"
categories = ["text-processing"]
autotests = false
edition = "2021"
rust-version = "1.65"

[[bin]]
name = "regex-cli"
Expand Down
2 changes: 1 addition & 1 deletion regex-lite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A lightweight regex engine that optimizes for binary size and compilation time.
"""
workspace = ".."
edition = "2021"
rust-version = "1.60.0"
rust-version = "1.65"
autotests = false

# Features are documented in the "Crate features" section of the crate docs:
Expand Down
2 changes: 1 addition & 1 deletion regex-lite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ year: 2014, month: 10, day: 14

### Minimum Rust version policy

This crate's minimum supported `rustc` version is `1.60.0`.
This crate's minimum supported `rustc` version is `1.65.0`.

The policy is that the minimum Rust version required to use this crate can be
increased in semver compatible updates.
Expand Down
2 changes: 1 addition & 1 deletion regex-syntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ documentation = "https://docs.rs/regex-syntax"
description = "A regular expression parser."
workspace = ".."
edition = "2021"
rust-version = "1.60.0"
rust-version = "1.65"

# Features are documented in the "Crate features" section of the crate docs:
# https://docs.rs/regex-syntax/*/#crate-features
Expand Down
21 changes: 8 additions & 13 deletions regex-syntax/src/hir/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2235,24 +2235,19 @@ impl PreferenceTrie {
/// after them and because any removed literals are guaranteed to never
/// match.
fn minimize(literals: &mut Vec<Literal>, keep_exact: bool) {
use core::cell::RefCell;

// MSRV(1.61): Use retain_mut here to avoid interior mutability.
let trie = RefCell::new(PreferenceTrie {
let mut trie = PreferenceTrie {
states: vec![],
matches: vec![],
next_literal_index: 1,
});
};
let mut make_inexact = vec![];
literals.retain(|lit| {
match trie.borrow_mut().insert(lit.as_bytes()) {
Ok(_) => true,
Err(i) => {
if !keep_exact {
make_inexact.push(i.checked_sub(1).unwrap());
}
false
literals.retain_mut(|lit| match trie.insert(lit.as_bytes()) {
Ok(_) => true,
Err(i) => {
if !keep_exact {
make_inexact.push(i.checked_sub(1).unwrap());
}
false
}
});
for i in make_inexact {
Expand Down
12 changes: 0 additions & 12 deletions regex-syntax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,6 @@ The following features are available:
#![forbid(unsafe_code)]
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
#![warn(missing_debug_implementations)]
// MSRV(1.62): Allow unused warnings. Needed for the 'allow' below,
// since the warning is no longer triggered in newer Rust releases.
// Once the 'allow(mutable_borrow_reservation_conflict)' can be
// removed, we can remove the 'allow(renamed_and_removed_lints)' too.
#![allow(renamed_and_removed_lints)]
// MSRV(1.62): This gets triggered on Rust <1.62, and since our MSRV
// is Rust 1.60 at the time of writing, a warning is displayed. But
// the lang team decided the code pattern flagged by this warning is
// OK, so the warning is innocuous. We can remove this explicit allow
// once we get to a Rust release where the warning is no longer
// triggered. I believe that's Rust 1.62.
#![allow(mutable_borrow_reservation_conflict)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

#[cfg(any(test, feature = "std"))]
Expand Down

0 comments on commit daec17a

Please sign in to comment.