diff --git a/codegen/src/function.rs b/codegen/src/function.rs index 8738b410..ceb4cb89 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -503,10 +503,9 @@ impl ExportedFn { } pub fn set_params(&mut self, mut params: ExportedFnParams) -> syn::Result<()> { - // Several issues are checked here to avoid issues with diagnostics caused by raising them - // later. + // Several issues are checked here to avoid issues with diagnostics caused by raising them later. // - // 1. Do not allow non-returning raw functions. + // 1a. Do not allow non-returning raw functions. // if params.return_raw && self.return_type().is_none() { return Err(syn::Error::new( @@ -515,6 +514,15 @@ impl ExportedFn { )); } + // 1b. Do not allow non-method pure functions. + // + if params.pure && !self.mutable_receiver() { + return Err(syn::Error::new( + self.signature.span(), + "functions marked with 'pure' must have a &mut first parameter", + )); + } + match params.special { // 2a. Property getters must take only the subject as an argument. FnSpecialAccess::Property(Property::Get(_)) if self.arg_count() != 1 => {