tracing/tracing-attributes/tests/ui/const_instrument.rs
Andrew Pollack 58accc6da3
attributes: add compile error on const fn instrumentation (#2418)
## 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
2022-12-31 19:59:44 +00:00

8 lines
93 B
Rust

#![allow(unreachable_code)]
#[tracing::instrument]
const fn unit() {
""
}
fn main() {}