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

Clean up soon to be stable features and enabled lints #705

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo miri test -p rune-alloc --all-features

rune_nightly:
runs-on: ubuntu-latest
needs: basics
env:
RUSTFLAGS: -D warnings --cfg rune_nightly
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: miri
- uses: Swatinem/rust-cache@v2
- run: cargo build --all-features
- run: cargo build --tests --all-features

no_default_features:
runs-on: ubuntu-latest
needs: basics
Expand Down
2 changes: 2 additions & 0 deletions crates/rune-alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ categories = ["parser-implementations"]
default = ["std", "serde"]
std = ["alloc", "ahash/std", "serde?/std"]
alloc = []
inline-more = []
raw = []

[dependencies]
rune-alloc-macros = { version = "=0.14.0", path = "../rune-alloc-macros" }
Expand Down
8 changes: 0 additions & 8 deletions crates/rune-alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,6 @@ impl<T, A: Allocator> Box<T, A> {
unsafe { Ok(Box::from_raw_in(ptr.as_ptr(), alloc)) }
}

/// Converts a `Box<T>` into a `Box<[T]>`
///
/// This conversion does not allocate on the heap and happens in place.
pub(crate) fn into_boxed_slice(boxed: Self) -> Box<[T], A> {
let (raw, alloc) = Box::into_raw_with_allocator(boxed);
unsafe { Box::from_raw_in(raw as *mut [T; 1], alloc) }
}

/// Consumes the `Box`, returning the wrapped value.
#[inline]
pub fn into_inner(boxed: Self) -> T {
Expand Down
11 changes: 0 additions & 11 deletions crates/rune-alloc/src/btree/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,4 @@ impl<'a, T> DormantMutRef<'a, T> {
// SAFETY: our own safety conditions imply this reference is again unique.
unsafe { &mut *self.ptr.as_ptr() }
}

/// Borrows a new shared reference from the unique borrow initially captured.
///
/// # Safety
///
/// The reborrow must have ended, i.e., the reference returned by `new` and
/// all pointers and references derived from it, must not be used anymore.
pub(crate) unsafe fn reborrow_shared(&self) -> &'a T {
// SAFETY: our own safety conditions imply this reference is again unique.
unsafe { &*self.ptr.as_ptr() }
}
}
70 changes: 16 additions & 54 deletions crates/rune-alloc/src/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3156,8 +3156,11 @@ impl<K: Debug, V: Debug> Debug for Cursor<'_, K, V> {
/// methods.
pub struct CursorMut<'a, K: 'a, V: 'a, A = Global> {
current: Option<Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::KV>>,
#[cfg_attr(not(test), allow(unused))]
root: DormantMutRef<'a, Option<node::Root<K, V>>>,
#[cfg_attr(not(test), allow(unused))]
length: &'a mut usize,
#[cfg_attr(not(test), allow(unused))]
alloc: &'a mut A,
}

Expand All @@ -3173,6 +3176,7 @@ impl<'a, K, V> Cursor<'a, K, V> {
/// If the cursor is pointing to the "ghost" non-element then this will move it to
/// the first element of the `BTreeMap`. If it is pointing to the last
/// element of the `BTreeMap` then this will move it to the "ghost" non-element.
#[cfg(test)]
pub(crate) fn move_next(&mut self) {
match self.current.take() {
None => {
Expand All @@ -3195,6 +3199,7 @@ impl<'a, K, V> Cursor<'a, K, V> {
/// If the cursor is pointing to the "ghost" non-element then this will move it to
/// the last element of the `BTreeMap`. If it is pointing to the first
/// element of the `BTreeMap` then this will move it to the "ghost" non-element.
#[cfg(test)]
pub(crate) fn move_prev(&mut self) {
match self.current.take() {
None => {
Expand Down Expand Up @@ -3244,6 +3249,7 @@ impl<'a, K, V> Cursor<'a, K, V> {
/// If the cursor is pointing to the "ghost" non-element then this returns
/// the first element of the `BTreeMap`. If it is pointing to the last
/// element of the `BTreeMap` then this returns `None`.
#[cfg(test)]
pub(crate) fn peek_next(&self) -> Option<(&'a K, &'a V)> {
let mut next = self.clone();
next.move_next();
Expand All @@ -3255,6 +3261,7 @@ impl<'a, K, V> Cursor<'a, K, V> {
/// If the cursor is pointing to the "ghost" non-element then this returns
/// the last element of the `BTreeMap`. If it is pointing to the first
/// element of the `BTreeMap` then this returns `None`.
#[cfg(test)]
pub(crate) fn peek_prev(&self) -> Option<(&'a K, &'a V)> {
let mut prev = self.clone();
prev.move_prev();
Expand All @@ -3268,6 +3275,7 @@ impl<'a, K, V, A> CursorMut<'a, K, V, A> {
/// If the cursor is pointing to the "ghost" non-element then this will move it to
/// the first element of the `BTreeMap`. If it is pointing to the last
/// element of the `BTreeMap` then this will move it to the "ghost" non-element.
#[cfg(test)]
pub(crate) fn move_next(&mut self) {
match self.current.take() {
None => {
Expand All @@ -3286,29 +3294,6 @@ impl<'a, K, V, A> CursorMut<'a, K, V, A> {
}
}

/// Moves the cursor to the previous element of the `BTreeMap`.
///
/// If the cursor is pointing to the "ghost" non-element then this will move it to
/// the last element of the `BTreeMap`. If it is pointing to the first
/// element of the `BTreeMap` then this will move it to the "ghost" non-element.
pub(crate) fn move_prev(&mut self) {
match self.current.take() {
None => {
// SAFETY: The previous borrow of root has ended.
self.current = unsafe { self.root.reborrow() }.as_mut().and_then(|root| {
root.borrow_mut()
.last_leaf_edge()
.forget_node_type()
.left_kv()
.ok()
});
}
Some(current) => {
self.current = current.next_back_leaf_edge().next_back_kv().ok();
}
}
}

/// Returns a reference to the key of the element that the cursor is
/// currently pointing to.
///
Expand Down Expand Up @@ -3363,29 +3348,12 @@ impl<'a, K, V, A> CursorMut<'a, K, V, A> {
})
}

/// Returns a mutable reference to the key of the element that the cursor is
/// currently pointing to.
///
/// This returns `None` if the cursor is currently pointing to the
/// "ghost" non-element.
///
/// # Safety
///
/// This can be used to modify the key, but you must ensure that the
/// `BTreeMap` invariants are maintained. Specifically:
///
/// * The key must remain unique within the tree.
/// * The key must remain in sorted order with regards to other elements in
/// the tree.
pub(crate) unsafe fn key_mut_unchecked(&mut self) -> Option<&mut K> {
self.current.as_mut().map(|current| current.kv_mut().0)
}

/// Returns a reference to the key and value of the next element.
///
/// If the cursor is pointing to the "ghost" non-element then this returns
/// the first element of the `BTreeMap`. If it is pointing to the last
/// element of the `BTreeMap` then this returns `None`.
#[cfg(test)]
pub(crate) fn peek_next(&mut self) -> Option<(&K, &mut V)> {
let (k, v) = match self.current {
None => {
Expand Down Expand Up @@ -3413,6 +3381,7 @@ impl<'a, K, V, A> CursorMut<'a, K, V, A> {
/// If the cursor is pointing to the "ghost" non-element then this returns
/// the last element of the `BTreeMap`. If it is pointing to the first
/// element of the `BTreeMap` then this returns `None`.
#[cfg(test)]
pub(crate) fn peek_prev(&mut self) -> Option<(&K, &mut V)> {
let (k, v) = match self.current.as_mut() {
None => {
Expand All @@ -3436,19 +3405,6 @@ impl<'a, K, V, A> CursorMut<'a, K, V, A> {
};
Some((k, v))
}

/// Returns a read-only cursor pointing to the current element.
///
/// The lifetime of the returned `Cursor` is bound to that of the
/// `CursorMut`, which means it cannot outlive the `CursorMut` and that the
/// `CursorMut` is frozen for the lifetime of the `Cursor`.
pub(crate) fn as_cursor(&self) -> Cursor<'_, K, V> {
Cursor {
// SAFETY: The tree is immutable while the cursor exists.
root: unsafe { self.root.reborrow_shared().as_ref() },
current: self.current.as_ref().map(|current| current.reborrow()),
}
}
}

// Now the tree editing operations
Expand All @@ -3465,6 +3421,7 @@ impl<'a, K: Ord, V, A: Allocator> CursorMut<'a, K, V, A> {
///
/// * The key of the newly inserted element must be unique in the tree.
/// * All keys in the tree must remain in sorted order.
#[cfg(test)]
pub(crate) unsafe fn try_insert_after_unchecked(
&mut self,
key: K,
Expand Down Expand Up @@ -3514,6 +3471,7 @@ impl<'a, K: Ord, V, A: Allocator> CursorMut<'a, K, V, A> {
///
/// * The key of the newly inserted element must be unique in the tree.
/// * All keys in the tree must remain in sorted order.
#[cfg(test)]
pub(crate) unsafe fn try_insert_before_unchecked(
&mut self,
key: K,
Expand Down Expand Up @@ -3563,6 +3521,7 @@ impl<'a, K: Ord, V, A: Allocator> CursorMut<'a, K, V, A> {
/// any).
/// - the given key compares greater than or equal to the next element (if
/// any).
#[cfg(test)]
pub(crate) fn try_insert_after(&mut self, key: K, value: V) -> Result<(), AllocError> {
if let Some(current) = self.key() {
if &key <= current {
Expand Down Expand Up @@ -3597,6 +3556,7 @@ impl<'a, K: Ord, V, A: Allocator> CursorMut<'a, K, V, A> {
/// (if any).
/// - the given key compares less than or equal to the previous element (if
/// any).
#[cfg(test)]
pub(crate) fn try_insert_before(&mut self, key: K, value: V) -> Result<(), AllocError> {
if let Some(current) = self.key() {
if &key >= current {
Expand Down Expand Up @@ -3626,6 +3586,7 @@ impl<'a, K: Ord, V, A: Allocator> CursorMut<'a, K, V, A> {
///
/// If the cursor is currently pointing to the "ghost" non-element then no element
/// is removed and `None` is returned. The cursor is not moved in this case.
#[cfg(test)]
pub(crate) fn remove_current(&mut self) -> Option<(K, V)> {
let current = self.current.take()?;
let mut emptied_internal_root = false;
Expand All @@ -3648,6 +3609,7 @@ impl<'a, K: Ord, V, A: Allocator> CursorMut<'a, K, V, A> {
///
/// If the cursor is currently pointing to the "ghost" non-element then no element
/// is removed and `None` is returned. The cursor is not moved in this case.
#[cfg(test)]
pub(crate) fn remove_current_and_move_back(&mut self) -> Option<(K, V)> {
let current = self.current.take()?;
let mut emptied_internal_root = false;
Expand Down
2 changes: 1 addition & 1 deletion crates/rune-alloc/src/btree/navigate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea
pub(crate) enum Position<BorrowType, K, V> {
Leaf(NodeRef<BorrowType, K, V, marker::Leaf>),
Internal(NodeRef<BorrowType, K, V, marker::Internal>),
InternalKV(Handle<NodeRef<BorrowType, K, V, marker::Internal>, marker::KV>),
InternalKV(#[allow(unused)] Handle<NodeRef<BorrowType, K, V, marker::Internal>, marker::KV>),
}

impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal> {
Expand Down
1 change: 1 addition & 0 deletions crates/rune-alloc/src/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ impl<'a, K: 'a, V: 'a, NodeType> Handle<NodeRef<marker::Mut<'a>, K, V, NodeType>
unsafe { leaf.vals.get_unchecked_mut(self.idx).assume_init_mut() }
}

#[cfg(test)]
pub(crate) fn into_kv_valmut(self) -> (&'a K, &'a mut V) {
debug_assert!(self.idx < self.node.len());
let leaf = self.node.into_leaf_mut();
Expand Down
2 changes: 1 addition & 1 deletion crates/rune-alloc/src/btree/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ fn test_extend_ref() {
#[test]
fn test_recovery() {
#[derive(Debug)]
struct Foo(&'static str, i32);
struct Foo(&'static str, #[allow(unused)] i32);

impl PartialEq for Foo {
fn eq(&self, other: &Self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/rune-alloc/src/hashbrown/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ impl<T, A: Allocator> RawTable<T, A> {
///
/// This does not check if the given element already exists in the table.
#[cfg_attr(feature = "inline-more", inline)]
#[cfg(any(feature = "raw", feature = "rustc-internal-api"))]
#[cfg(feature = "raw")]
pub unsafe fn insert_no_grow(&mut self, hash: u64, value: T) -> Bucket<T> {
let (index, old_ctrl) = self.table.prepare_insert_slot(hash);
let bucket = self.table.bucket(index);
Expand Down
2 changes: 1 addition & 1 deletion crates/rune-alloc/src/hashbrown/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,7 @@ mod test_set {
use core::hash;

#[derive(Debug)]
struct Foo(&'static str, i32);
struct Foo(&'static str, #[allow(unused)] i32);

impl PartialEq for Foo {
fn eq(&self, other: &Self) -> bool {
Expand Down
13 changes: 4 additions & 9 deletions crates/rune-alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,20 @@
// may not be copied, modified, or distributed except according to those terms.

#![no_std]
// TODO: get rid of this once we've evaluated what we want to have public.
#![allow(dead_code)]
#![allow(unexpected_cfgs)]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(rustdoc::private_doc_tests)]
#![cfg_attr(rune_nightly, feature(rustdoc_missing_doc_code_examples))]
#![cfg_attr(rune_nightly, deny(rustdoc::missing_doc_code_examples))]
#![cfg_attr(rune_nightly, allow(internal_features))]
#![cfg_attr(rune_nightly, feature(fmt_internals))]
#![cfg_attr(rune_nightly, feature(rustdoc_missing_doc_code_examples))]
#![cfg_attr(rune_nightly, feature(core_intrinsics))]
#![cfg_attr(rune_nightly, feature(dropck_eyepatch))]
#![cfg_attr(rune_nightly, feature(min_specialization))]
#![cfg_attr(rune_nightly, feature(ptr_sub_ptr))]
#![cfg_attr(rune_nightly, feature(set_ptr_value))]
#![cfg_attr(rune_nightly, feature(slice_ptr_len))]
#![cfg_attr(rune_nightly, feature(slice_range))]
#![cfg_attr(rune_nightly, feature(strict_provenance))]
#![cfg_attr(rune_nightly, feature(saturating_int_impl))]
#![cfg_attr(rune_nightly, feature(inline_const))]
#![cfg_attr(rune_nightly, feature(const_maybe_uninit_zeroed))]
// The only feature we use is `rustc_specialization_trait`.
#![cfg_attr(rune_nightly, allow(internal_features))]
#![cfg_attr(rune_nightly, feature(rustc_attrs))]
#![allow(clippy::comparison_chain)]
#![allow(clippy::manual_map)]
Expand Down
3 changes: 3 additions & 0 deletions crates/rune-alloc/src/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum AllocInit {
/// The contents of the new memory are uninitialized.
Uninitialized,
/// The new memory is guaranteed to be zeroed.
#[cfg(rune_nightly)]
Zeroed,
}

Expand Down Expand Up @@ -99,6 +100,7 @@ impl<T, A: Allocator> RawVec<T, A> {
/// Like `with_capacity_zeroed`, but parameterized over the choice
/// of allocator for the returned `RawVec`.
#[inline]
#[cfg(rune_nightly)]
pub(crate) fn try_with_capacity_zeroed_in(capacity: usize, alloc: A) -> Result<Self, Error> {
Self::try_allocate_in(capacity, AllocInit::Zeroed, alloc)
}
Expand Down Expand Up @@ -146,6 +148,7 @@ impl<T, A: Allocator> RawVec<T, A> {
}
let ptr = match init {
AllocInit::Uninitialized => alloc.allocate(layout)?,
#[cfg(rune_nightly)]
AllocInit::Zeroed => alloc.allocate_zeroed(layout)?,
};

Expand Down
7 changes: 0 additions & 7 deletions crates/rune-alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,6 @@ where
}
}

#[doc(hidden)]
pub trait NonDrop {}

// T: Copy as approximation for !Drop since get_unchecked does not advance self.ptr
// and thus we can't implement drop-handling
impl<T: Copy> NonDrop for T {}

#[cfg(rune_nightly)]
unsafe impl<#[may_dangle] T, A: Allocator> Drop for IntoIter<T, A> {
fn drop(&mut self) {
Expand Down
4 changes: 0 additions & 4 deletions crates/rune-alloc/src/vec_deque/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ impl<T, A: Allocator> IntoIter<T, A> {
pub(super) fn new(inner: VecDeque<T, A>) -> Self {
IntoIter { inner }
}

pub(super) fn into_vecdeque(self) -> VecDeque<T, A> {
self.inner
}
}

impl<T: fmt::Debug, A: Allocator> fmt::Debug for IntoIter<T, A> {
Expand Down
Loading
Loading