Skip to content

Commit

Permalink
chore: target nightly-2021-09-04
Browse files Browse the repository at this point in the history
Replaces `guard::guard!` with the native `if let ... else` from
<rust-lang/rfcs#3137> (still unstable).
  • Loading branch information
yvt committed Sep 5, 2021
1 parent 6597abf commit d0efd94
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "interlock"
version = "0.0.0"
authors = ["yvt <[email protected]>"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"
readme = "README.md"
description = "Readers-writer locks optimized for interval locks"
categories = ["no-std"]
Expand All @@ -17,7 +17,6 @@ std = [
]

[dependencies]
guard = "0.5.1" # <https://github.com/rust-lang/rfcs/pull/1303> polyfill
futures = { version = "0.3.16", default-features = false }
pin-utils = "0.1.0"
pin-project = "1.0.8"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2021-08-29
nightly-2021-09-04
8 changes: 4 additions & 4 deletions src/core/rbtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use core::{
pin::Pin,
ptr::NonNull,
};
use guard::guard;

use super::{IntervalRwLockCore, LockCallback, UnlockCallback};
use crate::utils::{
Expand Down Expand Up @@ -908,8 +907,8 @@ where
// `Option<[NonNull<T>; 2]>`. If the result is `None`, return early.
//
// Safety: `*read_nodes` is safe to borrow
guard!(let Some(mut read_nodes) = unsafe { option_array2_as_ptr(read_nodes_ptr) }
else { return; });
let Some(mut read_nodes) =( unsafe { option_array2_as_ptr(read_nodes_ptr) })
else { return; };

// The range we are about to unlock
// Safety: It's still safe to borrow
Expand Down Expand Up @@ -1014,7 +1013,8 @@ where
// If the result is `None`, return early.
//
// Safety: `*pending_node` is safe to borrow
guard!(let Some(mut write_node) = unsafe { option_as_ptr(write_node_ptr) } else { return; });
let Some(mut write_node) = (unsafe { option_as_ptr(write_node_ptr) })
else { return; };

let Range { start, mut end } = unsafe { write_node.as_ref().element.clone() };

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#![doc = include_str!("../README.md")]
#![no_std]
#![deny(unsafe_op_in_unsafe_fn)]
#![allow(clippy::needless_return)] // <https://github.com/rust-lang/rust-clippy/issues/7637>
#![feature(const_fn_trait_bound)]
#![feature(array_methods)]
#![feature(never_type)]
#![feature(type_alias_impl_trait)]
#![feature(const_impl_trait)]
#![feature(slice_ptr_len)]
#![feature(slice_ptr_get)]
#![feature(let_else)] // <https://github.com/rust-lang/rust/issues/87335>

#[cfg(test)]
extern crate std;
Expand Down
11 changes: 5 additions & 6 deletions src/raw/local.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! The thread-unsafe (but faster) implementation.
use core::{ops::Range, pin::Pin};
use guard::guard;
use pin_cell::PinCell;

use crate::{
Expand All @@ -27,11 +26,11 @@ fn deadlocked() -> ! {
}

macro_rules! borrow_core {
(let $p:pat = $self:ident.core) => {
guard!(let Ok(mut core) = $self.project_ref().core.try_borrow_mut()
else { core_is_not_reentrant(); });
let $p = pin_cell::PinMut::as_mut(&mut core);
};
(let $p:pat = $self:ident.core) => {
let Ok(mut core) = $self.project_ref().core.try_borrow_mut()
else { core_is_not_reentrant(); };
let $p = pin_cell::PinMut::as_mut(&mut core);
};
}

unsafe impl<Core: IntervalRwLockCore<InProgress = !>> RawIntervalRwLock
Expand Down
3 changes: 1 addition & 2 deletions src/utils/rbtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use core::{
mem::{replace, swap},
ptr::NonNull,
};
use guard::guard;

#[cfg(not(debug_assertions))]
use core::hint::unreachable_unchecked;
Expand Down Expand Up @@ -405,7 +404,7 @@ impl<Element, Summary: Clone> Node<Element, Summary> {

// If `parent` is `None`, the black height change propagated up to
// the root
guard!(let Some(mut parent) = node.as_ref().parent else { return; });
let Some(mut parent) = node.as_ref().parent else { return; };

loop {
// parent
Expand Down

0 comments on commit d0efd94

Please sign in to comment.