Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tracing-attributes/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) fn gen_function<'a, B: ToTokens + 'a>(
let block = quote! {
{
#fake_return_edge
#block
{ #block }
}
};

Expand Down
11 changes: 6 additions & 5 deletions tracing-attributes/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Only test on nightly, since UI tests are bound to change over time
// Only test on stable, since UI tests are bound to change over time

#[rustversion::stable]
#[test]
fn async_instrument() {
fn pass() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/async_instrument.rs");
t.pass("tests/ui/pass/*.rs");
}

#[rustversion::stable]
#[test]
fn const_instrument() {
fn compile_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/const_instrument.rs");
t.compile_fail("tests/ui/fail/*.rs");
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:5:5
--> tests/ui/fail/async_instrument.rs:5:5
|
5 | ""
| ^^ expected `()`, found `&str`
|
note: return type inferred to be `()` here
--> tests/ui/async_instrument.rs:4:10
--> tests/ui/fail/async_instrument.rs:4:10
|
4 | async fn unit() {
| ^^^^

error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:10:5
--> tests/ui/fail/async_instrument.rs:10:5
|
10 | ""
| ^^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found `&str`
|
note: return type inferred to be `String` here
--> tests/ui/async_instrument.rs:9:31
--> tests/ui/fail/async_instrument.rs:9:31
|
9 | async fn simple_mismatch() -> String {
| ^^^^^^

error[E0277]: `(&str,)` doesn't implement `std::fmt::Display`
--> tests/ui/async_instrument.rs:14:57
--> tests/ui/fail/async_instrument.rs:14:57
|
14 | async fn opaque_unsatisfied() -> impl std::fmt::Display {
| _________________________________________________________-
Expand All @@ -40,7 +40,7 @@ error[E0277]: `(&str,)` doesn't implement `std::fmt::Display`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error[E0277]: `(&str,)` doesn't implement `std::fmt::Display`
--> tests/ui/async_instrument.rs:14:34
--> tests/ui/fail/async_instrument.rs:14:34
|
14 | async fn opaque_unsatisfied() -> impl std::fmt::Display {
| ^^^^^^^^^^^^^^^^^^^^^^ `(&str,)` cannot be formatted with the default formatter
Expand All @@ -49,15 +49,15 @@ error[E0277]: `(&str,)` doesn't implement `std::fmt::Display`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:22:5
--> tests/ui/fail/async_instrument.rs:22:5
|
22 | ""
| ^^ expected `Wrapper<_>`, found `&str`
|
= note: expected struct `Wrapper<_>`
found reference `&'static str`
note: return type inferred to be `Wrapper<_>` here
--> tests/ui/async_instrument.rs:21:36
--> tests/ui/fail/async_instrument.rs:21:36
|
21 | async fn mismatch_with_opaque() -> Wrapper<impl std::fmt::Display> {
| ^^^^^^^
Expand All @@ -67,33 +67,33 @@ help: try wrapping the expression in `Wrapper`
| ++++++++ +

error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:28:16
--> tests/ui/fail/async_instrument.rs:28:16
|
28 | return "";
| ^^ expected `()`, found `&str`
|
note: return type inferred to be `()` here
--> tests/ui/async_instrument.rs:26:10
--> tests/ui/fail/async_instrument.rs:26:10
|
26 | async fn early_return_unit() {
| ^^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:35:16
--> tests/ui/fail/async_instrument.rs:35:16
|
35 | return "";
| ^^- help: try using a conversion method: `.to_string()`
| |
| expected `String`, found `&str`
|
note: return type inferred to be `String` here
--> tests/ui/async_instrument.rs:33:28
--> tests/ui/fail/async_instrument.rs:33:28
|
33 | async fn early_return() -> String {
| ^^^^^^

error[E0308]: mismatched types
--> tests/ui/async_instrument.rs:40:1
--> tests/ui/fail/async_instrument.rs:40:1
|
40 | #[tracing::instrument]
| ^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `()`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: macros that expand to items must be delimited with braces or followed by a semicolon
--> tests/ui/const_instrument.rs:3:1
--> tests/ui/fail/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
--> tests/ui/fail/const_instrument.rs:3:1
|
3 | #[tracing::instrument]
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down
6 changes: 6 additions & 0 deletions tracing-attributes/tests/ui/fail/unused_instrumented_fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![deny(dead_code)]

#[tracing::instrument]
fn never_used() {}

fn main() {}
11 changes: 11 additions & 0 deletions tracing-attributes/tests/ui/fail/unused_instrumented_fn.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: function `never_used` is never used
--> tests/ui/fail/unused_instrumented_fn.rs:4:4
|
4 | fn never_used() {}
| ^^^^^^^^^^
|
note: the lint level is defined here
--> tests/ui/fail/unused_instrumented_fn.rs:1:9
|
1 | #![deny(dead_code)]
| ^^^^^^^^^
17 changes: 17 additions & 0 deletions tracing-attributes/tests/ui/pass/type_shadowing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! This program is a regression test for [#3306], where shadowing
//! caused compilation failure in certain cases due to the original
//! function body not getting its own scope.
//!
//! [#3306]: https://github.com/tokio-rs/tracing/issues/3306
type Foo = ();
enum Bar {
Foo,
}

#[tracing::instrument]
fn this_is_fine() -> Foo {
// glob import imports Bar::Foo, shadowing Foo
use Bar::*;
}

fn main() {}