Skip to content

Commit a8d9fc6

Browse files
Remove unmaintained proc-macro-error2 dependency (RUSTSEC-2026-0173)
1 parent 0711c61 commit a8d9fc6

4 files changed

Lines changed: 33 additions & 34 deletions

File tree

mlua_derive/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ license = "MIT"
1313
proc-macro = true
1414

1515
[features]
16-
macros = ["proc-macro-error2", "itertools"]
16+
macros = ["itertools"]
1717

1818
[dependencies]
1919
quote = "1.0"
2020
proc-macro2 = { version = "1.0", features = ["span-locations"] }
21-
proc-macro-error2 = { version = "2.0.1", optional = true }
2221
syn = { version = "2.0", features = ["full"] }
2322
itertools = { version = "0.14", optional = true }

mlua_derive/src/chunk/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ pub(crate) struct Chunk {
6363
}
6464

6565
impl Chunk {
66-
pub(crate) fn new(tokens: TokenStream) -> Self {
67-
let tokens = Tokens::retokenize(tokens);
66+
pub(crate) fn new(tokens: TokenStream) -> Result<Self, TokenStream2> {
67+
let tokens = Tokens::retokenize(tokens)?;
6868

6969
let mut source = String::new();
7070
let mut caps = Captures::new();
@@ -91,10 +91,10 @@ impl Chunk {
9191
prev_end = Some(t.end());
9292
}
9393

94-
Self {
94+
Ok(Self {
9595
source: source.trim_end().to_string(),
9696
caps,
97-
}
97+
})
9898
}
9999

100100
pub(crate) fn captures(&self) -> &[Capture] {

mlua_derive/src/chunk/token.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ use std::cmp::{Eq, PartialEq};
22
use std::fmt::{self, Display, Formatter};
33
use std::vec::IntoIter;
44

5-
use itertools::Itertools;
65
use proc_macro::{Delimiter, Span, TokenStream, TokenTree};
76
use proc_macro2::Span as Span2;
7+
use proc_macro2::TokenStream as TokenStream2;
8+
use syn;
89

910
#[derive(Clone, Copy, Debug)]
1011
pub(crate) struct Pos {
@@ -39,9 +40,7 @@ fn span_pos(span: &Span) -> (Pos, Pos) {
3940

4041
// Rust 1.88 stabilized Span APIs, so this branch must be unreachable
4142
if start.line == 0 || end.line == 0 {
42-
proc_macro_error2::abort_call_site!(
43-
"cannot retrieve span location information; mlua requires nightly Rust or stable >= 1.88"
44-
);
43+
unreachable!("cannot retrieve span location information; mlua requires nightly Rust or stable >= 1.88");
4544
}
4645

4746
(Pos::new(start.line, start.column), Pos::new(end.line, end.column))
@@ -133,27 +132,26 @@ impl Token {
133132
pub(crate) struct Tokens(pub(crate) Vec<Token>);
134133

135134
impl Tokens {
136-
pub(crate) fn retokenize(tt: TokenStream) -> Tokens {
137-
Tokens(
138-
tt.into_iter()
139-
.flat_map(Tokens::from)
140-
.batching(|iter| {
141-
// Find variable tokens: `$` + `ident` => `$ident`
142-
let t = iter.next()?;
143-
if t.is("$") {
144-
if let Some(next) = iter.next()
145-
&& matches!(next.tree, TokenTree::Ident(_))
146-
{
147-
Some(next.attr(TokenAttr::Cap))
148-
} else {
149-
proc_macro_error2::abort!(t.tree.span(), "`$` must be followed by an identifier");
150-
}
151-
} else {
152-
Some(t)
153-
}
154-
})
155-
.collect(),
156-
)
135+
pub(crate) fn retokenize(tt: TokenStream) -> Result<Tokens, TokenStream2> {
136+
let flat: Vec<Token> = tt.into_iter().flat_map(Tokens::from).collect();
137+
let mut tokens = Vec::new();
138+
let mut iter = flat.into_iter();
139+
while let Some(t) = iter.next() {
140+
// Find variable tokens: `$` + `ident` => `$ident`
141+
if t.is("$") {
142+
if let Some(next) = iter.next()
143+
&& matches!(next.tree, TokenTree::Ident(_))
144+
{
145+
tokens.push(next.attr(TokenAttr::Cap));
146+
} else {
147+
return Err(syn::Error::new(t.tree.span().into(), "`$` must be followed by an identifier")
148+
.to_compile_error());
149+
}
150+
} else {
151+
tokens.push(t);
152+
}
153+
}
154+
Ok(Tokens(tokens))
157155
}
158156
}
159157

mlua_derive/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use proc_macro::TokenStream;
33
mod module;
44

55
#[cfg(feature = "macros")]
6-
use {crate::chunk::Chunk, proc_macro_error2::proc_macro_error};
6+
use crate::chunk::Chunk;
77

88
#[cfg(feature = "macros")]
99
macro_rules! try_compile {
@@ -22,9 +22,11 @@ pub fn lua_module(attr: TokenStream, item: TokenStream) -> TokenStream {
2222

2323
#[cfg(feature = "macros")]
2424
#[proc_macro]
25-
#[proc_macro_error]
2625
pub fn chunk(input: TokenStream) -> TokenStream {
27-
Chunk::new(input).expand().into()
26+
match Chunk::new(input) {
27+
Ok(chunk) => chunk.expand().into(),
28+
Err(err) => err.into(),
29+
}
2830
}
2931

3032
#[cfg(feature = "macros")]

0 commit comments

Comments
 (0)