Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Limit attributes copied into generated code (#1429)
### What Limit the attributes that get copied into code generated to: - `doc` - rust docs - `cfg` - used to control whether functions are included or not depending on features - `allow`/`deny` - used to ignore or require compiler warnings ### Why The copying of attributes into generated code is from early code developed for the SDK where we were trying to deal with functions that weren't named consistently with Rust's naming scheme. We wanted to carry through to the generated code `allow` statements so that the generated code didn't generate warnings that were ignored at the source level. However, this has introduced a problem. For any dev who is introducing macros into their contracts and where those macros appear as attributes on contract functions, the macros are then being duplicated into the generated code and injected onto the contract client functions, and modules. Docs attributes are retained because it's valuable if docs show up when hovering over generated contract client functions. The value there is that when someone hovers over a call to a contract client function in an IDE, it'll display the docs for that function. Cfg attributes are retained because folks might put a contract function behind a feature, or behind the test flag, so that the function is only present when that feature is enabled, or tests are enabled. Allow and deny are added because folks might be allowing or denying non-std function names and it'd benefit to pass those allows down to the client at least. Close #1426 ### Known Limitations A limitation with this change, and a risk, is that it is a breaking change that is very difficult to pick up on. Someone may be attaching an attribute to their contract function and expecting it to carry over to the client. After this change is merged unless there is an error compiling or an easily observable change in behaviour, the developer may not know that the attribute no longer applies to the client. I think the risk is lowered because it's unexpected and not normal that the attributes are copied over, so unlikely someone knows they could depend on it, and it's undocumented and not a difficult "feature" to discover. Any use of this kind is likely to be accidental. We could keep this change for the v23 major version to reduce risk, although this change is actually a bug fix blocking development, so I think we should treat it as a bug fix and merge it into a v22 patch release.
- Loading branch information