Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Attributes

Reading

  • What actually are attributes? - Jana Dönszelmann | EuroRust 2025 YouTube

    The part on how they changed and centralized attribute parsing is interesting.

Design

  • Which character to introduce attribute? #, @

    @ clashes with bindings in match arms.

#attr;
#attr("foo")
#attr{name = "c"}
fn item() {
#rustfmt::skip
let matrix = [
1, 2, 3,
4, 5, 6,
];

#allow(clippy::placeholder_name)
let foo = ();
}
  • Concern: Bare attributes (i.e. no [] to delimit) on expression can conflict

    #foo (1)
    #foo() 1
    
    #foo [1, 2, 3]
    #foo[] 1
    

    Currently, attributes have precedence.

    • Do we not have bare attributes? #foo is #foo()

    • Do we delimit the attribute? with ;?

      e.g. #foo; [1, 2, 3]