Skip to content

Commit

Permalink
Forbid default on logical and terminates functions
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgolfouse committed Nov 12, 2024
1 parent cec2880 commit ac12944
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion creusot-contracts-proc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,17 @@ pub fn snapshot(assertion: TS1) -> TS1 {
#[proc_macro_attribute]
pub fn terminates(_: TS1, tokens: TS1) -> TS1 {
let documentation = document_spec("terminates", TS1::new());
if let Ok(item) = syn::parse::<ImplItemFn>(tokens.clone()) {
if let Some(def) = item.defaultness {
return syn::Error::new(
def.span(),
"`terminates` functions cannot use the `default` modifier",
)
.into_compile_error()
.into();
}
};

let mut result = TS1::from(quote! { #[creusot::clause::terminates] #documentation });
result.extend(tokens);
result
Expand All @@ -434,6 +445,16 @@ pub fn terminates(_: TS1, tokens: TS1) -> TS1 {
#[proc_macro_attribute]
pub fn pure(_: TS1, tokens: TS1) -> TS1 {
let documentation = document_spec("pure", TS1::new());
if let Ok(item) = syn::parse::<ImplItemFn>(tokens.clone()) {
if let Some(def) = item.defaultness {
return syn::Error::new(
def.span(),
"`pure` functions cannot use the `default` modifier",
)
.into_compile_error()
.into();
}
};
let mut result = TS1::from(
quote! { #[creusot::clause::no_panic] #[creusot::clause::terminates] #documentation },
);
Expand Down Expand Up @@ -474,7 +495,13 @@ impl Parse for LogicInput {
let attrs = input.call(Attribute::parse_outer)?;
// Infalliable, no visibility = inherited
let vis: Visibility = input.parse()?;
let default = input.parse()?;
let default: Option<_> = input.parse()?;
if default.is_some() {
return Err(syn::Error::new(
input.span(),
"logical functions cannot use the `default` modifier",
));
}
let sig: Signature = input.parse()?;
let lookahead = input.lookahead1();
if lookahead.peek(Token![;]) {
Expand Down

0 comments on commit ac12944

Please sign in to comment.