Commit 533f768
committed
tracing: support bare
The `valueset!` macro imports `display`, `debug` and `Value` from
`tracing::field`. This is unhygienic in that tracing macros that use
`valueset!` (all the event and span macros) cannot use any symbols named
`display` or `debug` when defining fields inside the macro.
A side affect of this is that these three symbols can be used
unqualified within the definition of fields within the tracing macros.
So the following is valid:
```rust
tracing::error!(foo = display("foo"));
tracing::error!(quux = debug(4_u8 as u64));
tracing::error!(bar = &num as &dyn Value);
```
As per [Hyrum's Law], this behavior depended on by plenty of users and
has been for years. At least 2 attempts have been made to clean this up,
but they've had to be reverted as it is effectively a breaking change
(see #820 and #3424 for details).
[Hyrum's Law]: https://www.hyrumslaw.com/
To partially resolve this situation, this change adds support for
`display` and `debug` patterns to the `valueset!` macro explicitly. As
such, the use of `display(expr)`, `display(ident)` and the same for
`debug` are matched in the patterns the same way that the `%` and `?`
sigils already are.
These patterns then get expanded the same way that the sigils do, into
the fully qualified path to the appropriate function.
As the use of bare `display` and `debug` are now caught by the macro, we
can safely remove the import of those 2 symbols. This still leaves the
import of `$crate::field::Value`, but I don't know if that's avoidable,
and has also proved to be less problematic as it's a type and less
likely to clash to the use of variables. However, we still don't want to
break user code by removing it.
The bare `display` and `debug` also continue to work with the
`#[instrument]` attribute macro:
```rust
#[tracing::instrument(fields(foo = debug(Some(5))))]
fn foo() {}
```
Fairly extensive tests have been added to cover all the cases that the
macros support (which are all the cases that could be thought up).
This means that we can support all previously valid macro invocations,
but we can also support the following, which didn't work before:
```rust
let display = "display";
let debug = "debug";
tracing::error!("{debug:?} {display}");
```
This change deliberately doesn't add support for wrapping an identifier
in `debug` or `display` with no key. This isn't supported now and there
is no need to support it when the sigils are available. That is to say
that the following didn't compile before and will continue not to
compile:
```rust
tracing::error!(display(disp));
tracing::error!(debug(deb));
```
To make this clear, UI tests have been added for the compilation error.display and debug in macros1 parent 7c44f7b commit 533f768
File tree
9 files changed
+296
-7
lines changed- tracing-attributes/tests
- tracing
- src
- tests
- ui/fail
9 files changed
+296
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
80 | 107 | | |
81 | 108 | | |
82 | 109 | | |
| |||
236 | 263 | | |
237 | 264 | | |
238 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
239 | 312 | | |
240 | 313 | | |
241 | 314 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2831 | 2831 | | |
2832 | 2832 | | |
2833 | 2833 | | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
2834 | 2840 | | |
2835 | 2841 | | |
2836 | 2842 | | |
2837 | 2843 | | |
2838 | 2844 | | |
2839 | 2845 | | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
| 2851 | + | |
2840 | 2852 | | |
2841 | 2853 | | |
2842 | 2854 | | |
| |||
2866 | 2878 | | |
2867 | 2879 | | |
2868 | 2880 | | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
2869 | 2886 | | |
2870 | 2887 | | |
2871 | 2888 | | |
2872 | 2889 | | |
2873 | 2890 | | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
2874 | 2896 | | |
2875 | 2897 | | |
2876 | 2898 | | |
| |||
2899 | 2921 | | |
2900 | 2922 | | |
2901 | 2923 | | |
| 2924 | + | |
| 2925 | + | |
| 2926 | + | |
| 2927 | + | |
| 2928 | + | |
| 2929 | + | |
2902 | 2930 | | |
2903 | 2931 | | |
2904 | 2932 | | |
2905 | 2933 | | |
2906 | 2934 | | |
2907 | 2935 | | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
2908 | 2942 | | |
2909 | 2943 | | |
2910 | 2944 | | |
| |||
2916 | 2950 | | |
2917 | 2951 | | |
2918 | 2952 | | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
2919 | 2958 | | |
2920 | 2959 | | |
2921 | 2960 | | |
2922 | 2961 | | |
2923 | 2962 | | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
2924 | 2968 | | |
2925 | 2969 | | |
2926 | 2970 | | |
| |||
2930 | 2974 | | |
2931 | 2975 | | |
2932 | 2976 | | |
2933 | | - | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
2934 | 2984 | | |
2935 | 2985 | | |
2936 | 2986 | | |
2937 | 2987 | | |
2938 | 2988 | | |
2939 | | - | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
| 2994 | + | |
| 2995 | + | |
2940 | 2996 | | |
2941 | 2997 | | |
2942 | 2998 | | |
2943 | 2999 | | |
2944 | 3000 | | |
2945 | | - | |
| 3001 | + | |
2946 | 3002 | | |
2947 | 3003 | | |
2948 | 3004 | | |
2949 | 3005 | | |
2950 | 3006 | | |
2951 | | - | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
2952 | 3013 | | |
2953 | 3014 | | |
2954 | 3015 | | |
2955 | 3016 | | |
2956 | | - | |
| 3017 | + | |
| 3018 | + | |
| 3019 | + | |
| 3020 | + | |
| 3021 | + | |
| 3022 | + | |
2957 | 3023 | | |
2958 | 3024 | | |
2959 | 3025 | | |
2960 | 3026 | | |
2961 | | - | |
| 3027 | + | |
2962 | 3028 | | |
2963 | 3029 | | |
2964 | 3030 | | |
| |||
2973 | 3039 | | |
2974 | 3040 | | |
2975 | 3041 | | |
2976 | | - | |
| 3042 | + | |
| 3043 | + | |
| 3044 | + | |
| 3045 | + | |
2977 | 3046 | | |
2978 | 3047 | | |
2979 | 3048 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
23 | 38 | | |
24 | 39 | | |
25 | 40 | | |
| |||
1398 | 1413 | | |
1399 | 1414 | | |
1400 | 1415 | | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
1401 | 1501 | | |
1402 | 1502 | | |
1403 | 1503 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments