Skip to content
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
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
repository = "https://github.com/rust-analyzer/rowan"
license = "MIT OR Apache-2.0"
description = "Library for generic lossless syntax trees"
edition = "2021"
rust-version = "1.77.0"
edition = "2024"
rust-version = "1.85.0"
exclude = [".github/", "bors.toml", "rustfmt.toml"]

[workspace]
members = ["xtask"]

[dependencies]
rustc-hash = "1.0.1"
hashbrown = { version = "0.14.3", features = [
"inline-more",
rustc-hash = "2.1.1"
hashbrown = { version = "0.15.2", features = [
"inline-more",
"raw-entry",
], default-features = false }
text-size = "1.1.0"
countme = "3.0.0"
text-size = "1.1.1"
countme = "3.0.1"

serde = { version = "1.0.89", optional = true, default-features = false }
serde = { version = "1.0.218", optional = true, default-features = false }

[dev-dependencies]
m_lexer = "0.0.4"
Expand Down
1 change: 1 addition & 0 deletions examples/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum SyntaxKind {
OPERATION,
ROOT,
}

use SyntaxKind::*;

impl From<SyntaxKind> for rowan::SyntaxKind {
Expand Down
8 changes: 3 additions & 5 deletions examples/s_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ fn parse(text: &str) -> Parse {
/// has identity semantics.

type SyntaxNode = rowan::SyntaxNode<Lang>;

#[allow(unused)]
type SyntaxToken = rowan::SyntaxToken<Lang>;

#[allow(unused)]
type SyntaxElement = rowan::NodeOrToken<SyntaxNode, SyntaxToken>;

Expand Down Expand Up @@ -255,11 +257,7 @@ macro_rules! ast_node {
impl $ast {
#[allow(unused)]
fn cast(node: SyntaxNode) -> Option<Self> {
if node.kind() == $kind {
Some(Self(node))
} else {
None
}
if node.kind() == $kind { Some(Self(node)) } else { None }
}
}
};
Expand Down
9 changes: 3 additions & 6 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{borrow::Cow, fmt, iter, marker::PhantomData, ops::Range};

use crate::{
cursor, green::GreenTokenData, Direction, GreenNode, GreenNodeData, GreenToken, NodeOrToken,
SyntaxKind, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent,
Direction, GreenNode, GreenNodeData, GreenToken, NodeOrToken, SyntaxKind, SyntaxText,
TextRange, TextSize, TokenAtOffset, WalkEvent, cursor, green::GreenTokenData,
};

pub trait Language: Sized + Copy + fmt::Debug + Eq + Ord + std::hash::Hash {
Expand Down Expand Up @@ -446,10 +446,7 @@ impl<L: Language> Iterator for SyntaxNodeChildren<L> {

impl<L: Language> SyntaxNodeChildren<L> {
pub fn by_kind(self, matcher: impl Fn(L::Kind) -> bool) -> impl Iterator<Item = SyntaxNode<L>> {
self.raw
.by_kind(move |raw_kind| matcher(L::kind_from_raw(raw_kind)))
.into_iter()
.map(SyntaxNode::from)
self.raw.by_kind(move |raw_kind| matcher(L::kind_from_raw(raw_kind))).map(SyntaxNode::from)
}
}

Expand Down
22 changes: 10 additions & 12 deletions src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
cmp::Ordering,
hash::{Hash, Hasher},
marker::PhantomData,
mem::{self, offset_of, ManuallyDrop},
mem::{self, ManuallyDrop, offset_of},
ops::Deref,
ptr,
sync::atomic::{
Expand Down Expand Up @@ -55,14 +55,17 @@ impl<T> Arc<T> {
pub(crate) unsafe fn from_raw(ptr: *const T) -> Self {
// To find the corresponding pointer to the `ArcInner` we need
// to subtract the offset of the `data` field from the pointer.
let ptr = (ptr as *const u8).sub(offset_of!(ArcInner<T>, data));
Arc { p: ptr::NonNull::new_unchecked(ptr as *mut ArcInner<T>), phantom: PhantomData }
unsafe {
let ptr = (ptr as *const u8).sub(offset_of!(ArcInner<T>, data));
Arc { p: ptr::NonNull::new_unchecked(ptr as *mut ArcInner<T>), phantom: PhantomData }
}
}
}

impl<T: ?Sized> Arc<T> {
#[inline]
fn inner(&self) -> &ArcInner<T> {
// SAFETY:
// This unsafety is ok because while this arc is alive we're guaranteed
// that the inner pointer is valid. Furthermore, we know that the
// `ArcInner` structure itself is `Sync` because the inner data is
Expand All @@ -74,7 +77,9 @@ impl<T: ?Sized> Arc<T> {
// Non-inlined part of `drop`. Just invokes the destructor.
#[inline(never)]
unsafe fn drop_slow(&mut self) {
let _ = Box::from_raw(self.ptr());
unsafe {
let _ = Box::from_raw(self.ptr());
}
}

/// Test pointer equality between the two Arcs, i.e. they must be the _same_
Expand Down Expand Up @@ -195,10 +200,6 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
fn eq(&self, other: &Arc<T>) -> bool {
Self::ptr_eq(self, other) || *(*self) == *(*other)
}

fn ne(&self, other: &Arc<T>) -> bool {
!Self::ptr_eq(self, other) && *(*self) != *(*other)
}
}

impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
Expand Down Expand Up @@ -312,10 +313,7 @@ impl<H, T> ThinArc<H, T> {
};

// Expose the transient Arc to the callback, which may clone it if it wants.
let result = f(&transient);

// Forward the result.
result
f(&transient)
}

/// Creates a `ThinArc` for a HeaderSlice using the given header struct and
Expand Down
4 changes: 2 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<N: AstNode> AstPtr<N> {

/// Returns the underlying [`SyntaxNodePtr`].
pub fn syntax_node_ptr(&self) -> SyntaxNodePtr<N::Language> {
self.raw.clone()
self.raw
}

/// Casts this to an [`AstPtr`] to the given node type if possible.
Expand All @@ -176,7 +176,7 @@ impl<N: AstNode> fmt::Debug for AstPtr<N> {

impl<N: AstNode> Clone for AstPtr<N> {
fn clone(&self) -> Self {
Self { raw: self.raw.clone() }
Self { raw: self.raw }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cow_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<T> std::ops::Deref for CowMut<'_, T> {
fn deref(&self) -> &T {
match self {
CowMut::Owned(it) => it,
CowMut::Borrowed(it) => *it,
CowMut::Borrowed(it) => it,
}
}
}
Expand All @@ -18,7 +18,7 @@ impl<T> std::ops::DerefMut for CowMut<'_, T> {
fn deref_mut(&mut self) -> &mut T {
match self {
CowMut::Owned(it) => it,
CowMut::Borrowed(it) => *it,
CowMut::Borrowed(it) => it,
}
}
}
Expand Down
Loading
Loading