Skip to content

Commit 0549e6a

Browse files
authored
Add guideline stub for attribute macros (rustfoundation#62)
* add attribute macro guideline stub * typo * phrasing
1 parent 9c7d814 commit 0549e6a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/coding-guidelines/macros.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,48 @@ Macros
215215
fn example_function() {
216216
// Compliant implementation
217217
}
218+
219+
.. guideline:: Attribute macros shall not be used
220+
:id: gui_13XWp3mb0g2P
221+
:category: required
222+
:status: draft
223+
:release: todo
224+
:fls: fls_4vjbkm4ceymk
225+
:decidability: decidable
226+
:scope: system
227+
:tags: reduce-human-error
228+
229+
Attribute macros shall neither be declared nor invoked.
230+
Prefer less powerful macros that only extend source code.
231+
232+
.. rationale::
233+
:id: rat_X8uCF5yx7Mpo
234+
:status: draft
235+
236+
Attribute macros are able to rewrite items entirely or in other unexpected ways which can cause confusion and introduce errors.
237+
238+
.. non_compliant_example::
239+
:id: non_compl_ex_eW374waRPbeL
240+
:status: draft
241+
242+
Explanation of code example.
243+
244+
.. code-block:: rust
245+
246+
#[tokio::main] // non-compliant
247+
async fn main() {
248+
249+
}
250+
251+
.. compliant_example::
252+
:id: compl_ex_Mg8ePOgbGJeW
253+
:status: draft
254+
255+
Explanation of code example.
256+
257+
.. code-block:: rust
258+
259+
fn example_function() {
260+
// Compliant implementation
261+
}
262+

0 commit comments

Comments
 (0)