Macros

Guideline: Shall not use Declarative Macros gui_h0uG1C9ZjryA
status: draft
tags: reduce-human-error
category: mandatory
decidability: decidable
scope: system
release: todo

Description of the guideline goes here.

Rationale: rat_U3AEUPyaUhcb
status: draft
parent needs: gui_h0uG1C9ZjryA

Explanation of why this guideline is important.

Non-Compliant Example: non_compl_ex_Gb4zimei8cNI
status: draft
parent needs: gui_h0uG1C9ZjryA

Explanation of code example.

fn example_function() {
    // Non-compliant implementation
}
Compliant Example: compl_ex_Pw7YCh4Iv47Z
status: draft
parent needs: gui_h0uG1C9ZjryA

Explanation of code example

fn example_function() {
    // Compliant implementation
}
Guideline: Procedural macros should not be used gui_66FSqzD55VRZ
status: draft
tags: readability, reduce-human-error
category: advisory
decidability: decidable
scope: crate
release: 1.85.0;1.85.1

Macros should be expressed using declarative syntax in preference to procedural syntax.

Rationale: rat_AmCavSymv3Ev
status: draft
parent needs: gui_66FSqzD55VRZ

Procedural macros are not restricted to pure transcription and can contain arbitrary Rust code. This means they can be harder to understand, and cannot be as easily proved to work as intended. Procedural macros can have arbitrary side effects, which can exhaust compiler resources or expose a vulnerability for users of adopted code.

Non-Compliant Example: non_compl_ex_pJhVZW6a1HP9
status: draft
parent needs: gui_66FSqzD55VRZ

(example of a simple expansion using a proc-macro)

// TODO
Compliant Example: compl_ex_4VFyucETB7C3
status: draft
parent needs: gui_66FSqzD55VRZ

(example of the same simple expansion using a declarative macro)

// TODO
Guideline: Shall not use Function-like Macros gui_WJlWqgIxmE8P
status: draft
tags: reduce-human-error
category: mandatory
decidability: decidable
scope: system
release: todo

Description of the guideline goes here.

Rationale: rat_C8RRidiVzhRj
status: draft
parent needs: gui_WJlWqgIxmE8P

Explanation of why this guideline is important.

Non-Compliant Example: non_compl_ex_TjRiRkmBY6wG
status: draft
parent needs: gui_WJlWqgIxmE8P

Explanation of code example.

fn example_function() {
    // Non-compliant implementation
}
Compliant Example: compl_ex_AEKEOYhBWPMl
status: draft
parent needs: gui_WJlWqgIxmE8P

Explanation of code example.

fn example_function() {
    // Compliant implementation
}
Guideline: Shall not invoke macros gui_a1mHfjgKk4Xr
status: draft
tags: reduce-human-error
category: mandatory
decidability: decidable
scope: system
release: todo

Description of the guideline goes here.

Rationale: rat_62mSorNF05kD
status: draft
parent needs: gui_a1mHfjgKk4Xr

Explanation of why this guideline is important.

Non-Compliant Example: non_compl_ex_hP5KLhqQfDcd
status: draft
parent needs: gui_a1mHfjgKk4Xr

Explanation of code example.

fn example_function() {
    // Non-compliant implementation
}
Compliant Example: compl_ex_ti7GWHCOhUvT
status: draft
parent needs: gui_a1mHfjgKk4Xr

Explanation of code example.

fn example_function() {
    // Compliant implementation
}
Guideline: Shall not write code that expands macros gui_uuDOArzyO3Qw
status: draft
tags: reduce-human-error
category: mandatory
decidability: decidable
scope: system
release: todo

Description of the guideline goes here.

Rationale: rat_dNgSvC0SZ3JJ
status: draft
parent needs: gui_uuDOArzyO3Qw

Explanation of why this guideline is important.

Non-Compliant Example: non_compl_ex_g9j8shyGM2Rh
status: draft
parent needs: gui_uuDOArzyO3Qw

Explanation of code example.

fn example_function() {
    // Non-compliant implementation
}
Compliant Example: compl_ex_cFPg6y7upNdl
status: draft
parent needs: gui_uuDOArzyO3Qw

Explanation of code example.

fn example_function() {
    // Compliant implementation
}
Guideline: Shall ensure complete hygiene of macros gui_8hs33nyp0ipX
status: draft
tags: reduce-human-error
category: mandatory
decidability: decidable
scope: system
release: todo

Description of the guideline goes here.

Rationale: rat_e9iS187skbHH
status: draft
parent needs: gui_8hs33nyp0ipX

Explanation of why this guideline is important.

Non-Compliant Example: non_compl_ex_lRt4LBen6Lkc
status: draft
parent needs: gui_8hs33nyp0ipX

Explanation of code example.

fn example_function() {
    // Non-compliant implementation
}
Compliant Example: compl_ex_GLP05s9c1g8N
status: draft
parent needs: gui_8hs33nyp0ipX

Explanation of code example.

fn example_function() {
    // Compliant implementation
}
Guideline: Attribute macros shall not be used gui_13XWp3mb0g2P
status: draft
tags: reduce-human-error
category: required
decidability: decidable
scope: system
release: todo

Attribute macros shall neither be declared nor invoked. Prefer less powerful macros that only extend source code.

Rationale: rat_X8uCF5yx7Mpo
status: draft
parent needs: gui_13XWp3mb0g2P

Attribute macros are able to rewrite items entirely or in other unexpected ways which can cause confusion and introduce errors.

Non-Compliant Example: non_compl_ex_eW374waRPbeL
status: draft
parent needs: gui_13XWp3mb0g2P

Explanation of code example.

#[tokio::main]  // non-compliant
async fn main() {

}
Compliant Example: compl_ex_Mg8ePOgbGJeW
status: draft
parent needs: gui_13XWp3mb0g2P

Explanation of code example.

fn example_function() {
    // Compliant implementation
}