Skip to content

Commit 2609387

Browse files
committed
Revise naked attribute text
Let's revise the text in the `naked` attribute section with some editorial adjustments.
1 parent 864a81c commit 2609387

1 file changed

Lines changed: 24 additions & 25 deletions

File tree

src/attributes/codegen.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,16 @@ r[attributes.codegen.naked]
124124
## The `naked` attribute
125125
126126
r[attributes.codegen.naked.intro]
127-
The *`naked` [attribute]* prevents the compiler from emitting a function prologue and epilogue for the attributed function.
127+
The *`naked` [attribute]* prevents the compiler from emitting a function prologue and epilogue for the attributed function --- a *naked function*.
128128
129129
> [!EXAMPLE]
130130
> ```rust
131131
> # #[cfg(target_arch = "x86_64")] {
132132
> /// Adds 3 to the given number.
133-
> ///
134-
> /// SAFETY: The validity of the used registers
135-
> /// is guaranteed according to the "sysv64" ABI.
133+
> // SAFETY: The body respects the "sysv64" calling convention,
134+
> // upholds the signature, and does not fall through.
136135
> #[unsafe(naked)]
137-
> pub extern "sysv64" fn add_n(number: usize) -> usize {
136+
> pub extern "sysv64" fn add_n(number: u64) -> u64 {
138137
> core::arch::naked_asm!(
139138
> "add rdi, {}",
140139
> "mov rax, rdi",
@@ -149,15 +148,10 @@ r[attributes.codegen.naked.syntax]
149148
The `naked` attribute uses the [MetaWord] syntax.
150149
151150
r[attributes.codegen.naked.allowed-positions]
152-
The `naked` attribute may only be applied to:
153-
154-
- [Free functions][items.fn]
155-
- [Inherent associated functions][items.associated.fn]
156-
- [Trait impl functions][items.impl.trait]
157-
- [Trait definition functions][items.traits.associated-item-decls] with a body
151+
The `naked` attribute may only be applied to [free functions], [associated functions] in an [inherent impl] or [trait impl], and associated functions in a [trait definition] when those functions have a [default definition].
158152
159153
r[attributes.codegen.naked.duplicates]
160-
The `naked` attribute may be used any number of times on a form.
154+
Only the first use of `naked` on a function has effect.
161155
162156
> [!NOTE]
163157
> `rustc` lints against any use following the first.
@@ -169,36 +163,36 @@ r[attributes.codegen.naked.body]
169163
The [function body] must consist of exactly one [`naked_asm!`] macro invocation.
170164
171165
r[attributes.codegen.naked.prologue-epilogue]
172-
No function prologue or epilogue is generated for the attributed function. The assembly code in the `naked_asm!` block constitutes the full body of a naked function.
166+
The compiler emits no prologue or epilogue for a naked function: the assembly code in the [`naked_asm!`] invocation constitutes its entire body.
173167
174168
r[attributes.codegen.naked.call-stack]
175-
The assembly code may assume that the call stack and register state are valid on entry as per the signature and calling convention of the function.
169+
On entry the assembly code may assume that the call stack and register state are valid per the function's signature and calling convention.
176170
177171
r[attributes.codegen.naked.no-duplication]
178-
The assembly code may not be duplicated by the compiler except when monomorphizing polymorphic functions.
172+
The compiler may not duplicate the assembly code except when monomorphizing a polymorphic function.
179173
180174
> [!NOTE]
181-
> Guaranteeing when the assembly code may or may not be duplicated is important for naked functions that define symbols.
175+
> This guarantee matters for naked functions that define symbols.
182176
183177
r[attributes.codegen.naked.unused-variables]
184-
The [`unused_variables`] lint is suppressed within naked functions.
178+
The [`unused_variables` lint] is suppressed in naked functions.
185179
186180
r[attributes.codegen.naked.inline]
187-
The [`inline`](#the-inline-attribute) attribute cannot by applied to a naked function.
181+
The [`inline` attribute] cannot be applied to a naked function.
188182
189183
r[attributes.codegen.naked.track_caller]
190-
The [`track_caller`](#the-track_caller-attribute) attribute cannot be applied to a naked function.
184+
The [`track_caller` attribute] cannot be applied to a naked function.
191185
192186
r[attributes.codegen.naked.testing]
193-
The [testing attributes](testing.md) cannot be applied to a naked function.
187+
The [testing attributes] cannot be applied to a naked function.
194188
195189
r[attributes.codegen.naked.target_feature]
196-
The [`target_feature`][attributes.codegen.target_feature] attribute cannot be applied to a naked function.
190+
The [`target_feature` attribute] cannot be applied to a naked function.
197191
198192
<!-- TODO: Reflexive rules? -->
199193
200194
r[attributes.codegen.naked.abi]
201-
The function cannot have the ["Rust" ABI][items.extern.abi.rust].
195+
A naked function cannot use the ["Rust" ABI].
202196
203197
<!-- template:attributes -->
204198
r[attributes.codegen.no_builtins]
@@ -896,13 +890,16 @@ If the address of the function is taken as a function pointer, the low bit of th
896890
[`-C target-cpu`]: ../../rustc/codegen-options/index.html#target-cpu
897891
[`-C target-feature`]: ../../rustc/codegen-options/index.html#target-feature
898892
[`export_name`]: abi.export_name
893+
[`inline` attribute]: attributes.codegen.inline
899894
[`is_aarch64_feature_detected`]: ../../std/arch/macro.is_aarch64_feature_detected.html
900895
[`is_x86_feature_detected`]: ../../std/arch/macro.is_x86_feature_detected.html
901896
[`Location`]: core::panic::Location
902-
[`naked_asm!`]: ../inline-assembly.md
897+
[`naked_asm!`]: asm
903898
[`no_mangle`]: abi.no_mangle
899+
[`target_feature` attribute]: attributes.codegen.target_feature
904900
[`target_feature` conditional compilation option]: ../conditional-compilation.md#target_feature
905-
[`unused_variables`]: ../../rustc/lints/listing/warn-by-default.html#unused-variables
901+
[`track_caller` attribute]: attributes.codegen.track_caller
902+
[`unused_variables` lint]: ../../rustc/lints/listing/warn-by-default.html#unused-variables
906903
[associated functions]: items.associated.fn
907904
[async blocks]: expr.block.async
908905
[async closure]: expr.closure.async
@@ -913,11 +910,13 @@ If the address of the function is taken as a function pointer, the low bit of th
913910
[closures]: expr.closure
914911
[default definition]: items.traits.associated-item-decls
915912
[free functions]: items.fn
916-
[function body]: ../items/functions.md#function-body
913+
[function body]: items.fn.body
917914
[functions]: ../items/functions.md
918915
[inherent impl]: items.impl.inherent
916+
["Rust" ABI]: items.extern.abi.rust
919917
[rust-abi]: ../items/external-blocks.md#abi
920918
[target architecture]: ../conditional-compilation.md#target_arch
919+
[testing attributes]: attributes.testing
921920
[trait]: items.traits
922921
[trait definition]: items.traits
923922
[trait impl]: items.impl.trait

0 commit comments

Comments
 (0)