Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tokio-rs/tracing into hds/mock-co…
Browse files Browse the repository at this point in the history
…llector-docs
  • Loading branch information
hds committed Jan 4, 2023
2 parents fe92324 + 58accc6 commit 28b25fc
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 17 deletions.
1 change: 0 additions & 1 deletion tracing-appender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
//! supported compiler version is not considered a semver breaking change as
//! long as doing so complies with this policy.
//!
#![doc(html_root_url = "https://docs.rs/tracing-appender/0.1.1")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down
18 changes: 16 additions & 2 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
//! supported compiler version is not considered a semver breaking change as
//! long as doing so complies with this policy.
//!
#![doc(html_root_url = "https://docs.rs/tracing-attributes/0.1.11")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down Expand Up @@ -80,7 +79,7 @@
)]

use proc_macro2::TokenStream;
use quote::ToTokens;
use quote::{quote, ToTokens};
use syn::parse::{Parse, ParseStream};
use syn::{Attribute, ItemFn, Signature, Visibility};

Expand Down Expand Up @@ -343,6 +342,14 @@ mod expand;
/// }
/// ```
///
/// `const fn` cannot be instrumented, and will result in a compilation failure:
///
/// ```compile_fail
/// # use tracing_attributes::instrument;
/// #[instrument]
/// const fn my_const_function() {}
/// ```
///
/// [span]: https://docs.rs/tracing/latest/tracing/span/index.html
/// [`follows_from`]: https://docs.rs/tracing/latest/tracing/struct.Span.html#method.follows_from
/// [`tracing`]: https://github.com/tokio-rs/tracing
Expand Down Expand Up @@ -386,6 +393,13 @@ fn instrument_precise(
let input = syn::parse::<ItemFn>(item)?;
let instrumented_function_name = input.sig.ident.to_string();

if input.sig.constness.is_some() {
return Ok(quote! {
compile_error!("the `#[instrument]` attribute may not be used with `const fn`s")
}
.into());
}

// check for async_trait-like patterns in the block, and instrument
// the future instead of the wrapper
if let Some(async_like) = expand::AsyncInfo::from_fn(&input) {
Expand Down
7 changes: 7 additions & 0 deletions tracing-attributes/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ 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");
}
2 changes: 1 addition & 1 deletion tracing-attributes/tests/ui/async_instrument.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ error[E0308]: mismatched types
42 | async fn extra_semicolon() -> i32 {
| ___________________________________^
43 | | 1;
| | - help: remove this semicolon
| | - help: remove this semicolon to return this value
44 | | }
| |_^ expected `i32`, found `()`
8 changes: 8 additions & 0 deletions tracing-attributes/tests/ui/const_instrument.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![allow(unreachable_code)]

#[tracing::instrument]
const fn unit() {
""
}

fn main() {}
15 changes: 15 additions & 0 deletions tracing-attributes/tests/ui/const_instrument.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: macros that expand to items must be delimited with braces or followed by a semicolon
--> tests/ui/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
|
3 | #[tracing::instrument]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 0 additions & 1 deletion tracing-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
//! [`Dispatch`]: dispatch::Dispatch
//! [`tokio-rs/tracing`]: https://github.com/tokio-rs/tracing
//! [`tracing`]: https://crates.io/crates/tracing
#![doc(html_root_url = "https://docs.rs/tracing-core/0.1.17")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down
1 change: 0 additions & 1 deletion tracing-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@
//! long as doing so complies with this policy.
//!
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(html_root_url = "https://docs.rs/tracing-error/0.1.2")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down
1 change: 0 additions & 1 deletion tracing-futures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
//! supported compiler version is not considered a semver breaking change as
//! long as doing so complies with this policy.
//!
#![doc(html_root_url = "https://docs.rs/tracing-futures/0.2.4")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down
1 change: 0 additions & 1 deletion tracing-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
//! [`tracing::Event`]: tracing_core::Event
//! [`Collect`]: tracing::Collect
//! [flags]: https://docs.rs/tracing/latest/tracing/#crate-feature-flags
#![doc(html_root_url = "https://docs.rs/tracing-log/0.1.1")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down
1 change: 0 additions & 1 deletion tracing-opentelemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
//! [subscriber]: tracing_subscriber::subscribe
#![deny(unreachable_pub)]
#![cfg_attr(test, deny(warnings))]
#![doc(html_root_url = "https://docs.rs/tracing-opentelemetry/0.16.0")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down
1 change: 0 additions & 1 deletion tracing-serde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
//!
//! [`tracing`]: https://crates.io/crates/tracing
//! [`serde`]: https://crates.io/crates/serde
#![doc(html_root_url = "https://docs.rs/tracing-serde/0.1.2")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down
9 changes: 4 additions & 5 deletions tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,15 +1065,14 @@ where
write!(writer, "{:0>2?} ", std::thread::current().id())?;
}

let bold = writer.bold();
let dimmed = writer.dimmed();
if self.display_target {
write!(writer, "{}{}", bold.paint(meta.target()), dimmed.paint(":"))?;
write!(writer, "{}{}", dimmed.paint(meta.target()), dimmed.paint(":"))?;
}

if self.display_filename {
if let Some(filename) = meta.file() {
write!(writer, "{}{}", bold.paint(filename), dimmed.paint(":"))?;
write!(writer, "{}{}", dimmed.paint(filename), dimmed.paint(":"))?;
}
}

Expand All @@ -1082,9 +1081,9 @@ where
write!(
writer,
"{}{}{}{}",
bold.prefix(),
dimmed.prefix(),
line_number,
bold.suffix(),
dimmed.suffix(),
dimmed.paint(":")
)?;
}
Expand Down
1 change: 0 additions & 1 deletion tracing-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
//! [`time` crate]: https://crates.io/crates/time
//! [`liballoc`]: https://doc.rust-lang.org/alloc/index.html
//! [`libstd`]: https://doc.rust-lang.org/std/index.html
#![doc(html_root_url = "https://docs.rs/tracing-subscriber/0.2.25")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down
1 change: 0 additions & 1 deletion tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@
//! [flags]: #crate-feature-flags
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(html_root_url = "https://docs.rs/tracing/0.1.21")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/favicon.ico",
Expand Down

0 comments on commit 28b25fc

Please sign in to comment.