Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollup of several outstanding PRs + bump MSRV to Rust 1.73 #198

Merged
merged 25 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b26a0d8
lint: `clippy::deprecated_cfg_attr` lint violations
lopopolo May 21, 2023
6219476
lint: `clippy::get_first` lint violations
lopopolo May 21, 2023
cfb59f9
lint: `clippy::needless_borrow` lint violations
lopopolo May 21, 2023
c357178
lint: `clippy::op_ref` lint violations
lopopolo May 21, 2023
31d583f
lint: `clippy::needless_lifetimes` lint violations
lopopolo May 21, 2023
963727c
lint: `clippy::useless_conversion` lint violations
lopopolo May 21, 2023
0bf20fa
lint: `clippy::map_clone` lint violations
lopopolo May 21, 2023
62a0fdd
lint: `ByteSlice::last_byte`
lopopolo May 21, 2023
c99cbbc
lint: `clippy::redundant_static_lifetimes` lint violations
lopopolo May 21, 2023
0de90c4
lint: `clippy::while_let_on_iterator` lint violations
lopopolo May 21, 2023
ebddbd1
lint: `clippy::needless_return` lint violations
lopopolo May 21, 2023
41f1dee
lint: `clippy::ptr_offset_with_cast` lint violations
lopopolo May 21, 2023
7b54970
lint: `clippy::derived_hash_with_manual_eq` lint violations
lopopolo May 21, 2023
e648a39
lint: `clippy::wildcard_in_or_patterns` lint violations
lopopolo May 21, 2023
23eed04
style: use ptr.sub instead of ptr.offset with cast and assert
lopopolo May 22, 2023
01069a2
lint: `clippy::transmute_ptr_to_ptr` lint violations
lopopolo May 22, 2023
f3e71e2
lint: `clippy::range_plus_one` lint violations
lopopolo May 22, 2023
a3e1b2d
lint: `clippy::cloned_instead_of_copied` lint violation
lopopolo May 22, 2023
5abff4e
lint: `clippy::redundant_closure_for_method_calls` lint violation
lopopolo May 22, 2023
58005de
lint: `clippy::cast_lossless` and `clippy::unreadable_literal` lints
lopopolo May 22, 2023
cfacb78
impl: fix discrepancy in upper/lower case in `impl fmt::Debug for BStr`
wbenny Jul 28, 2024
b011c20
impl: add PartialEq and PartialOrd instances for byte arrays `[u8; N]`
joshtriplett Oct 7, 2024
775a2c1
lint: fix elided_named_lifetimes warning on nightly
joshtriplett Oct 7, 2024
d7a6e5c
safety: introduce `ALIGN_MASK` based on `core::mem::align_of`
anforowicz Oct 25, 2024
9ac0341
msrv: bump to Rust 1.73
BurntSushi Nov 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
include:
- build: pinned
os: ubuntu-latest
rust: 1.65.0
rust: 1.73.0
- build: stable
os: ubuntu-latest
rust: stable
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"
categories = ["text-processing", "encoding"]
exclude = ["/.github", "/scripts"]
edition = "2021"
rust-version = "1.65"
rust-version = "1.73"
resolver = "2"

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Unicode support.

### Minimum Rust version policy

This crate's minimum supported `rustc` version (MSRV) is `1.65`.
This crate's minimum supported `rustc` version (MSRV) is `1.73`.

In general, this crate will be conservative with respect to the minimum
supported version of Rust. MSRV may be bumped in minor version releases.
Expand Down
11 changes: 5 additions & 6 deletions src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#[cfg(any(test, miri, not(target_arch = "x86_64")))]
const USIZE_BYTES: usize = core::mem::size_of::<usize>();
#[cfg(any(test, miri, not(target_arch = "x86_64")))]
const ALIGN_MASK: usize = core::mem::align_of::<usize>() - 1;
#[cfg(any(test, miri, not(target_arch = "x86_64")))]
const FALLBACK_LOOP_SIZE: usize = 2 * USIZE_BYTES;

// This is a mask where the most significant bit of each byte in the usize
Expand Down Expand Up @@ -53,7 +55,6 @@ pub fn first_non_ascii_byte(slice: &[u8]) -> usize {

#[cfg(any(test, miri, not(target_arch = "x86_64")))]
fn first_non_ascii_byte_fallback(slice: &[u8]) -> usize {
let align = USIZE_BYTES - 1;
let start_ptr = slice.as_ptr();
let end_ptr = slice[slice.len()..].as_ptr();
let mut ptr = start_ptr;
Expand All @@ -69,7 +70,7 @@ fn first_non_ascii_byte_fallback(slice: &[u8]) -> usize {
return first_non_ascii_byte_mask(mask);
}

ptr = ptr_add(ptr, USIZE_BYTES - (start_ptr as usize & align));
ptr = ptr_add(ptr, USIZE_BYTES - (start_ptr as usize & ALIGN_MASK));
debug_assert!(ptr > start_ptr);
debug_assert!(ptr_sub(end_ptr, USIZE_BYTES) >= start_ptr);
if slice.len() >= FALLBACK_LOOP_SIZE {
Expand Down Expand Up @@ -233,14 +234,12 @@ fn first_non_ascii_byte_mask(mask: usize) -> usize {

/// Increment the given pointer by the given amount.
unsafe fn ptr_add(ptr: *const u8, amt: usize) -> *const u8 {
debug_assert!(amt < ::core::isize::MAX as usize);
ptr.offset(amt as isize)
ptr.add(amt)
}

/// Decrement the given pointer by the given amount.
unsafe fn ptr_sub(ptr: *const u8, amt: usize) -> *const u8 {
debug_assert!(amt < ::core::isize::MAX as usize);
ptr.offset((amt as isize).wrapping_neg())
ptr.sub(amt)
}

#[cfg(any(test, miri, not(target_arch = "x86_64")))]
Expand Down
9 changes: 3 additions & 6 deletions src/bstr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::mem;

#[cfg(feature = "alloc")]
use alloc::boxed::Box;

Expand Down Expand Up @@ -29,7 +27,6 @@ use alloc::boxed::Box;
/// The `Display` implementation behaves as if `BStr` were first lossily
/// converted to a `str`. Invalid UTF-8 bytes are substituted with the Unicode
/// replacement codepoint, which looks like this: �.
#[derive(Hash)]
#[repr(transparent)]
pub struct BStr {
pub(crate) bytes: [u8],
Expand Down Expand Up @@ -60,7 +57,7 @@ impl BStr {
/// assert_eq!(a, c);
/// ```
#[inline]
pub fn new<'a, B: ?Sized + AsRef<[u8]>>(bytes: &'a B) -> &'a BStr {
pub fn new<B: ?Sized + AsRef<[u8]>>(bytes: &B) -> &BStr {
BStr::from_bytes(bytes.as_ref())
}

Expand All @@ -73,12 +70,12 @@ impl BStr {

#[inline]
pub(crate) fn from_bytes(slice: &[u8]) -> &BStr {
unsafe { mem::transmute(slice) }
unsafe { &*(slice as *const [u8] as *const BStr) }
}

#[inline]
pub(crate) fn from_bytes_mut(slice: &mut [u8]) -> &mut BStr {
unsafe { mem::transmute(slice) }
unsafe { &mut *(slice as *mut [u8] as *mut BStr) }
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/bstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::bstr::BStr;
/// A `BString` has the same representation as a `Vec<u8>` and a `String`.
/// That is, it is made up of three word sized components: a pointer to a
/// region of memory containing the bytes, a length and a capacity.
#[derive(Clone, Hash)]
#[derive(Clone)]
pub struct BString {
bytes: Vec<u8>,
}
Expand Down
8 changes: 4 additions & 4 deletions src/byteset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn build_table(byteset: &[u8]) -> [u8; 256] {
#[inline]
pub(crate) fn find(haystack: &[u8], byteset: &[u8]) -> Option<usize> {
match byteset.len() {
0 => return None,
0 => None,
1 => memchr(byteset[0], haystack),
2 => memchr2(byteset[0], byteset[1], haystack),
3 => memchr3(byteset[0], byteset[1], byteset[2], haystack),
Expand All @@ -28,7 +28,7 @@ pub(crate) fn find(haystack: &[u8], byteset: &[u8]) -> Option<usize> {
#[inline]
pub(crate) fn rfind(haystack: &[u8], byteset: &[u8]) -> Option<usize> {
match byteset.len() {
0 => return None,
0 => None,
1 => memrchr(byteset[0], haystack),
2 => memrchr2(byteset[0], byteset[1], haystack),
3 => memrchr3(byteset[0], byteset[1], byteset[2], haystack),
Expand All @@ -45,7 +45,7 @@ pub(crate) fn find_not(haystack: &[u8], byteset: &[u8]) -> Option<usize> {
return None;
}
match byteset.len() {
0 => return Some(0),
0 => Some(0),
1 => scalar::inv_memchr(byteset[0], haystack),
2 => scalar::forward_search_bytes(haystack, |b| {
b != byteset[0] && b != byteset[1]
Expand All @@ -65,7 +65,7 @@ pub(crate) fn rfind_not(haystack: &[u8], byteset: &[u8]) -> Option<usize> {
return None;
}
match byteset.len() {
0 => return Some(haystack.len() - 1),
0 => Some(haystack.len() - 1),
1 => scalar::inv_memrchr(byteset[0], haystack),
2 => scalar::reverse_search_bytes(haystack, |b| {
b != byteset[0] && b != byteset[1]
Expand Down
7 changes: 3 additions & 4 deletions src/byteset/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use core::{cmp, usize};

const USIZE_BYTES: usize = core::mem::size_of::<usize>();
const ALIGN_MASK: usize = core::mem::align_of::<usize>() - 1;

// The number of bytes to loop at in one iteration of memchr/memrchr.
const LOOP_SIZE: usize = 2 * USIZE_BYTES;
Expand All @@ -22,7 +23,6 @@ pub fn inv_memchr(n1: u8, haystack: &[u8]) -> Option<usize> {
let vn1 = repeat_byte(n1);
let confirm = |byte| byte != n1;
let loop_size = cmp::min(LOOP_SIZE, haystack.len());
let align = USIZE_BYTES - 1;
let start_ptr = haystack.as_ptr();

unsafe {
Expand All @@ -38,7 +38,7 @@ pub fn inv_memchr(n1: u8, haystack: &[u8]) -> Option<usize> {
return forward_search(start_ptr, end_ptr, ptr, confirm);
}

ptr = ptr.add(USIZE_BYTES - (start_ptr as usize & align));
ptr = ptr.add(USIZE_BYTES - (start_ptr as usize & ALIGN_MASK));
debug_assert!(ptr > start_ptr);
debug_assert!(end_ptr.sub(USIZE_BYTES) >= start_ptr);
while loop_size == LOOP_SIZE && ptr <= end_ptr.sub(loop_size) {
Expand All @@ -62,7 +62,6 @@ pub fn inv_memrchr(n1: u8, haystack: &[u8]) -> Option<usize> {
let vn1 = repeat_byte(n1);
let confirm = |byte| byte != n1;
let loop_size = cmp::min(LOOP_SIZE, haystack.len());
let align = USIZE_BYTES - 1;
let start_ptr = haystack.as_ptr();

unsafe {
Expand All @@ -78,7 +77,7 @@ pub fn inv_memrchr(n1: u8, haystack: &[u8]) -> Option<usize> {
return reverse_search(start_ptr, end_ptr, ptr, confirm);
}

ptr = ptr.sub(end_ptr as usize & align);
ptr = ptr.sub(end_ptr as usize & ALIGN_MASK);
debug_assert!(start_ptr <= ptr && ptr <= end_ptr);
while loop_size == LOOP_SIZE && ptr >= start_ptr.add(loop_size) {
debug_assert_eq!(0, (ptr as usize) % USIZE_BYTES);
Expand Down
2 changes: 1 addition & 1 deletion src/escape_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct EscapeBytes<'a> {
}

impl<'a> EscapeBytes<'a> {
pub(crate) fn new(bytes: &'a [u8]) -> EscapeBytes {
pub(crate) fn new(bytes: &'a [u8]) -> EscapeBytes<'a> {
EscapeBytes { remaining: bytes, state: EscapeState::Start }
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/ext_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ use crate::{
/// string literals. This can be quite convenient!
#[allow(non_snake_case)]
#[inline]
pub fn B<'a, B: ?Sized + AsRef<[u8]>>(bytes: &'a B) -> &'a [u8] {
pub fn B<B: ?Sized + AsRef<[u8]>>(bytes: &B) -> &[u8] {
bytes.as_ref()
}

Expand Down Expand Up @@ -3045,7 +3045,7 @@ pub trait ByteSlice: private::Sealed {
#[inline]
fn last_byte(&self) -> Option<u8> {
let bytes = self.as_bytes();
bytes.get(bytes.len().saturating_sub(1)).map(|&b| b)
bytes.last().copied()
}

/// Returns the index of the first non-ASCII byte in this byte string (if
Expand Down Expand Up @@ -3331,7 +3331,7 @@ impl<'a> Iterator for Bytes<'a> {

#[inline]
fn next(&mut self) -> Option<u8> {
self.it.next().map(|&b| b)
self.it.next().copied()
}

#[inline]
Expand All @@ -3343,7 +3343,7 @@ impl<'a> Iterator for Bytes<'a> {
impl<'a> DoubleEndedIterator for Bytes<'a> {
#[inline]
fn next_back(&mut self) -> Option<u8> {
self.it.next_back().map(|&b| b)
self.it.next_back().copied()
}
}

Expand Down Expand Up @@ -3374,7 +3374,7 @@ pub struct Fields<'a> {
#[cfg(feature = "unicode")]
impl<'a> Fields<'a> {
fn new(bytes: &'a [u8]) -> Fields<'a> {
Fields { it: bytes.fields_with(|ch| ch.is_whitespace()) }
Fields { it: bytes.fields_with(char::is_whitespace) }
}
}

Expand Down Expand Up @@ -3428,7 +3428,7 @@ impl<'a, F: FnMut(char) -> bool> Iterator for FieldsWith<'a, F> {
}
}
}
while let Some((_, e, ch)) = self.chars.next() {
for (_, e, ch) in self.chars.by_ref() {
if (self.f)(ch) {
break;
}
Expand Down Expand Up @@ -3744,7 +3744,7 @@ impl<'a> Iterator for LinesWithTerminator<'a> {
Some(line)
}
Some(end) => {
let line = &self.bytes[..end + 1];
let line = &self.bytes[..=end];
self.bytes = &self.bytes[end + 1..];
Some(line)
}
Expand All @@ -3764,7 +3764,7 @@ impl<'a> DoubleEndedIterator for LinesWithTerminator<'a> {
}
Some(end) => {
let line = &self.bytes[end + 1..];
self.bytes = &self.bytes[..end + 1];
self.bytes = &self.bytes[..=end];
Some(line)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/ext_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ pub trait ByteVec: private::Sealed {
fn imp(os_str: OsString) -> Result<Vec<u8>, OsString> {
use std::os::unix::ffi::OsStringExt;

Ok(Vec::from(os_str.into_vec()))
Ok(os_str.into_vec())
}

#[cfg(not(unix))]
Expand Down Expand Up @@ -220,18 +220,18 @@ pub trait ByteVec: private::Sealed {
/// ```
#[inline]
#[cfg(feature = "std")]
fn from_os_str_lossy<'a>(os_str: &'a OsStr) -> Cow<'a, [u8]> {
fn from_os_str_lossy(os_str: &OsStr) -> Cow<'_, [u8]> {
#[cfg(unix)]
#[inline]
fn imp<'a>(os_str: &'a OsStr) -> Cow<'a, [u8]> {
fn imp(os_str: &OsStr) -> Cow<'_, [u8]> {
use std::os::unix::ffi::OsStrExt;

Cow::Borrowed(os_str.as_bytes())
}

#[cfg(not(unix))]
#[inline]
fn imp<'a>(os_str: &'a OsStr) -> Cow<'a, [u8]> {
fn imp(os_str: &OsStr) -> Cow<'_, [u8]> {
match os_str.to_string_lossy() {
Cow::Borrowed(x) => Cow::Borrowed(x.as_bytes()),
Cow::Owned(x) => Cow::Owned(Vec::from(x)),
Expand Down Expand Up @@ -289,7 +289,7 @@ pub trait ByteVec: private::Sealed {
/// ```
#[inline]
#[cfg(feature = "std")]
fn from_path_lossy<'a>(path: &'a Path) -> Cow<'a, [u8]> {
fn from_path_lossy(path: &Path) -> Cow<'_, [u8]> {
Vec::from_os_str_lossy(path.as_os_str())
}

Expand Down Expand Up @@ -958,7 +958,7 @@ pub trait ByteVec: private::Sealed {
R: ops::RangeBounds<usize>,
B: AsRef<[u8]>,
{
self.as_vec_mut().splice(range, replace_with.as_ref().iter().cloned());
self.as_vec_mut().splice(range, replace_with.as_ref().iter().copied());
}

/// Creates a draining iterator that removes the specified range in this
Expand Down
Loading
Loading