From 006da2a3011a482c5d2dba8b06a7507b276410ce Mon Sep 17 00:00:00 2001 From: tangtingting Date: Tue, 24 Jun 2025 12:20:59 +0800 Subject: [PATCH] New upstream version 0.1.30 --- .cargo_vcs_info.json | 2 +- CHANGELOG.md | 49 ++ Cargo.lock | 601 ++++++++++++++++++++ Cargo.toml | 84 ++- Cargo.toml.orig | 31 +- README.md | 16 +- src/attr.rs | 53 +- src/expand.rs | 83 ++- src/lib.rs | 28 +- tests/async_fn.rs | 29 +- tests/dead_code.rs | 10 + tests/destructuring.rs | 12 +- tests/err.rs | 4 +- tests/fields.rs | 31 +- tests/follows_from.rs | 3 +- tests/instrument.rs | 122 +++- tests/parents.rs | 25 +- tests/ret.rs | 3 +- tests/ui.rs | 11 +- tests/ui/{ => fail}/async_instrument.rs | 1 - tests/ui/{ => fail}/async_instrument.stderr | 68 ++- tests/ui/{ => fail}/const_instrument.rs | 0 tests/ui/{ => fail}/const_instrument.stderr | 4 +- tests/ui/fail/unused_instrumented_fn.rs | 6 + tests/ui/fail/unused_instrumented_fn.stderr | 11 + tests/ui/pass/type_shadowing.rs | 17 + 26 files changed, 1126 insertions(+), 178 deletions(-) create mode 100644 Cargo.lock create mode 100644 tests/dead_code.rs rename tests/ui/{ => fail}/async_instrument.rs (94%) rename tests/ui/{ => fail}/async_instrument.stderr (60%) rename tests/ui/{ => fail}/const_instrument.rs (100%) rename tests/ui/{ => fail}/const_instrument.stderr (86%) create mode 100644 tests/ui/fail/unused_instrumented_fn.rs create mode 100644 tests/ui/fail/unused_instrumented_fn.stderr create mode 100644 tests/ui/pass/type_shadowing.rs diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index ae421af..355a2c2 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "2502f19d934b092fc01bb7493eacbb16b4038bf3" + "sha1": "e63ef57f3d686abe3727ddd586eb9af73d6715b7" }, "path_in_vcs": "tracing-attributes" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cb95f7..ca9c881 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,52 @@ +# 0.1.30 (June 17, 2025) + +### Fixed + +- Fix `tracing::instrument` regression around shadowing ([#3311]) + +[#3311]: https://github.com/tokio-rs/tracing/pull/3311 + +# 0.1.29 (June 6, 2025) + +### Changed + +- Bump MSRV to 1.65 ([#3033]) + +### Fixed + +- Let `dead_code` lint work on `#[instrument]`ed functions ([#3108]) +- Globally qualify attribute paths ([#3126]) + +[#3033]: https://github.com/tokio-rs/tracing/pull/3033 +[#3108]: https://github.com/tokio-rs/tracing/pull/3108 +[#3126]: https://github.com/tokio-rs/tracing/pull/3126 + +# 0.1.28 (November 26, 2024) + +### Changed + +- Bump MSRV to 1.63 ([#2793]) + +### Fixed + +- Added missing RecordTypes for instrument ([#2781]) +- Change order of async and unsafe modifier ([#2864]) +- Extract match scrutinee ([#2880]) +- Allow field path segments to be keywords ([#2925]) +- Support const values for `target` and `name` ([#2941]) + +### Documented + +- Fix backporting error in attributes ([#2780]) + +[#2780]: https://github.com/tokio-rs/tracing/pull/2780 +[#2781]: https://github.com/tokio-rs/tracing/pull/2781 +[#2793]: https://github.com/tokio-rs/tracing/pull/2793 +[#2864]: https://github.com/tokio-rs/tracing/pull/2864 +[#2880]: https://github.com/tokio-rs/tracing/pull/2880 +[#2925]: https://github.com/tokio-rs/tracing/pull/2925 +[#2941]: https://github.com/tokio-rs/tracing/pull/2941 + # 0.1.27 (October 13, 2023) ### Changed diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..821b4d7 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,601 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "async-stream" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dad5c83079eae9969be7fadefe640a1c566901f05ff91ab221de4b6f68d9507e" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f203db73a71dfa2fb6dd22763990fa26f3d2625a6da2da900d23b87d26be27" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.103", +] + +[[package]] +name = "async-trait" +version = "0.1.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b2d0f03b3640e3a630367e40c468cb7f309529c708ed1d88597047b0e7c6ef7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "basic-toml" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f2139706359229bfa8f19142ac1155b4b80beafb7a60471ac5dd109d4a19778" +dependencies = [ + "serde", +] + +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + +[[package]] +name = "cc" +version = "1.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "futures-core" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" + +[[package]] +name = "gimli" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.172" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustversion" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "serde_json" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tokio" +version = "1.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" +dependencies = [ + "autocfg", + "backtrace", + "pin-project-lite", +] + +[[package]] +name = "tokio-stream" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tokio-test" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53474327ae5e166530d17f2d956afcb4f8a004de581b3cae10f12006bc8163e3" +dependencies = [ + "async-stream", + "bytes", + "futures-core", + "tokio", + "tokio-stream", +] + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes 0.1.29", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1ffbcf9c6f6b99d386e7444eb608ba646ae452a36b39737deb9663b610f662" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.30" +dependencies = [ + "async-trait", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.101", + "tokio-test", + "tracing", + "tracing-subscriber", + "trybuild", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "trybuild" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8419ecd263363827c5730386f418715766f584e2f874d32c23c5b00bd9727e7e" +dependencies = [ + "basic-toml", + "glob", + "once_cell", + "serde", + "serde_derive", + "serde_json", + "termcolor", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 8d90671..36f3971 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,14 +11,20 @@ [package] edition = "2018" -rust-version = "1.56.0" +rust-version = "1.65.0" name = "tracing-attributes" -version = "0.1.27" +version = "0.1.30" authors = [ "Tokio Contributors ", "Eliza Weisman ", "David Barsky ", ] +build = false +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false description = """ Procedural macro attributes for automatically instrumenting functions. """ @@ -38,10 +44,71 @@ categories = [ ] license = "MIT" repository = "https://github.com/tokio-rs/tracing" +resolver = "2" + +[badges.maintenance] +status = "experimental" + +[features] +async-await = [] [lib] +name = "tracing_attributes" +path = "src/lib.rs" proc-macro = true +[[test]] +name = "async_fn" +path = "tests/async_fn.rs" + +[[test]] +name = "dead_code" +path = "tests/dead_code.rs" + +[[test]] +name = "destructuring" +path = "tests/destructuring.rs" + +[[test]] +name = "err" +path = "tests/err.rs" + +[[test]] +name = "fields" +path = "tests/fields.rs" + +[[test]] +name = "follows_from" +path = "tests/follows_from.rs" + +[[test]] +name = "instrument" +path = "tests/instrument.rs" + +[[test]] +name = "levels" +path = "tests/levels.rs" + +[[test]] +name = "names" +path = "tests/names.rs" + +[[test]] +name = "parents" +path = "tests/parents.rs" + +[[test]] +name = "ret" +path = "tests/ret.rs" + +[[test]] +name = "targets" +path = "tests/targets.rs" + +[[test]] +name = "ui" +path = "tests/ui.rs" + [dependencies.proc-macro2] version = "1.0.60" @@ -80,8 +147,11 @@ features = ["env-filter"] [dev-dependencies.trybuild] version = "1.0.64" -[features] -async-await = [] - -[badges.maintenance] -status = "experimental" +[lints.rust.unexpected_cfgs] +level = "warn" +priority = 0 +check-cfg = [ + "cfg(flaky_tests)", + "cfg(tracing_unstable)", + "cfg(unsound_local_offset)", +] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 5bac47a..58b3123 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -2,13 +2,10 @@ name = "tracing-attributes" # When releasing to crates.io: # - Remove path dependencies -# - Update html_root_url. -# - Update doc url -# - Cargo.toml -# - README.md +# - Update doc url in README.md. # - Update CHANGELOG.md. -# - Create "v0.1.x" git tag. -version = "0.1.27" +# - Create "tracing-attributes-0.1.x" git tag. +version = "0.1.30" authors = [ "Tokio Contributors ", "Eliza Weisman ", @@ -28,7 +25,7 @@ keywords = ["logging", "tracing", "macro", "instrument", "log"] license = "MIT" readme = "README.md" edition = "2018" -rust-version = "1.56.0" +rust-version = "1.65.0" [lib] proc-macro = true @@ -40,17 +37,31 @@ async-await = [] [dependencies] proc-macro2 = "1.0.60" -syn = { version = "2.0", default-features = false, features = ["full", "parsing", "printing", "visit-mut", "clone-impls", "extra-traits", "proc-macro"] } +syn = { version = "2.0", default-features = false, features = [ + "full", + "parsing", + "printing", + "visit-mut", + "clone-impls", + "extra-traits", + "proc-macro", +] } quote = "1.0.20" [dev-dependencies] tracing = { path = "../tracing", version = "0.1.35" } -tracing-mock = { path = "../tracing-mock", features = ["tokio-test"] } -tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", features = ["env-filter"] } +tracing-mock = { path = "../tracing-mock" } tokio-test = "0.4.2" +tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", features = [ + "env-filter", +] } +tracing-test = { path = "../tracing-test" } async-trait = "0.1.67" trybuild = "1.0.64" rustversion = "1.0.9" [badges] maintenance = { status = "experimental" } + +[lints] +workspace = true diff --git a/README.md b/README.md index f14dbb6..048d5f2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Tracing — Structured, application-level diagnostics][splash] -[splash]: https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/splash.svg +[splash]: https://raw.githubusercontent.com/tokio-rs/tracing/main/assets/splash.svg # tracing-attributes @@ -8,7 +8,7 @@ Macro attributes for application-level tracing. [![Crates.io][crates-badge]][crates-url] [![Documentation][docs-badge]][docs-url] -[![Documentation (master)][docs-master-badge]][docs-master-url] +[![Documentation (v0.2.x)][docs-v0.2.x-badge]][docs-v0.2.x-url] [![MIT licensed][mit-badge]][mit-url] [![Build Status][actions-badge]][actions-url] [![Discord chat][discord-badge]][discord-url] @@ -18,9 +18,9 @@ Macro attributes for application-level tracing. [crates-badge]: https://img.shields.io/crates/v/tracing-attributes.svg [crates-url]: https://crates.io/crates/tracing-attributes [docs-badge]: https://docs.rs/tracing-attributes/badge.svg -[docs-url]: https://docs.rs/tracing-attributes/0.1.26 -[docs-master-badge]: https://img.shields.io/badge/docs-master-blue -[docs-master-url]: https://tracing-rs.netlify.com/tracing_attributes +[docs-url]: https://docs.rs/tracing-attributes/0.1.30 +[docs-v0.2.x-badge]: https://img.shields.io/badge/docs-v0.2.x-blue +[docs-v0.2.x-url]: https://tracing.rs/tracing_attributes [mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg [mit-url]: LICENSE [actions-badge]: https://github.com/tokio-rs/tracing/workflows/CI/badge.svg @@ -37,7 +37,7 @@ structured, event-based diagnostic information. This crate provides the Note that this macro is also re-exported by the main `tracing` crate. -*Compiler support: [requires `rustc` 1.56+][msrv]* +*Compiler support: [requires `rustc` 1.65+][msrv]* [msrv]: #supported-rust-versions @@ -47,7 +47,7 @@ First, add this to your `Cargo.toml`: ```toml [dependencies] -tracing-attributes = "0.1.26" +tracing-attributes = "0.1.30" ``` @@ -69,7 +69,7 @@ pub fn my_function(my_arg: usize) { ## Supported Rust Versions Tracing is built against the latest stable release. The minimum supported -version is 1.56. The current Tracing version is not guaranteed to build on Rust +version is 1.65. The current Tracing version is not guaranteed to build on Rust versions earlier than the minimum supported version. Tracing follows the same compiler support policies as the rest of the Tokio diff --git a/src/attr.rs b/src/attr.rs index f5ad409..f3d9141 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -17,8 +17,8 @@ pub(crate) struct EventArgs { #[derive(Clone, Default, Debug)] pub(crate) struct InstrumentArgs { level: Option, - pub(crate) name: Option, - target: Option, + pub(crate) name: Option, + target: Option, pub(crate) parent: Option, pub(crate) follows_from: Option, pub(crate) skips: HashSet, @@ -87,6 +87,8 @@ impl Parse for InstrumentArgs { // XXX: apparently we support names as either named args with an // sign, _or_ as unnamed string literals. That's weird, but // changing it is apparently breaking. + // This also means that when using idents for name, it must be via + // a named arg, i.e. `#[instrument(name = SOME_IDENT)]`. if args.name.is_some() { return Err(input.error("expected only a single `name` argument")); } @@ -211,8 +213,32 @@ impl Parse for EventArgs { } } +#[derive(Debug, Clone)] +pub(super) enum LitStrOrIdent { + LitStr(LitStr), + Ident(Ident), +} + +impl ToTokens for LitStrOrIdent { + fn to_tokens(&self, tokens: &mut TokenStream) { + match self { + LitStrOrIdent::LitStr(target) => target.to_tokens(tokens), + LitStrOrIdent::Ident(ident) => ident.to_tokens(tokens), + } + } +} + +impl Parse for LitStrOrIdent { + fn parse(input: ParseStream<'_>) -> syn::Result { + input + .parse::() + .map(LitStrOrIdent::LitStr) + .or_else(|_| input.parse::().map(LitStrOrIdent::Ident)) + } +} + struct StrArg { - value: LitStr, + value: LitStrOrIdent, _p: std::marker::PhantomData, } @@ -268,19 +294,14 @@ impl Parse for Skips { } } -#[derive(Clone, Debug, Hash, PartialEq, Eq)] +#[derive(Clone, Debug, Hash, PartialEq, Eq, Default)] pub(crate) enum FormatMode { + #[default] Default, Display, Debug, } -impl Default for FormatMode { - fn default() -> Self { - FormatMode::Default - } -} - #[derive(Clone, Debug)] pub(crate) struct Fields(pub(crate) Punctuated); @@ -357,7 +378,7 @@ impl ToTokens for Field { // `instrument` produce empty field values, so changing it now // is a breaking change. agh. let name = &self.name; - tokens.extend(quote!(#name = tracing::field::Empty)) + tokens.extend(quote!(#name = ::tracing::field::Empty)) } else { self.kind.to_tokens(tokens); self.name.to_tokens(tokens); @@ -433,11 +454,11 @@ impl Parse for Level { impl ToTokens for Level { fn to_tokens(&self, tokens: &mut TokenStream) { match self { - Level::Trace => tokens.extend(quote!(tracing::Level::TRACE)), - Level::Debug => tokens.extend(quote!(tracing::Level::DEBUG)), - Level::Info => tokens.extend(quote!(tracing::Level::INFO)), - Level::Warn => tokens.extend(quote!(tracing::Level::WARN)), - Level::Error => tokens.extend(quote!(tracing::Level::ERROR)), + Level::Trace => tokens.extend(quote!(::tracing::Level::TRACE)), + Level::Debug => tokens.extend(quote!(::tracing::Level::DEBUG)), + Level::Info => tokens.extend(quote!(::tracing::Level::INFO)), + Level::Warn => tokens.extend(quote!(::tracing::Level::WARN)), + Level::Error => tokens.extend(quote!(::tracing::Level::ERROR)), Level::Path(ref pat) => tokens.extend(quote!(#pat)), } } diff --git a/src/expand.rs b/src/expand.rs index a7123e5..eb3ea5c 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -1,6 +1,7 @@ use std::iter; use proc_macro2::TokenStream; +use quote::TokenStreamExt; use quote::{quote, quote_spanned, ToTokens}; use syn::visit_mut::VisitMut; use syn::{ @@ -29,6 +30,7 @@ pub(crate) fn gen_function<'a, B: ToTokens + 'a>( inner_attrs, vis, sig, + brace_token, block, } = input; @@ -44,9 +46,12 @@ pub(crate) fn gen_function<'a, B: ToTokens + 'a>( syn::Generics { params: gen_params, where_clause, - .. + lt_token, + gt_token, }, - .. + fn_token, + paren_token, + variadic, } = sig; let warnings = args.warnings(); @@ -65,9 +70,14 @@ pub(crate) fn gen_function<'a, B: ToTokens + 'a>( // exactly that way for it to do its magic. let fake_return_edge = quote_spanned! {return_span=> #[allow( - unknown_lints, unreachable_code, clippy::diverging_sub_expression, - clippy::let_unit_value, clippy::unreachable, clippy::let_with_type_underscore, - clippy::empty_loop + unknown_lints, + unreachable_code, + clippy::diverging_sub_expression, + clippy::empty_loop, + clippy::let_unit_value, + clippy::let_with_type_underscore, + clippy::needless_return, + clippy::unreachable )] if false { let __tracing_attr_fake_return: #return_type = loop {}; @@ -77,7 +87,7 @@ pub(crate) fn gen_function<'a, B: ToTokens + 'a>( let block = quote! { { #fake_return_edge - #block + { #block } } }; @@ -90,16 +100,27 @@ pub(crate) fn gen_function<'a, B: ToTokens + 'a>( self_type, ); - quote!( + let mut result = quote!( #(#outer_attrs) * - #vis #constness #unsafety #asyncness #abi fn #ident<#gen_params>(#params) #output - #where_clause - { - #(#inner_attrs) * - #warnings - #body - } - ) + #vis #constness #asyncness #unsafety #abi #fn_token #ident + #lt_token #gen_params #gt_token + ); + + paren_token.surround(&mut result, |tokens| { + params.to_tokens(tokens); + variadic.to_tokens(tokens); + }); + + output.to_tokens(&mut result); + where_clause.to_tokens(&mut result); + + brace_token.surround(&mut result, |tokens| { + tokens.append_all(inner_attrs); + warnings.to_tokens(tokens); + body.to_tokens(tokens); + }); + + result } /// Instrument a block @@ -199,7 +220,7 @@ fn gen_block( }) .map(|(user_name, (real_name, record_type))| match record_type { RecordType::Value => quote!(#user_name = #real_name), - RecordType::Debug => quote!(#user_name = tracing::field::debug(&#real_name)), + RecordType::Debug => quote!(#user_name = ::tracing::field::debug(&#real_name)), }) .collect(); @@ -223,7 +244,7 @@ fn gen_block( let custom_fields = &args.fields; - quote!(tracing::span!( + quote!(::tracing::span!( target: #target, #(parent: #parent,)* #level, @@ -241,10 +262,10 @@ fn gen_block( let level_tokens = event_args.level(Level::Error); match event_args.mode { FormatMode::Default | FormatMode::Display => Some(quote!( - tracing::event!(target: #target, #level_tokens, error = %e) + ::tracing::event!(target: #target, #level_tokens, error = %e) )), FormatMode::Debug => Some(quote!( - tracing::event!(target: #target, #level_tokens, error = ?e) + ::tracing::event!(target: #target, #level_tokens, error = ?e) )), } } @@ -256,10 +277,10 @@ fn gen_block( let level_tokens = event_args.level(args_level); match event_args.mode { FormatMode::Display => Some(quote!( - tracing::event!(target: #target, #level_tokens, return = %x) + ::tracing::event!(target: #target, #level_tokens, return = %x) )), FormatMode::Default | FormatMode::Debug => Some(quote!( - tracing::event!(target: #target, #level_tokens, return = ?x) + ::tracing::event!(target: #target, #level_tokens, return = ?x) )), } } @@ -277,7 +298,8 @@ fn gen_block( let mk_fut = match (err_event, ret_event) { (Some(err_event), Some(ret_event)) => quote_spanned!(block.span()=> async move { - match async move #block.await { + let __match_scrutinee = async move #block.await; + match __match_scrutinee { #[allow(clippy::unit_arg)] Ok(x) => { #ret_event; @@ -319,7 +341,7 @@ fn gen_block( let __tracing_instrument_future = #mk_fut; if !__tracing_attr_span.is_disabled() { #follows_from - tracing::Instrument::instrument( + ::tracing::Instrument::instrument( __tracing_instrument_future, __tracing_attr_span ) @@ -343,7 +365,7 @@ fn gen_block( // regression in case the level is enabled. let __tracing_attr_span; let __tracing_attr_guard; - if tracing::level_enabled!(#level) || tracing::if_log_enabled!(#level, {true} else {false}) { + if ::tracing::level_enabled!(#level) || ::tracing::if_log_enabled!(#level, {true} else {false}) { __tracing_attr_span = #span; #follows_from __tracing_attr_guard = __tracing_attr_span.enter(); @@ -422,10 +444,13 @@ impl RecordType { "i32", "u64", "i64", + "u128", + "i128", "f32", "f64", "usize", "isize", + "String", "NonZeroU8", "NonZeroI8", "NonZeroU16", @@ -434,6 +459,8 @@ impl RecordType { "NonZeroI32", "NonZeroU64", "NonZeroI64", + "NonZeroU128", + "NonZeroI128", "NonZeroUsize", "NonZeroIsize", "Wrapping", @@ -447,7 +474,7 @@ impl RecordType { if path .segments .iter() - .last() + .next_back() .map(|path_segment| { let ident = path_segment.ident.to_string(); Self::TYPES_FOR_VALUE.iter().any(|&t| t == ident) @@ -718,7 +745,7 @@ impl<'block> AsyncInfo<'block> { let async_attrs = &async_expr.attrs; if pinned_box { quote! { - Box::pin(#(#async_attrs) * async move { #instrumented_block }) + ::std::boxed::Box::pin(#(#async_attrs) * async move { #instrumented_block }) } } else { quote! { @@ -766,7 +793,7 @@ struct IdentAndTypesRenamer<'a> { idents: Vec<(Ident, Ident)>, } -impl<'a> VisitMut for IdentAndTypesRenamer<'a> { +impl VisitMut for IdentAndTypesRenamer<'_> { // we deliberately compare strings because we want to ignore the spans // If we apply clippy's lint, the behavior changes #[allow(clippy::cmp_owned)] @@ -795,7 +822,7 @@ struct AsyncTraitBlockReplacer<'a> { patched_block: Block, } -impl<'a> VisitMut for AsyncTraitBlockReplacer<'a> { +impl VisitMut for AsyncTraitBlockReplacer<'_> { fn visit_block_mut(&mut self, i: &mut Block) { if i == self.block { *i = self.patched_block.clone(); diff --git a/src/lib.rs b/src/lib.rs index 6a0fd54..fe5612f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ //! //! Note that this macro is also re-exported by the main `tracing` crate. //! -//! *Compiler support: [requires `rustc` 1.56+][msrv]* +//! *Compiler support: [requires `rustc` 1.65+][msrv]* //! //! [msrv]: #supported-rust-versions //! @@ -41,7 +41,7 @@ //! ## Supported Rust Versions //! //! Tracing is built against the latest stable release. The minimum supported -//! version is 1.56. The current Tracing version is not guaranteed to build on +//! version is 1.65. The current Tracing version is not guaranteed to build on //! Rust versions earlier than the minimum supported version. //! //! Tracing follows the same compiler support policies as the rest of the Tokio @@ -53,7 +53,7 @@ //! long as doing so complies with this policy. //! #![doc( - html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png", + html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/main/assets/logo-type.png", issue_tracker_base_url = "https://github.com/tokio-rs/tracing/issues/" )] #![cfg_attr(docsrs, deny(rustdoc::broken_intra_doc_links))] @@ -70,7 +70,8 @@ overflowing_literals, path_statements, patterns_in_fns_without_body, - private_in_public, + private_interfaces, + private_bounds, unconditional_recursion, unused_allocation, unused_comparisons, @@ -82,8 +83,10 @@ extern crate proc_macro; use proc_macro2::TokenStream; +use quote::TokenStreamExt; use quote::{quote, ToTokens}; use syn::parse::{Parse, ParseStream}; +use syn::token::Brace; use syn::{Attribute, ItemFn, Signature, Visibility}; mod attr; @@ -96,10 +99,10 @@ mod expand; /// By default, all arguments to the function are included as fields on the /// span. Arguments that are `tracing` [primitive types] implementing the /// [`Value` trait] will be recorded as fields of that type. Types which do -/// not implement `Value` will be recorded using [`std::fmt::Debug`]. +/// not implement `Value` will be recorded using [`fmt::Debug`]. /// /// [primitive types]: https://docs.rs/tracing/latest/tracing/field/trait.Value.html#foreign-impls -/// [`Value` trait]: https://docs.rs/tracing/latest/tracing/field/trait.Value.html. +/// [`Value` trait]: https://docs.rs/tracing/latest/tracing/field/trait.Value.html /// /// # Overriding Span Attributes /// @@ -627,6 +630,7 @@ struct MaybeItemFn { inner_attrs: Vec, vis: Visibility, sig: Signature, + brace_token: Brace, block: TokenStream, } @@ -637,6 +641,7 @@ impl MaybeItemFn { inner_attrs: &self.inner_attrs, vis: &self.vis, sig: &self.sig, + brace_token: &self.brace_token, block: &self.block, } } @@ -650,12 +655,15 @@ impl Parse for MaybeItemFn { let vis: Visibility = input.parse()?; let sig: Signature = input.parse()?; let inner_attrs = input.call(Attribute::parse_inner)?; - let block: TokenStream = input.parse()?; + let block; + let brace_token = syn::braced!(block in input); + let block: TokenStream = block.call(|buffer| buffer.parse())?; Ok(Self { outer_attrs, inner_attrs, vis, sig, + brace_token, block, }) } @@ -673,12 +681,15 @@ impl From for MaybeItemFn { let (outer_attrs, inner_attrs) = attrs .into_iter() .partition(|attr| attr.style == syn::AttrStyle::Outer); + let mut block_tokens = TokenStream::new(); + block_tokens.append_all(block.stmts); Self { outer_attrs, inner_attrs, vis, sig, - block: block.to_token_stream(), + brace_token: block.brace_token, + block: block_tokens, } } } @@ -691,5 +702,6 @@ struct MaybeItemFnRef<'a, B: ToTokens> { inner_attrs: &'a Vec, vis: &'a Visibility, sig: &'a Signature, + brace_token: &'a Brace, block: &'a B, } diff --git a/tests/async_fn.rs b/tests/async_fn.rs index 1d92734..c672ed6 100644 --- a/tests/async_fn.rs +++ b/tests/async_fn.rs @@ -1,9 +1,10 @@ -use tracing_mock::*; - use std::convert::Infallible; use std::{future::Future, pin::Pin, sync::Arc}; + use tracing::subscriber::with_default; use tracing_attributes::instrument; +use tracing_mock::{expect, subscriber}; +use tracing_test::{block_on_future, PollN}; #[instrument] async fn test_async_fn(polls: usize) -> Result<(), ()> { @@ -29,11 +30,17 @@ async fn test_ret_impl_trait_err(n: i32) -> Result, &' } #[instrument] +#[allow(dead_code)] async fn test_async_fn_empty() {} +#[instrument] +#[allow(dead_code)] +async unsafe fn test_async_unsafe_fn_empty() {} + // Reproduces a compile error when an instrumented function body contains inner // attributes (https://github.com/tokio-rs/tracing/issues/2294). #[deny(unused_variables)] +#[allow(dead_code, clippy::mixed_attributes_style)] #[instrument] async fn repro_async_2294() { #![allow(unused_variables)] @@ -46,6 +53,7 @@ async fn repro_async_2294() { // with the rustfmt-generated formatting, the lint will not be triggered! #[rustfmt::skip] #[deny(clippy::suspicious_else_formatting)] +#[allow(dead_code)] async fn repro_1613(var: bool) { println!( "{}", @@ -57,6 +65,7 @@ async fn repro_1613(var: bool) { // and https://github.com/rust-lang/rust-clippy/issues/7760 #[instrument] #[deny(clippy::suspicious_else_formatting)] +#[allow(dead_code)] async fn repro_1613_2() { // hello world // else @@ -196,8 +205,8 @@ fn async_fn_with_async_trait() { let (subscriber, handle) = subscriber::mock() .new_span( span.clone() - .with_field(expect::field("self")) - .with_field(expect::field("v")), + .with_fields(expect::field("self")) + .with_fields(expect::field("v")), ) .enter(span.clone()) .new_span(span3.clone()) @@ -207,7 +216,7 @@ fn async_fn_with_async_trait() { .enter(span3.clone()) .exit(span3.clone()) .drop_span(span3) - .new_span(span2.clone().with_field(expect::field("self"))) + .new_span(span2.clone().with_fields(expect::field("self"))) .enter(span2.clone()) .event(expect::event().with_fields(expect::field("val").with_value(&5u64))) .exit(span2.clone()) @@ -257,7 +266,7 @@ fn async_fn_with_async_trait_and_fields_expressions() { let span = expect::span().named("call"); let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("_v") .with_value(&5usize) .and(expect::field("test").with_value(&tracing::field::debug(10))) @@ -327,7 +336,7 @@ fn async_fn_with_async_trait_and_fields_expressions_with_generic_parameter() { let span4 = expect::span().named("sync_fun"); let (subscriber, handle) = subscriber::mock() /*.new_span(span.clone() - .with_field( + .with_fields( expect::field("Self").with_value(&"TestImpler"))) .enter(span.clone()) .exit(span.clone()) @@ -335,13 +344,13 @@ fn async_fn_with_async_trait_and_fields_expressions_with_generic_parameter() { .new_span( span2 .clone() - .with_field(expect::field("Self").with_value(&std::any::type_name::())), + .with_fields(expect::field("Self").with_value(&std::any::type_name::())), ) .enter(span2.clone()) .new_span( span4 .clone() - .with_field(expect::field("Self").with_value(&std::any::type_name::())), + .with_fields(expect::field("Self").with_value(&std::any::type_name::())), ) .enter(span4.clone()) .exit(span4.clone()) @@ -354,7 +363,7 @@ fn async_fn_with_async_trait_and_fields_expressions_with_generic_parameter() { .new_span( span3 .clone() - .with_field(expect::field("Self").with_value(&std::any::type_name::())), + .with_fields(expect::field("Self").with_value(&std::any::type_name::())), ) .enter(span3.clone()) .exit(span3.clone()) diff --git a/tests/dead_code.rs b/tests/dead_code.rs new file mode 100644 index 0000000..6a3e05d --- /dev/null +++ b/tests/dead_code.rs @@ -0,0 +1,10 @@ +use tracing_attributes::instrument; + +#[deny(unfulfilled_lint_expectations)] +#[expect(dead_code)] +#[instrument] +fn unused() {} + +#[expect(dead_code)] +#[instrument] +async fn unused_async() {} diff --git a/tests/destructuring.rs b/tests/destructuring.rs index cc4fecf..b0e8737 100644 --- a/tests/destructuring.rs +++ b/tests/destructuring.rs @@ -11,7 +11,7 @@ fn destructure_tuples() { let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("arg1") .with_value(&format_args!("1")) .and(expect::field("arg2").with_value(&format_args!("2"))) @@ -40,7 +40,7 @@ fn destructure_nested_tuples() { let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("arg1") .with_value(&format_args!("1")) .and(expect::field("arg2").with_value(&format_args!("2"))) @@ -72,7 +72,7 @@ fn destructure_refs() { let (subscriber, handle) = subscriber::mock() .new_span( span.clone() - .with_field(expect::field("arg1").with_value(&1usize).only()), + .with_fields(expect::field("arg1").with_value(&1usize).only()), ) .enter(span.clone()) .exit(span.clone()) @@ -98,7 +98,7 @@ fn destructure_tuple_structs() { let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("arg1") .with_value(&format_args!("1")) .and(expect::field("arg2").with_value(&format_args!("2"))) @@ -139,7 +139,7 @@ fn destructure_structs() { let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("arg1") .with_value(&format_args!("1")) .and(expect::field("arg2").with_value(&format_args!("2"))) @@ -184,7 +184,7 @@ fn destructure_everything() { let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("arg1") .with_value(&format_args!("1")) .and(expect::field("arg2").with_value(&format_args!("2"))) diff --git a/tests/err.rs b/tests/err.rs index bee7aa5..7cc7ada 100644 --- a/tests/err.rs +++ b/tests/err.rs @@ -4,6 +4,7 @@ use tracing_attributes::instrument; use tracing_mock::*; use tracing_subscriber::filter::EnvFilter; use tracing_subscriber::layer::SubscriberExt; +use tracing_test::{block_on_future, PollN}; use std::convert::TryFrom; use std::num::TryFromIntError; @@ -14,6 +15,7 @@ fn err() -> Result { } #[instrument(err)] +#[allow(dead_code)] fn err_suspicious_else() -> Result { {} u8::try_from(1234) @@ -159,7 +161,7 @@ fn impl_trait_return_type() { let (subscriber, handle) = subscriber::mock() .new_span( span.clone() - .with_field(expect::field("x").with_value(&10usize).only()), + .with_fields(expect::field("x").with_value(&10usize).only()), ) .enter(span.clone()) .exit(span.clone()) diff --git a/tests/fields.rs b/tests/fields.rs index a3b23d7..3f9dce6 100644 --- a/tests/fields.rs +++ b/tests/fields.rs @@ -34,6 +34,9 @@ fn fn_string(s: String) { let _ = s; } +#[instrument(fields(keywords.impl.type.fn = _arg), skip(_arg))] +fn fn_keyword_ident_in_field(_arg: &str) {} + #[derive(Debug)] struct HasField { my_field: &'static str, @@ -46,7 +49,7 @@ impl HasField { #[test] fn fields() { - let span = expect::span().with_field( + let span = expect::span().with_fields( expect::field("foo") .with_value(&"bar") .and(expect::field("dsa").with_value(&true)) @@ -60,7 +63,7 @@ fn fields() { #[test] fn expr_field() { - let span = expect::span().with_field( + let span = expect::span().with_fields( expect::field("s") .with_value(&"hello world") .and(expect::field("len").with_value(&"hello world".len())) @@ -73,7 +76,7 @@ fn expr_field() { #[test] fn two_expr_fields() { - let span = expect::span().with_field( + let span = expect::span().with_fields( expect::field("s") .with_value(&"hello world") .and(expect::field("s.len").with_value(&"hello world".len())) @@ -87,7 +90,7 @@ fn two_expr_fields() { #[test] fn clashy_expr_field() { - let span = expect::span().with_field( + let span = expect::span().with_fields( // Overriding the `s` field should record `s` as a `Display` value, // rather than as a `Debug` value. expect::field("s") @@ -99,7 +102,7 @@ fn clashy_expr_field() { fn_clashy_expr_field("hello world"); }); - let span = expect::span().with_field(expect::field("s").with_value(&"s").only()); + let span = expect::span().with_fields(expect::field("s").with_value(&"s").only()); run_test(span, || { fn_clashy_expr_field2("hello world"); }); @@ -108,7 +111,7 @@ fn clashy_expr_field() { #[test] fn self_expr_field() { let span = - expect::span().with_field(expect::field("my_field").with_value(&"hello world").only()); + expect::span().with_fields(expect::field("my_field").with_value(&"hello world").only()); run_test(span, || { let has_field = HasField { my_field: "hello world", @@ -119,7 +122,7 @@ fn self_expr_field() { #[test] fn parameters_with_fields() { - let span = expect::span().with_field( + let span = expect::span().with_fields( expect::field("foo") .with_value(&"bar") .and(expect::field("param").with_value(&1u32)) @@ -132,7 +135,7 @@ fn parameters_with_fields() { #[test] fn empty_field() { - let span = expect::span().with_field(expect::field("foo").with_value(&"bar").only()); + let span = expect::span().with_fields(expect::field("foo").with_value(&"bar").only()); run_test(span, || { fn_empty_field(); }); @@ -140,12 +143,22 @@ fn empty_field() { #[test] fn string_field() { - let span = expect::span().with_field(expect::field("s").with_value(&"hello world").only()); + let span = expect::span().with_fields(expect::field("s").with_value(&"hello world").only()); run_test(span, || { fn_string(String::from("hello world")); }); } +#[test] +fn keyword_ident_in_field_name() { + let span = expect::span().with_fields( + expect::field("keywords.impl.type.fn") + .with_value(&"test") + .only(), + ); + run_test(span, || fn_keyword_ident_in_field("test")); +} + fn run_test T, T>(span: NewSpan, fun: F) { let (subscriber, handle) = subscriber::mock() .new_span(span) diff --git a/tests/follows_from.rs b/tests/follows_from.rs index 6b5526b..a81c6c7 100644 --- a/tests/follows_from.rs +++ b/tests/follows_from.rs @@ -1,6 +1,7 @@ use tracing::{subscriber::with_default, Id, Level, Span}; use tracing_attributes::instrument; -use tracing_mock::*; +use tracing_mock::{expect, subscriber}; +use tracing_test::block_on_future; #[instrument(follows_from = causes, skip(causes))] fn with_follows_from_sync(causes: impl IntoIterator>>) {} diff --git a/tests/instrument.rs b/tests/instrument.rs index f751eeb..193044d 100644 --- a/tests/instrument.rs +++ b/tests/instrument.rs @@ -6,6 +6,7 @@ use tracing_mock::*; // Reproduces a compile error when an instrumented function body contains inner // attributes (https://github.com/tokio-rs/tracing/issues/2294). #[deny(unused_variables)] +#[allow(dead_code, clippy::mixed_attributes_style)] #[instrument] fn repro_2294() { #![allow(unused_variables)] @@ -51,7 +52,7 @@ fn override_everything() { #[test] fn fields() { #[instrument(target = "my_target", level = "debug")] - fn my_fn(arg1: usize, arg2: bool) {} + fn my_fn(arg1: usize, arg2: bool, arg3: String) {} let span = expect::span() .named("my_fn") @@ -64,10 +65,11 @@ fn fields() { .with_target("my_target"); let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("arg1") .with_value(&2usize) .and(expect::field("arg2").with_value(&false)) + .and(expect::field("arg3").with_value(&"Cool".to_string())) .only(), ), ) @@ -75,10 +77,11 @@ fn fields() { .exit(span.clone()) .drop_span(span) .new_span( - span2.clone().with_field( + span2.clone().with_fields( expect::field("arg1") .with_value(&3usize) .and(expect::field("arg2").with_value(&true)) + .and(expect::field("arg3").with_value(&"Still Cool".to_string())) .only(), ), ) @@ -89,8 +92,8 @@ fn fields() { .run_with_handle(); with_default(subscriber, || { - my_fn(2, false); - my_fn(3, true); + my_fn(2, false, "Cool".to_string()); + my_fn(3, true, "Still Cool".to_string()); }); handle.assert_finished(); @@ -98,7 +101,7 @@ fn fields() { #[test] fn skip() { - struct UnDebug(pub u32); + struct UnDebug(); #[instrument(target = "my_target", level = "debug", skip(_arg2, _arg3))] fn my_fn(arg1: usize, _arg2: UnDebug, _arg3: UnDebug) {} @@ -124,7 +127,7 @@ fn skip() { let (subscriber, handle) = subscriber::mock() .new_span( span.clone() - .with_field(expect::field("arg1").with_value(&2usize).only()), + .with_fields(expect::field("arg1").with_value(&2usize).only()), ) .enter(span.clone()) .exit(span.clone()) @@ -132,7 +135,7 @@ fn skip() { .new_span( span2 .clone() - .with_field(expect::field("arg1").with_value(&3usize).only()), + .with_fields(expect::field("arg1").with_value(&3usize).only()), ) .enter(span2.clone()) .exit(span2.clone()) @@ -145,9 +148,9 @@ fn skip() { .run_with_handle(); with_default(subscriber, || { - my_fn(2, UnDebug(0), UnDebug(1)); - my_fn(3, UnDebug(0), UnDebug(1)); - my_fn2(2, UnDebug(0), UnDebug(1)); + my_fn(2, UnDebug(), UnDebug()); + my_fn(3, UnDebug(), UnDebug()); + my_fn2(2, UnDebug(), UnDebug()); }); handle.assert_finished(); @@ -169,7 +172,7 @@ fn generics() { let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("arg1") .with_value(&format_args!("Foo")) .and(expect::field("arg2").with_value(&format_args!("false"))), @@ -202,7 +205,7 @@ fn methods() { let (subscriber, handle) = subscriber::mock() .new_span( - span.clone().with_field( + span.clone().with_fields( expect::field("self") .with_value(&format_args!("Foo")) .and(expect::field("arg1").with_value(&42usize)), @@ -234,7 +237,7 @@ fn impl_trait_return_type() { let (subscriber, handle) = subscriber::mock() .new_span( span.clone() - .with_field(expect::field("x").with_value(&10usize).only()), + .with_fields(expect::field("x").with_value(&10usize).only()), ) .enter(span.clone()) .exit(span.clone()) @@ -250,3 +253,94 @@ fn impl_trait_return_type() { handle.assert_finished(); } + +#[test] +fn name_ident() { + const MY_NAME: &str = "my_name"; + #[instrument(name = MY_NAME)] + fn name() {} + + let span_name = expect::span().named(MY_NAME); + + let (subscriber, handle) = subscriber::mock() + .new_span(span_name.clone()) + .enter(span_name.clone()) + .exit(span_name.clone()) + .drop_span(span_name) + .only() + .run_with_handle(); + + with_default(subscriber, || { + name(); + }); + + handle.assert_finished(); +} + +#[test] +fn target_ident() { + const MY_TARGET: &str = "my_target"; + + #[instrument(target = MY_TARGET)] + fn target() {} + + let span_target = expect::span().named("target").with_target(MY_TARGET); + + let (subscriber, handle) = subscriber::mock() + .new_span(span_target.clone()) + .enter(span_target.clone()) + .exit(span_target.clone()) + .drop_span(span_target) + .only() + .run_with_handle(); + + with_default(subscriber, || { + target(); + }); + + handle.assert_finished(); +} + +#[test] +fn target_name_ident() { + const MY_NAME: &str = "my_name"; + const MY_TARGET: &str = "my_target"; + + #[instrument(target = MY_TARGET, name = MY_NAME)] + fn name_target() {} + + let span_name_target = expect::span().named(MY_NAME).with_target(MY_TARGET); + + let (subscriber, handle) = subscriber::mock() + .new_span(span_name_target.clone()) + .enter(span_name_target.clone()) + .exit(span_name_target.clone()) + .drop_span(span_name_target) + .only() + .run_with_handle(); + + with_default(subscriber, || { + name_target(); + }); + + handle.assert_finished(); +} + +#[test] +fn user_tracing_module() { + use ::tracing::field::Empty; + + // Reproduces https://github.com/tokio-rs/tracing/issues/3119 + #[instrument(fields(f = Empty))] + #[allow(dead_code)] + fn my_fn() { + assert_eq!("test", tracing::my_other_fn()); + } + + mod tracing { + #[allow(dead_code)] + pub fn my_other_fn() -> &'static str { + "test" + } + } +} diff --git a/tests/parents.rs b/tests/parents.rs index d455941..e6db581 100644 --- a/tests/parents.rs +++ b/tests/parents.rs @@ -21,23 +21,16 @@ fn default_parent_test() { .new_span( contextual_parent .clone() - .with_contextual_parent(None) - .with_explicit_parent(None), - ) - .new_span( - child - .clone() - .with_contextual_parent(Some("contextual_parent")) - .with_explicit_parent(None), + .with_ancestry(expect::is_contextual_root()), ) + .new_span(child.clone().with_ancestry(expect::is_contextual_root())) .enter(child.clone()) .exit(child.clone()) .enter(contextual_parent.clone()) .new_span( child .clone() - .with_contextual_parent(Some("contextual_parent")) - .with_explicit_parent(None), + .with_ancestry(expect::has_contextual_parent("contextual_parent")), ) .enter(child.clone()) .exit(child) @@ -68,20 +61,14 @@ fn explicit_parent_test() { .new_span( contextual_parent .clone() - .with_contextual_parent(None) - .with_explicit_parent(None), - ) - .new_span( - explicit_parent - .with_contextual_parent(None) - .with_explicit_parent(None), + .with_ancestry(expect::is_contextual_root()), ) + .new_span(explicit_parent.with_ancestry(expect::is_contextual_root())) .enter(contextual_parent.clone()) .new_span( child .clone() - .with_contextual_parent(Some("contextual_parent")) - .with_explicit_parent(Some("explicit_parent")), + .with_ancestry(expect::has_explicit_parent("explicit_parent")), ) .enter(child.clone()) .exit(child) diff --git a/tests/ret.rs b/tests/ret.rs index 90bd9e1..0ba2e10 100644 --- a/tests/ret.rs +++ b/tests/ret.rs @@ -1,11 +1,12 @@ use std::convert::TryFrom; use std::num::TryFromIntError; -use tracing_mock::*; use tracing::{subscriber::with_default, Level}; use tracing_attributes::instrument; +use tracing_mock::{expect, subscriber}; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::EnvFilter; +use tracing_test::block_on_future; #[instrument(ret)] fn ret() -> i32 { diff --git a/tests/ui.rs b/tests/ui.rs index 73d7fdc..14ae02c 100644 --- a/tests/ui.rs +++ b/tests/ui.rs @@ -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"); } diff --git a/tests/ui/async_instrument.rs b/tests/ui/fail/async_instrument.rs similarity index 94% rename from tests/ui/async_instrument.rs rename to tests/ui/fail/async_instrument.rs index 5b24574..03b3e18 100644 --- a/tests/ui/async_instrument.rs +++ b/tests/ui/fail/async_instrument.rs @@ -10,7 +10,6 @@ async fn simple_mismatch() -> String { "" } -// FIXME: this span is still pretty poor #[tracing::instrument] async fn opaque_unsatisfied() -> impl std::fmt::Display { ("",) diff --git a/tests/ui/async_instrument.stderr b/tests/ui/fail/async_instrument.stderr similarity index 60% rename from tests/ui/async_instrument.stderr rename to tests/ui/fail/async_instrument.stderr index 2c64b0c..afb6ab3 100644 --- a/tests/ui/async_instrument.stderr +++ b/tests/ui/fail/async_instrument.stderr @@ -1,17 +1,17 @@ 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()` @@ -19,80 +19,86 @@ error[E0308]: mismatched types | 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:1 + --> tests/ui/fail/async_instrument.rs:14:57 | -14 | #[tracing::instrument] - | ^^^^^^^^^^^^^^^^^^^^^^ `(&str,)` cannot be formatted with the default formatter +14 | async fn opaque_unsatisfied() -> impl std::fmt::Display { + | _________________________________________________________- +15 | | ("",) +16 | | } + | | ^ + | | | + | |_`(&str,)` cannot be formatted with the default formatter + | return type was inferred to be `(&str,)` here | = help: the trait `std::fmt::Display` is not implemented for `(&str,)` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead - = note: this error originates in the attribute macro `tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: `(&str,)` doesn't implement `std::fmt::Display` - --> tests/ui/async_instrument.rs:15:34 + --> tests/ui/fail/async_instrument.rs:14:34 | -15 | async fn opaque_unsatisfied() -> impl std::fmt::Display { +14 | async fn opaque_unsatisfied() -> impl std::fmt::Display { | ^^^^^^^^^^^^^^^^^^^^^^ `(&str,)` cannot be formatted with the default formatter | = help: the trait `std::fmt::Display` is not implemented for `(&str,)` = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead error[E0308]: mismatched types - --> tests/ui/async_instrument.rs:23:5 + --> tests/ui/fail/async_instrument.rs:22:5 | -23 | "" +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:22:36 + --> tests/ui/fail/async_instrument.rs:21:36 | -22 | async fn mismatch_with_opaque() -> Wrapper { +21 | async fn mismatch_with_opaque() -> Wrapper { | ^^^^^^^ help: try wrapping the expression in `Wrapper` | -23 | Wrapper("") +22 | Wrapper("") | ++++++++ + error[E0308]: mismatched types - --> tests/ui/async_instrument.rs:29:16 + --> tests/ui/fail/async_instrument.rs:28:16 | -29 | return ""; +28 | return ""; | ^^ expected `()`, found `&str` | note: return type inferred to be `()` here - --> tests/ui/async_instrument.rs:27:10 + --> tests/ui/fail/async_instrument.rs:26:10 | -27 | async fn early_return_unit() { +26 | async fn early_return_unit() { | ^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> tests/ui/async_instrument.rs:36:16 + --> tests/ui/fail/async_instrument.rs:35:16 | -36 | return ""; +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:34:28 + --> tests/ui/fail/async_instrument.rs:33:28 | -34 | async fn early_return() -> String { +33 | async fn early_return() -> String { | ^^^^^^ error[E0308]: mismatched types - --> tests/ui/async_instrument.rs:42:35 - | -42 | async fn extra_semicolon() -> i32 { - | ___________________________________^ -43 | | 1; - | | - help: remove this semicolon to return this value -44 | | } - | |_^ expected `i32`, found `()` + --> tests/ui/fail/async_instrument.rs:40:1 + | +40 | #[tracing::instrument] + | ^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `()` +41 | async fn extra_semicolon() -> i32 { +42 | 1; + | - help: remove this semicolon to return this value + | + = note: this error originates in the attribute macro `tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/const_instrument.rs b/tests/ui/fail/const_instrument.rs similarity index 100% rename from tests/ui/const_instrument.rs rename to tests/ui/fail/const_instrument.rs diff --git a/tests/ui/const_instrument.stderr b/tests/ui/fail/const_instrument.stderr similarity index 86% rename from tests/ui/const_instrument.stderr rename to tests/ui/fail/const_instrument.stderr index e76d4ac..4f91466 100644 --- a/tests/ui/const_instrument.stderr +++ b/tests/ui/fail/const_instrument.stderr @@ -1,5 +1,5 @@ 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] | ^^^^^^^^^^^^^^^^^^^^^^ @@ -7,7 +7,7 @@ error: macros that expand to items must be delimited with braces or followed by = 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] | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/fail/unused_instrumented_fn.rs b/tests/ui/fail/unused_instrumented_fn.rs new file mode 100644 index 0000000..e3b9ece --- /dev/null +++ b/tests/ui/fail/unused_instrumented_fn.rs @@ -0,0 +1,6 @@ +#![deny(dead_code)] + +#[tracing::instrument] +fn never_used() {} + +fn main() {} diff --git a/tests/ui/fail/unused_instrumented_fn.stderr b/tests/ui/fail/unused_instrumented_fn.stderr new file mode 100644 index 0000000..7c671e8 --- /dev/null +++ b/tests/ui/fail/unused_instrumented_fn.stderr @@ -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)] + | ^^^^^^^^^ diff --git a/tests/ui/pass/type_shadowing.rs b/tests/ui/pass/type_shadowing.rs new file mode 100644 index 0000000..90192f2 --- /dev/null +++ b/tests/ui/pass/type_shadowing.rs @@ -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() {} -- Gitee