Skip to content

Commit

Permalink
Merge pull request #346 from dtolnay/fmttest
Browse files Browse the repository at this point in the history
Add tests of `_` and `self` variables in format string
  • Loading branch information
dtolnay authored Nov 4, 2024
2 parents 8d06fb5 + 4d397bc commit b6e30da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/test_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ fn test_keyword() {
assert("error: 1", Error);
}

#[test]
fn test_self() {
#[derive(Error, Debug)]
#[error("error: {self:?}")]
struct Error;

assert("error: Error", Error);
}

#[test]
fn test_str_special_chars() {
#[derive(Error, Debug)]
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/display-underscore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use thiserror::Error;

#[derive(Error, Debug)]
#[error("{_}")]
pub struct Error;

fn main() {}
7 changes: 7 additions & 0 deletions tests/ui/display-underscore.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error: invalid format string: invalid argument name `_`
--> tests/ui/display-underscore.rs:4:11
|
4 | #[error("{_}")]
| ^ invalid argument name in format string
|
= note: argument name cannot be a single underscore

0 comments on commit b6e30da

Please sign in to comment.