File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,7 @@ The following is an index of all built-in attributes.
219
219
- [ ` cold ` ] — Hint that a function is unlikely to be called.
220
220
- [ ` no_builtins ` ] — Disables use of certain built-in functions.
221
221
- [ ` target_feature ` ] — Configure platform-specific code generation.
222
+ - [ ` track_caller ` ] - Pass the parent call location to ` std::panic::Location::caller() ` .
222
223
- Documentation
223
224
- ` doc ` — Specifies documentation. See [ The Rustdoc Book] for more
224
225
information. [ Doc comments] are transformed into ` doc ` attributes.
@@ -291,6 +292,7 @@ The following is an index of all built-in attributes.
291
292
[ `should_panic` ] : attributes/testing.md#the-should_panic-attribute
292
293
[ `target_feature` ] : attributes/codegen.md#the-target_feature-attribute
293
294
[ `test` ] : attributes/testing.md#the-test-attribute
295
+ [ `track_caller` ] : attributes/codegen.md#the-track_caller-attribute
294
296
[ `type_length_limit` ] : attributes/limits.md#the-type_length_limit-attribute
295
297
[ `used` ] : abi.md#the-used-attribute
296
298
[ `warn` ] : attributes/diagnostics.md#lint-check-attributes
Original file line number Diff line number Diff line change @@ -140,6 +140,25 @@ feature detection on the x86 platforms.
140
140
> may be enabled or disabled for an entire crate with the
141
141
> [ ` -C target-feature ` ] flag.
142
142
143
+ ## The ` track_caller ` attribute
144
+
145
+ The ` track_caller ` attribute applies to function declarations and indicates to the compiler that the
146
+ attributed function's generated code should have an implicit ` &'static core::panic::Location `
147
+ argument which is populated by its caller. If the caller of the attributed function is also
148
+ annotated with ` #[track_caller] ` , then the attributed function should receive the location
149
+ its caller received, and so on.
150
+
151
+ An implementation of ` core::intrinsics::caller_location ` returns this implicit argument if called
152
+ from a function with the attribute. Otherwise it returns the location at which the intrinsic itself
153
+ was called.
154
+
155
+ Creating a function pointer to a function with ` #[track_caller] ` creates a shim which passes the
156
+ location at which the attributed function is defined. The pointer then refers to this shim,
157
+ preventing unsoundness or the implicit ABI from leaking into the function pointer's type.
158
+
159
+ In a const context, the attribute does not affect function ABI and instead informs the const
160
+ evaluator to continue walking up the stack when probing for the topmost caller location.
161
+
143
162
[ _MetaListNameValueStr_ ] : ../attributes.md#meta-item-attribute-syntax
144
163
[ `-C target-cpu` ] : ../../rustc/codegen-options/index.html#target-cpu
145
164
[ `-C target-feature` ] : ../../rustc/codegen-options/index.html#target-feature
You can’t perform that action at this time.
0 commit comments