## 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
8 lines
93 B
Rust
8 lines
93 B
Rust
#![allow(unreachable_code)]
|
|
|
|
#[tracing::instrument]
|
|
const fn unit() {
|
|
""
|
|
}
|
|
|
|
fn main() {}
|