## Motivation The `#[instrument]` macro cannot be used on `const fn`s, because the generated code will perform runtime tracing behavior. However, when adding the attribute to a `const fn`, the compiler errors generated currently are somewhat unclear (see #2414). It would be better if we generated a less verbose error that simply states that `#[instrument]` is not supported on `const fn`s. ## Solution This branch changes the `#[instrument]` macro to detect when the annotated function is a `const fn`, and emit a simpler, more descritpive error message. The new error simply states that the `#[instrument]` attribute cannot be used on `const fn`s, and should be much less confusing to the user. Fixes #2414
15 lines
643 B
Text
15 lines
643 B
Text
error: macros that expand to items must be delimited with braces or followed by a semicolon
|
|
--> tests/ui/const_instrument.rs:3:1
|
|
|
|
|
3 | #[tracing::instrument]
|
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: this error originates in the attribute macro `tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
|
|
error: the `#[instrument]` attribute may not be used with `const fn`s
|
|
--> tests/ui/const_instrument.rs:3:1
|
|
|
|
|
3 | #[tracing::instrument]
|
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
= note: this error originates in the attribute macro `tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info)
|