Skip to content

Commit 42cb260

Browse files
Benjamin BrienenBenjamin Brienen
Benjamin Brienen
authored and
Benjamin Brienen
committed
rust 2024 + clippy
1 parent 080b942 commit 42cb260

21 files changed

+316
-172
lines changed

Cargo.toml

+9-8
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ authors = ["Aleksey Kladov <[email protected]>"]
55
repository = "https://github.com/rust-analyzer/rowan"
66
license = "MIT OR Apache-2.0"
77
description = "Library for generic lossless syntax trees"
8-
edition = "2021"
9-
rust-version = "1.77.0"
8+
edition = "2024"
9+
rust-version = "1.85.0"
1010
exclude = [".github/", "bors.toml", "rustfmt.toml"]
1111

1212
[workspace]
1313
members = ["xtask"]
1414

1515
[dependencies]
16-
rustc-hash = "1.0.1"
17-
hashbrown = { version = "0.14.3", features = [
18-
"inline-more",
16+
rustc-hash = "2.1.1"
17+
hashbrown = { version = "0.15.2", features = [
18+
"inline-more",
19+
"raw-entry",
1920
], default-features = false }
20-
text-size = "1.1.0"
21-
countme = "3.0.0"
21+
text-size = "1.1.1"
22+
countme = "3.0.1"
2223

23-
serde = { version = "1.0.89", optional = true, default-features = false }
24+
serde = { version = "1.0.218", optional = true, default-features = false }
2425

2526
[dev-dependencies]
2627
m_lexer = "0.0.4"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Rowan is a library for lossless syntax trees, inspired in part by
77
Swift's [libsyntax](https://github.com/apple/swift/tree/5e2c815edfd758f9b1309ce07bfc01c4bc20ec23/lib/Syntax).
88

9-
A conceptual overview is available in the [rust-analyzer book](https://rust-analyzer.github.io/book/contributing/syntax.html).
9+
A conceptual overview is available in the [rust-analyzer repo](https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/syntax.md).
1010

1111
See `examples/s_expressions` for a tutorial, and [rust-analyzer](https://github.com/rust-analyzer/rust-analyzer/) for real-world usage.
1212

examples/math.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum SyntaxKind {
3232
OPERATION,
3333
ROOT,
3434
}
35+
3536
use SyntaxKind::*;
3637

3738
impl From<SyntaxKind> for rowan::SyntaxKind {

examples/s_expressions.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//!
88
//! It's suggested to read the conceptual overview of the design
99
//! alongside this tutorial:
10-
//! https://rust-analyzer.github.io/book/contributing/syntax.html
10+
//! https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/syntax.md
1111
1212
/// Let's start with defining all kinds of tokens and
1313
/// composite nodes.
@@ -194,8 +194,10 @@ fn parse(text: &str) -> Parse {
194194
/// has identity semantics.
195195
196196
type SyntaxNode = rowan::SyntaxNode<Lang>;
197+
197198
#[allow(unused)]
198199
type SyntaxToken = rowan::SyntaxToken<Lang>;
200+
199201
#[allow(unused)]
200202
type SyntaxElement = rowan::NodeOrToken<SyntaxNode, SyntaxToken>;
201203

@@ -255,11 +257,7 @@ macro_rules! ast_node {
255257
impl $ast {
256258
#[allow(unused)]
257259
fn cast(node: SyntaxNode) -> Option<Self> {
258-
if node.kind() == $kind {
259-
Some(Self(node))
260-
} else {
261-
None
262-
}
260+
if node.kind() == $kind { Some(Self(node)) } else { None }
263261
}
264262
}
265263
};

src/api.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{borrow::Cow, fmt, iter, marker::PhantomData, ops::Range};
22

33
use crate::{
4-
cursor, green::GreenTokenData, Direction, GreenNode, GreenNodeData, GreenToken, NodeOrToken,
5-
SyntaxKind, SyntaxText, TextRange, TextSize, TokenAtOffset, WalkEvent,
4+
Direction, GreenNode, GreenNodeData, GreenToken, NodeOrToken, SyntaxKind, SyntaxText,
5+
TextRange, TextSize, TokenAtOffset, WalkEvent, cursor, green::GreenTokenData,
66
};
77

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

447447
impl<L: Language> SyntaxNodeChildren<L> {
448448
pub fn by_kind(self, matcher: impl Fn(L::Kind) -> bool) -> impl Iterator<Item = SyntaxNode<L>> {
449-
self.raw
450-
.by_kind(move |raw_kind| matcher(L::kind_from_raw(raw_kind)))
451-
.into_iter()
452-
.map(SyntaxNode::from)
449+
self.raw.by_kind(move |raw_kind| matcher(L::kind_from_raw(raw_kind))).map(SyntaxNode::from)
453450
}
454451
}
455452

src/arc.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
cmp::Ordering,
55
hash::{Hash, Hasher},
66
marker::PhantomData,
7-
mem::{self, offset_of, ManuallyDrop},
7+
mem::{self, ManuallyDrop, offset_of},
88
ops::Deref,
99
ptr,
1010
sync::atomic::{
@@ -55,14 +55,17 @@ impl<T> Arc<T> {
5555
pub(crate) unsafe fn from_raw(ptr: *const T) -> Self {
5656
// To find the corresponding pointer to the `ArcInner` we need
5757
// to subtract the offset of the `data` field from the pointer.
58-
let ptr = (ptr as *const u8).sub(offset_of!(ArcInner<T>, data));
59-
Arc { p: ptr::NonNull::new_unchecked(ptr as *mut ArcInner<T>), phantom: PhantomData }
58+
unsafe {
59+
let ptr = (ptr as *const u8).sub(offset_of!(ArcInner<T>, data));
60+
Arc { p: ptr::NonNull::new_unchecked(ptr as *mut ArcInner<T>), phantom: PhantomData }
61+
}
6062
}
6163
}
6264

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

8085
/// Test pointer equality between the two Arcs, i.e. they must be the _same_
@@ -195,10 +200,6 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
195200
fn eq(&self, other: &Arc<T>) -> bool {
196201
Self::ptr_eq(self, other) || *(*self) == *(*other)
197202
}
198-
199-
fn ne(&self, other: &Arc<T>) -> bool {
200-
!Self::ptr_eq(self, other) && *(*self) != *(*other)
201-
}
202203
}
203204

204205
impl<T: ?Sized + PartialOrd> PartialOrd for Arc<T> {
@@ -312,10 +313,7 @@ impl<H, T> ThinArc<H, T> {
312313
};
313314

314315
// Expose the transient Arc to the callback, which may clone it if it wants.
315-
let result = f(&transient);
316-
317-
// Forward the result.
318-
result
316+
f(&transient)
319317
}
320318

321319
/// Creates a `ThinArc` for a HeaderSlice using the given header struct and

src/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<N: AstNode> AstPtr<N> {
156156

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

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

177177
impl<N: AstNode> Clone for AstPtr<N> {
178178
fn clone(&self) -> Self {
179-
Self { raw: self.raw.clone() }
179+
Self { raw: self.raw }
180180
}
181181
}
182182

src/cow_mut.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ impl<T> std::ops::Deref for CowMut<'_, T> {
99
fn deref(&self) -> &T {
1010
match self {
1111
CowMut::Owned(it) => it,
12-
CowMut::Borrowed(it) => *it,
12+
CowMut::Borrowed(it) => it,
1313
}
1414
}
1515
}
@@ -18,7 +18,7 @@ impl<T> std::ops::DerefMut for CowMut<'_, T> {
1818
fn deref_mut(&mut self) -> &mut T {
1919
match self {
2020
CowMut::Owned(it) => it,
21-
CowMut::Borrowed(it) => *it,
21+
CowMut::Borrowed(it) => it,
2222
}
2323
}
2424
}

0 commit comments

Comments
 (0)