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 a type for representing raw-agnostic format vars #349

Merged
merged 1 commit into from
Nov 4, 2024
Merged

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Nov 4, 2024

The core::fmt format string syntax considers format_args!("...", r#keyword = "...") as equivalent to format_args!("...", keyword = "..."). That means manipulating named argument sets as Set<Ident> using Ident's Ord impl doesn't make sense, as that impl considers r#keyword != keyword.

Before this PR, the following would compile successfully because thiserror would see that fn was already present in the user-provided named arguments, so it would not try to insert a new named argument referring to the struct field:

#[derive(Error, Debug)]
#[error("{fn}", fn = "...")]
pub struct Error {
    r#fn: &'static str,
}

But in contrast, the following would not compile, due to thiserror using an incorrect comparison and not realizing that a user-provided named argument for {fn} was already present.

#[derive(Error, Debug)]
#[error("{fn}", r#fn = "...")]
pub struct Error {
    r#fn: &'static str,
}
error: duplicate argument named `r#fn`
 --> src/main.rs:4:9
  |
4 | #[error("{fn}", r#fn = "...")]
  |         ^^^^^^  ---- previously here
  |         |
  |         duplicate argument

After this PR, both compile.

@dtolnay dtolnay merged commit 2e96c84 into master Nov 4, 2024
18 checks passed
@dtolnay dtolnay deleted the unraw branch November 4, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant