Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests of _ and self variables in format string #346

Merged
merged 2 commits into from
Nov 4, 2024
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
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
Loading