4 Commits

Author SHA1 Message Date
Eliza Weisman
4b54cbc689
chore: fix nightly clippy warnings (#991) (#1025)
This backports PR #991 to v0.1.x. This is primarily necessary for the MSRV
bump, since some dependencies no longer compile on Rust 1.40.0.

This has already been approved on `master`, in PR #991, so it should be 
fine to ship.

## Motivation

This will avoid breaking CI on new releases of clippy. It also makes the
code a little easier to read.

## Solution

- Convert `match val { pat => true, _ => false }` to `matches!(val, pat)`
- Remove unnecessary closures
- Convert `self: &mut Self` to `&mut self`

This bumps the MSRV to 1.42.0 for `matches!`.
The latest version of rust is 1.46.0, so as per
https://github.com/tokio-rs/tracing#supported-rust-versions this is not
considered a breaking change.

I didn't fix the following warning because the fix was not trivial/needed
a decision:

```
warning: you are deriving `Ord` but have implemented `PartialOrd` explicitly
   --> tracing-subscriber/src/filter/env/field.rs:16:32
    |
16  | #[derive(Debug, Eq, PartialEq, Ord)]
    |                                ^^^
    |
    = note: `#[warn(clippy::derive_ord_xor_partial_ord)]` on by default
note: `PartialOrd` implemented here
   --> tracing-subscriber/src/filter/env/field.rs:98:1
    |
98  | / impl PartialOrd for Match {
99  | |     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
100 | |         // Ordering for `Match` directives is based first on _whether_ a value
101 | |         // is matched or not. This is semantically meaningful --- we would
...   |
121 | |     }
122 | | }
    | |_^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
```

As a side note, this found a bug in clippy 😆 https://github.com/rust-lang/rust-clippy/issues/6089
2020-10-07 14:10:49 -07:00
Simon THOBY
9ae4676054
attributes: support use of the 'self' variable in async-trait contexts (#875)
##  Motivation

Fixes #864.

## Solution

Visit the fields and replace 'self' with '_self', and 'Self' with the
type of the impl (when we can acces it, see
https://github.com/tokio-rs/tracing/issues/864#issuecomment-667508801
for current limitations).
2020-08-07 11:46:26 -07:00
Simon THOBY
369b0c5e1d
attributes: support using #[instrument] with async-trait (#711)
## Motivation

As outlined in #399, right now `tracing-futures` (or more precisely, the
code generated by `#[instrument]`) is not working well with async-trait.
What happens is that async-trait rewrites the trait method as a
non-async function, insides of which it pins the async method we want to
instrument, and we end up instrumenting the wrapper instead of the async
fn.

This will allow people to use traits with (seemingly) async functions
along with `#[instrument]`.

## Solution

I decided to follow the discussion at
https://github.com/dtolnay/async-trait/issues/45 and see if I could make
it working. Right now I would describe its state as "works for me, and
*should* work for everyone".

The `instrument` macro will now:

* Rewrite the block when it looks like there is async_trait involved to
  wrap the internal async function instead of the wrapper generated by
  `async-trait` 
* Rewrite '_self' as 'self' when using #[instrument] jointly with 
  `async-trait`

Fixes #399
2020-05-13 13:01:55 -07:00
Eliza Weisman
7212355e47
chore: un-special-case std::future tests (#618)
## Motivation

Currently, `tracing-futures` and `tracing-attributes` both have separate
crates for tests that require `std::future` and async/await syntax.
These date back to before these features were stable, and the tests were
separated because they could only be run on nighly Rust. This has not
been the case for a long while, and `tracing` now supports `std::future`
as the default, requiring opt-in support for `futures` 0.1. I think we
had forgotten to remove the special-cased tests when we made that
transition.

## Solution

This branch removes the special-cased test crates, and moves all
`std::future` and async/await tests into the main test dirs for these
crates. I've also removed the separate CI steps that ran these.

This should simplify things significantly!

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-03-04 12:12:57 -08:00