mirror of https://github.com/zkat/miette.git
Add and use `no-format-args-capture` flag
This commit is contained in:
parent
4520d66815
commit
7fb4cb2494
|
|
@ -43,7 +43,11 @@ jobs:
|
|||
- name: Clippy
|
||||
run: cargo clippy --all -- -D warnings
|
||||
- name: Run tests
|
||||
if: matrix.rust == 'stable'
|
||||
run: cargo test --all --verbose --features fancy
|
||||
- name: Run tests
|
||||
if: matrix.rust == '1.56.0'
|
||||
run: cargo test --all --verbose --features fancy no-format-args-capture
|
||||
|
||||
miri:
|
||||
name: Miri
|
||||
|
|
|
|||
11
Cargo.toml
11
Cargo.toml
|
|
@ -42,7 +42,16 @@ lazy_static = "1.4"
|
|||
|
||||
[features]
|
||||
default = []
|
||||
fancy-no-backtrace = ["owo-colors", "is-terminal", "textwrap", "terminal_size", "supports-hyperlinks", "supports-color", "supports-unicode"]
|
||||
no-format-args-capture = []
|
||||
fancy-no-backtrace = [
|
||||
"owo-colors",
|
||||
"is-terminal",
|
||||
"textwrap",
|
||||
"terminal_size",
|
||||
"supports-hyperlinks",
|
||||
"supports-color",
|
||||
"supports-unicode",
|
||||
]
|
||||
fancy = ["fancy-no-backtrace", "backtrace", "backtrace-ext"]
|
||||
|
||||
[workspace]
|
||||
|
|
|
|||
|
|
@ -16,7 +16,14 @@
|
|||
/// # let resource = 0;
|
||||
/// #
|
||||
/// if !has_permission(user, resource) {
|
||||
/// bail!("permission denied for accessing {resource}");
|
||||
#[cfg_attr(
|
||||
not(feature = "no-format-args-capture"),
|
||||
doc = r#" bail!("permission denied for accessing {resource}");"#
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "no-format-args-capture",
|
||||
doc = r#" bail!("permission denied for accessing {}", resource);"#
|
||||
)]
|
||||
/// }
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
|
|
@ -56,7 +63,14 @@
|
|||
/// if y.abs() < 1e-3 {
|
||||
/// bail!(
|
||||
/// severity = Severity::Warning,
|
||||
/// "dividing by value ({y}) close to 0"
|
||||
#[cfg_attr(
|
||||
not(feature = "no-format-args-capture"),
|
||||
doc = r#" "dividing by value ({y}) close to 0""#
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "no-format-args-capture",
|
||||
doc = r#" "dividing by value ({}) close to 0", y"#
|
||||
)]
|
||||
/// );
|
||||
/// }
|
||||
/// Ok(x / y)
|
||||
|
|
@ -126,7 +140,14 @@ macro_rules! bail {
|
|||
/// ensure!(
|
||||
/// y.abs() >= 1e-3,
|
||||
/// severity = Severity::Warning,
|
||||
/// "dividing by value ({y}) close to 0"
|
||||
#[cfg_attr(
|
||||
not(feature = "no-format-args-capture"),
|
||||
doc = r#" "dividing by value ({y}) close to 0""#
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "no-format-args-capture",
|
||||
doc = r#" "dividing by value ({}) close to 0", y"#
|
||||
)]
|
||||
/// );
|
||||
/// Ok(x / y)
|
||||
/// }
|
||||
|
|
@ -156,11 +177,26 @@ macro_rules! ensure {
|
|||
/// # use miette::miette;
|
||||
/// let x = 1;
|
||||
/// let y = 2;
|
||||
/// let report = miette!("{x} + {} = {z}", y, z = x + y);
|
||||
#[cfg_attr(
|
||||
not(feature = "no-format-args-capture"),
|
||||
doc = r#"let report = miette!("{x} + {} = {z}", y, z = x + y);"#
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "no-format-args-capture",
|
||||
doc = r#"let report = miette!("{} + {} = {z}", x, y, z = x + y);"#
|
||||
)]
|
||||
///
|
||||
/// assert_eq!(report.to_string().as_str(), "1 + 2 = 3");
|
||||
///
|
||||
/// let z = x + y;
|
||||
/// let report = miette!("{x} + {y} = {z}");
|
||||
#[cfg_attr(
|
||||
not(feature = "no-format-args-capture"),
|
||||
doc = r#"let report = miette!("{x} + {y} = {z}");"#
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "no-format-args-capture",
|
||||
doc = r#"let report = miette!("{} + {} = {}", x, y, z);"#
|
||||
)]
|
||||
/// assert_eq!(report.to_string().as_str(), "1 + 2 = 3");
|
||||
/// ```
|
||||
///
|
||||
|
|
@ -225,11 +261,25 @@ macro_rules! miette {
|
|||
/// let x = 1;
|
||||
/// let y = 2;
|
||||
///
|
||||
/// let diag = diagnostic!("{x} + {} = {z}", y, z = x + y);
|
||||
#[cfg_attr(
|
||||
not(feature = "no-format-args-capture"),
|
||||
doc = r#" let diag = diagnostic!("{x} + {} = {z}", y, z = x + y);"#
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "no-format-args-capture",
|
||||
doc = r#" let diag = diagnostic!("{} + {} = {z}", x, y, z = x + y);"#
|
||||
)]
|
||||
/// assert_eq!(diag.message, "1 + 2 = 3");
|
||||
///
|
||||
/// let z = x + y;
|
||||
/// let diag = diagnostic!("{x} + {y} = {z}");
|
||||
#[cfg_attr(
|
||||
not(feature = "no-format-args-capture"),
|
||||
doc = r#"let diag = diagnostic!("{x} + {y} = {z}");"#
|
||||
)]
|
||||
#[cfg_attr(
|
||||
feature = "no-format-args-capture",
|
||||
doc = r#"let diag = diagnostic!("{} + {} = {}", x, y, z);"#
|
||||
)]
|
||||
/// assert_eq!(diag.message, "1 + 2 = 3");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
|
|
|
|||
|
|
@ -599,7 +599,7 @@
|
|||
//! then you may want to use [`miette!`], [`diagnostic!`] macros or
|
||||
//! [`MietteDiagnostic`] directly to create diagnostic on the fly.
|
||||
//!
|
||||
//! ```rs
|
||||
//! ```rust,ignore
|
||||
//! # use miette::{miette, LabeledSpan, Report};
|
||||
//!
|
||||
//! let source = "2 + 2 * 2 = 8".to_string();
|
||||
|
|
|
|||
Loading…
Reference in New Issue