Skip to content

Address issues with rustc 1.65 #31

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

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ fn vec_try_extend<T>(v: &mut Vec<T>, new_cap: usize) -> Result<(), TryReserveErr
let elem_size = core::mem::size_of::<T>();
let new_alloc_size = new_cap
.checked_mul(elem_size)
.filter(|size| *size <= isize::MAX as usize)
.ok_or(TryReserveError::CapacityOverflow)?;

// required for alloc safety
Expand Down Expand Up @@ -824,15 +825,15 @@ mod tests {
fn try_clone_oom() {
let layout = Layout::new::<u8>();
let v =
unsafe { Vec::<u8>::from_raw_parts(alloc(layout), core::usize::MAX, core::usize::MAX) };
unsafe { Vec::<u8>::from_raw_parts(alloc(layout), core::isize::MAX as usize, core::isize::MAX as usize) };
assert!(v.try_clone().is_err());
}

#[test]
fn tryvec_try_clone_oom() {
let layout = Layout::new::<u8>();
let inner =
unsafe { Vec::<u8>::from_raw_parts(alloc(layout), core::usize::MAX, core::usize::MAX) };
unsafe { Vec::<u8>::from_raw_parts(alloc(layout), core::isize::MAX as usize, core::isize::MAX as usize) };
let tv = TryVec { inner };
assert!(tv.try_clone().is_err());
}
Expand All @@ -846,6 +847,10 @@ mod tests {
#[test]
fn oom() {
let mut vec: Vec<char> = Vec::new();
match FallibleVec::try_reserve(&mut vec, core::usize::MAX / std::mem::size_of::<char>()) {
Ok(_) => panic!("it should be OOM"),
_ => (),
}
Comment on lines +850 to +853
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recognize this matches the existing code, but it strikes me as odd to use a match here rather than a simple assert like

Suggested change
match FallibleVec::try_reserve(&mut vec, core::usize::MAX / std::mem::size_of::<char>()) {
Ok(_) => panic!("it should be OOM"),
_ => (),
}
assert!(FallibleVec::try_reserve(&mut vec, core::usize::MAX / std::mem::size_of::<char>()).is_err());

For the sake of clarity, it seems worth changing both to the more idiomatic approach.

Also, based on https://rust-lang.github.io/unsafe-code-guidelines/layout/scalars.html#isize-and-usize, should this be testing the tighter bound of isize::MAX?

match FallibleVec::try_reserve(&mut vec, core::usize::MAX) {
Ok(_) => panic!("it should be OOM"),
_ => (),
Expand All @@ -855,6 +860,10 @@ mod tests {
#[test]
fn tryvec_oom() {
let mut vec: TryVec<char> = TryVec::new();
match vec.reserve(core::usize::MAX / std::mem::size_of::<char>()) {
Ok(_) => panic!("it should be OOM"),
_ => (),
}
match vec.reserve(core::usize::MAX) {
Ok(_) => panic!("it should be OOM"),
_ => (),
Expand Down