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
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion thrust-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ proc-macro = true
[dependencies]
proc-macro2 = "1"
quote = "1"
syn = { version = "2", features = ["extra-traits", "full", "visit", "visit-mut"] }
syn = { version = "3", features = ["extra-traits", "full", "visit", "visit-mut"] }
2 changes: 1 addition & 1 deletion thrust-macros/src/formula_fn_type_lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a> FormulaFnTypeLowering<'a> {
for arg in args {
match arg {
syn::FnArg::Receiver(receiver) => {
let ty = &receiver.ty;
let ty = crate::receiver_type(receiver);
model_inputs.push(syn::parse_quote!(self_: <#ty as thrust_models::Model>::Ty));
}
syn::FnArg::Typed(pt) => {
Expand Down
2 changes: 1 addition & 1 deletion thrust-macros/src/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl VisitMut for SelfValueRewriter {
match arg {
syn::FnArg::Receiver(receiver) => {
let to = &self.to;
let ty = &receiver.ty;
let ty = crate::receiver_type(receiver);
*arg = syn::parse_quote!(#to: #ty);
}
syn::FnArg::Typed(_) => { /* handled by visit_pat_ident_mut */ }
Expand Down
20 changes: 20 additions & 0 deletions thrust-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,26 @@ pub fn sig(attr: TokenStream, item: TokenStream) -> TokenStream {
rty::expand_sig(attr, item)
}

/// Reconstructs the effective type of a method receiver (`&self` -> `&Self`,
/// `&mut self` -> `&mut Self`, `self` -> `Self`, `self: T` -> `T`), mirroring
/// what syn 2's `Receiver::ty` used to provide directly.
fn receiver_type(receiver: &syn::Receiver) -> syn::Type {
match &receiver.kind {
syn::ReceiverKind::Typed(_, ty) => (**ty).clone(),
syn::ReceiverKind::Reference(and_token, lifetime, mutability) => {
syn::Type::Reference(syn::TypeReference {
attrs: Vec::new(),
and_token: *and_token,
lifetime: lifetime.clone(),
mutability: *mutability,
elem: Box::new(syn::parse_quote!(Self)),
})
}
syn::ReceiverKind::Value => syn::parse_quote!(Self),
_ => unimplemented!("unknown syn::ReceiverKind variant"),
}
}

fn tokens_contain_ident<T>(tokens: &TokenStream2, target: T) -> bool
where
T: AsRef<str>,
Expand Down
8 changes: 4 additions & 4 deletions thrust-macros/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ pub fn expand_requires_ensures(attr: TokenStream, item: TokenStream) -> TokenStr
.into();
}

let ens_expr = exprs.pop().unwrap().into_value();
let req_expr = exprs.pop().unwrap().into_value();
let ens_expr = exprs.pop().unwrap();
let req_expr = exprs.pop().unwrap();

let func = parse_macro_input!(item as FnItemWithSignature);
let outer_context = match extract_outer_context(&func) {
Expand Down Expand Up @@ -225,8 +225,8 @@ fn extract_requires_ensures(func: &mut FnItemWithSignature) -> syn::Result<(syn:
"expected exactly two comma-separated expressions in _requires_ensures attribute",
));
}
let ens_expr = exprs.pop().unwrap().into_value();
let req_expr = exprs.pop().unwrap().into_value();
let ens_expr = exprs.pop().unwrap();
let req_expr = exprs.pop().unwrap();
result = Some((req_expr, ens_expr));
}
}
Expand Down