From 654dfb1e57f0914c14115b27e2bd263f3f6de956 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 23 Oct 2025 07:29:42 -0700 Subject: [PATCH 1/4] Split outer attribute definition to a dedicated rule --- src/attributes.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/attributes.md b/src/attributes.md index 26fa10cc42..61294fb206 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -24,7 +24,10 @@ on Attributes in [ECMA-335], with the syntax coming from [ECMA-334] \(C#). r[attributes.inner] _Inner attributes_, written with a bang (`!`) after the hash (`#`), apply to the -item that the attribute is declared within. _Outer attributes_, written without +item that the attribute is declared within. + +r[attributes.outer] +_Outer attributes_, written without the bang after the hash, apply to the thing that follows the attribute. r[attributes.input] From 85d7f5c2cc9419ead3df95d77427180fa52bf815 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 23 Oct 2025 07:30:00 -0700 Subject: [PATCH 2/4] Unwrap inner/outer attribute --- src/attributes.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/attributes.md b/src/attributes.md index 61294fb206..dd895d12f2 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -23,12 +23,10 @@ to name, convention, language, and compiler version. Attributes are modeled on Attributes in [ECMA-335], with the syntax coming from [ECMA-334] \(C#). r[attributes.inner] -_Inner attributes_, written with a bang (`!`) after the hash (`#`), apply to the -item that the attribute is declared within. +_Inner attributes_, written with a bang (`!`) after the hash (`#`), apply to the item that the attribute is declared within. r[attributes.outer] -_Outer attributes_, written without -the bang after the hash, apply to the thing that follows the attribute. +_Outer attributes_, written without the bang after the hash, apply to the thing that follows the attribute. r[attributes.input] The attribute consists of a path to the attribute, followed by an optional From d6b2e6e84af0a8f5bbc8897c61a2763ff19fdf38 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 23 Oct 2025 07:30:26 -0700 Subject: [PATCH 3/4] Use the terminology "form" for attribute definitions "Thing" was unsatisfying to me. "Item" was wrong for inner attributes, since it includes other things. --- src/attributes.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/attributes.md b/src/attributes.md index dd895d12f2..a445669e05 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -23,10 +23,10 @@ to name, convention, language, and compiler version. Attributes are modeled on Attributes in [ECMA-335], with the syntax coming from [ECMA-334] \(C#). r[attributes.inner] -_Inner attributes_, written with a bang (`!`) after the hash (`#`), apply to the item that the attribute is declared within. +_Inner attributes_, written with a bang (`!`) after the hash (`#`), apply to the form that the attribute is declared within. r[attributes.outer] -_Outer attributes_, written without the bang after the hash, apply to the thing that follows the attribute. +_Outer attributes_, written without the bang after the hash, apply to the form that follows the attribute. r[attributes.input] The attribute consists of a path to the attribute, followed by an optional @@ -57,7 +57,7 @@ Attributes can be classified into the following kinds: * [Tool attributes](#tool-attributes) r[attributes.allowed-position] -Attributes may be applied to many things in the language: +Attributes may be applied to many forms in the language: * All [item declarations] accept outer attributes while [external blocks], [functions], [implementations], and [modules] accept inner attributes. @@ -197,7 +197,7 @@ r[attributes.activity] r[attributes.activity.intro] An attribute is either active or inert. During attribute processing, *active -attributes* remove themselves from the thing they are on while *inert attributes* +attributes* remove themselves from the form they are on while *inert attributes* stay on. The [`cfg`] and [`cfg_attr`] attributes are active. From 8d56c5d592b431ac8cade8cd11ee848f63019025 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 23 Oct 2025 07:34:50 -0700 Subject: [PATCH 4/4] Move attribute examples to earlier in the chapter --- src/attributes.md | 66 ++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/attributes.md b/src/attributes.md index a445669e05..9fd9c3ec85 100644 --- a/src/attributes.md +++ b/src/attributes.md @@ -25,9 +25,43 @@ on Attributes in [ECMA-335], with the syntax coming from [ECMA-334] \(C#). r[attributes.inner] _Inner attributes_, written with a bang (`!`) after the hash (`#`), apply to the form that the attribute is declared within. +> [!EXAMPLE] +> ```rust +> // General metadata applied to the enclosing module or crate. +> #![crate_type = "lib"] +> +> // Inner attribute applies to the entire function. +> fn some_unused_variables() { +> #![allow(unused_variables)] +> +> let x = (); +> let y = (); +> let z = (); +> } +> ``` + r[attributes.outer] _Outer attributes_, written without the bang after the hash, apply to the form that follows the attribute. +> [!EXAMPLE] +> ```rust +> // A function marked as a unit test +> #[test] +> fn test_foo() { +> /* ... */ +> } +> +> // A conditionally-compiled module +> #[cfg(target_os = "linux")] +> mod bar { +> /* ... */ +> } +> +> // A lint attribute used to suppress a warning/error +> #[allow(non_camel_case_types)] +> type int8_t = i8; +> ``` + r[attributes.input] The attribute consists of a path to the attribute, followed by an optional delimited token tree whose interpretation is defined by the attribute. @@ -75,38 +109,6 @@ Attributes may be applied to many forms in the language: parameters accept outer attributes. This includes attributes on variadic parameters denoted with `...` in function pointers and [external blocks][variadic functions]. -Some examples of attributes: - -```rust -// General metadata applied to the enclosing module or crate. -#![crate_type = "lib"] - -// A function marked as a unit test -#[test] -fn test_foo() { - /* ... */ -} - -// A conditionally-compiled module -#[cfg(target_os = "linux")] -mod bar { - /* ... */ -} - -// A lint attribute used to suppress a warning/error -#[allow(non_camel_case_types)] -type int8_t = i8; - -// Inner attribute applies to the entire function. -fn some_unused_variables() { - #![allow(unused_variables)] - - let x = (); - let y = (); - let z = (); -} -``` - r[attributes.meta] ## Meta item attribute syntax