Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,21 +622,21 @@ pub mod private {

#[doc(hidden)]
#[cold]
pub fn format_err<M>(message: M, args: Arguments) -> Error
pub fn format_err<M>(_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))
}
}
}
6 changes: 6 additions & 0 deletions tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}