diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9f43306..03b17e0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - rust: [nightly, beta, stable, 1.51.0, 1.50.0] + rust: [nightly, beta, stable, 1.52.0] steps: - uses: actions/checkout@v2 - uses: dtolnay/rust-toolchain@master @@ -22,6 +22,21 @@ jobs: - run: cargo test - run: cargo check --no-default-features - run: cargo check --features backtrace + + build: + name: Rust ${{matrix.rust}} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + rust: [1.51.0, 1.50.0] + steps: + - uses: actions/checkout@v2 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust}} + - run: cargo check --no-default-features + - run: cargo check --features backtrace if: matrix.rust != '1.50.0' backtrace: diff --git a/src/lib.rs b/src/lib.rs index b227eef..9be302b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -622,21 +622,21 @@ pub mod private { #[doc(hidden)] #[cold] - pub fn format_err(message: M, args: Arguments) -> Error + pub fn format_err(_message: M, args: Arguments) -> Error where M: Display + Debug + Send + Sync + 'static, { #[cfg(anyhow_no_fmt_arguments_as_str)] - let has_interpolated_format_args = false; + let fmt_arguments_as_str = Some(_message); #[cfg(not(anyhow_no_fmt_arguments_as_str))] - let has_interpolated_format_args = args.as_str().is_none(); + let fmt_arguments_as_str = args.as_str(); - if has_interpolated_format_args { - // anyhow!("interpolate {var}"), can downcast to String - Error::msg(fmt::format(args)) - } else { + if let Some(message) = fmt_arguments_as_str { // anyhow!("literal"), can downcast to &'static str Error::msg(message) + } else { + // anyhow!("interpolate {var}"), can downcast to String + Error::msg(fmt::format(args)) } } } diff --git a/tests/test_macros.rs b/tests/test_macros.rs index b08db97..4cbb580 100644 --- a/tests/test_macros.rs +++ b/tests/test_macros.rs @@ -56,3 +56,9 @@ fn test_temporaries() { future::ready(anyhow!("...")).await; }); } + +#[test] +fn test_brace_escape() { + let err = anyhow!("unterminated ${{..}} expression"); + assert_eq!("unterminated ${..} expression", err.to_string()); +}