mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 15:24:47 +00:00

## 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
369 B
Rust
15 lines
369 B
Rust
// Only test on nightly, since UI tests are bound to change over time
|
|
#[rustversion::stable]
|
|
#[test]
|
|
fn async_instrument() {
|
|
let t = trybuild::TestCases::new();
|
|
t.compile_fail("tests/ui/async_instrument.rs");
|
|
}
|
|
|
|
#[rustversion::stable]
|
|
#[test]
|
|
fn const_instrument() {
|
|
let t = trybuild::TestCases::new();
|
|
t.compile_fail("tests/ui/const_instrument.rs");
|
|
}
|