Skip to content

Commit 4e5d69c

Browse files
committed
Fix thrust-macros build against syn 3.0
syn 3.0 restructures method receivers: Receiver::ty is replaced by a ReceiverKind enum (Value/Reference/Typed), and Punctuated::pop() now returns the element directly instead of a Pair, so Pair::into_value() no longer applies. Add a receiver_type() helper that reconstructs the effective self type (mirroring syn 2's Receiver::ty) and use it at both call sites, and drop the now-unnecessary into_value() calls in spec.rs.
1 parent 39453ac commit 4e5d69c

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

thrust-macros/src/formula_fn_type_lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a> FormulaFnTypeLowering<'a> {
4949
for arg in args {
5050
match arg {
5151
syn::FnArg::Receiver(receiver) => {
52-
let ty = &receiver.ty;
52+
let ty = crate::receiver_type(receiver);
5353
model_inputs.push(syn::parse_quote!(self_: <#ty as thrust_models::Model>::Ty));
5454
}
5555
syn::FnArg::Typed(pt) => {

thrust-macros/src/invariant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl VisitMut for SelfValueRewriter {
300300
match arg {
301301
syn::FnArg::Receiver(receiver) => {
302302
let to = &self.to;
303-
let ty = &receiver.ty;
303+
let ty = crate::receiver_type(receiver);
304304
*arg = syn::parse_quote!(#to: #ty);
305305
}
306306
syn::FnArg::Typed(_) => { /* handled by visit_pat_ident_mut */ }

thrust-macros/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ pub fn sig(attr: TokenStream, item: TokenStream) -> TokenStream {
133133
rty::expand_sig(attr, item)
134134
}
135135

136+
/// Reconstructs the effective type of a method receiver (`&self` -> `&Self`,
137+
/// `&mut self` -> `&mut Self`, `self` -> `Self`, `self: T` -> `T`), mirroring
138+
/// what syn 2's `Receiver::ty` used to provide directly.
139+
fn receiver_type(receiver: &syn::Receiver) -> syn::Type {
140+
match &receiver.kind {
141+
syn::ReceiverKind::Typed(_, ty) => (**ty).clone(),
142+
syn::ReceiverKind::Reference(and_token, lifetime, mutability) => {
143+
syn::Type::Reference(syn::TypeReference {
144+
attrs: Vec::new(),
145+
and_token: *and_token,
146+
lifetime: lifetime.clone(),
147+
mutability: *mutability,
148+
elem: Box::new(syn::parse_quote!(Self)),
149+
})
150+
}
151+
syn::ReceiverKind::Value => syn::parse_quote!(Self),
152+
_ => unimplemented!("unknown syn::ReceiverKind variant"),
153+
}
154+
}
155+
136156
fn tokens_contain_ident<T>(tokens: &TokenStream2, target: T) -> bool
137157
where
138158
T: AsRef<str>,

thrust-macros/src/spec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ pub fn expand_requires_ensures(attr: TokenStream, item: TokenStream) -> TokenStr
9999
.into();
100100
}
101101

102-
let ens_expr = exprs.pop().unwrap().into_value();
103-
let req_expr = exprs.pop().unwrap().into_value();
102+
let ens_expr = exprs.pop().unwrap();
103+
let req_expr = exprs.pop().unwrap();
104104

105105
let func = parse_macro_input!(item as FnItemWithSignature);
106106
let outer_context = match extract_outer_context(&func) {
@@ -225,8 +225,8 @@ fn extract_requires_ensures(func: &mut FnItemWithSignature) -> syn::Result<(syn:
225225
"expected exactly two comma-separated expressions in _requires_ensures attribute",
226226
));
227227
}
228-
let ens_expr = exprs.pop().unwrap().into_value();
229-
let req_expr = exprs.pop().unwrap().into_value();
228+
let ens_expr = exprs.pop().unwrap();
229+
let req_expr = exprs.pop().unwrap();
230230
result = Some((req_expr, ens_expr));
231231
}
232232
}

0 commit comments

Comments
 (0)