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

Support mixing shorthand and non-shorthand format args #47

Closed
dtolnay opened this issue Nov 29, 2019 · 1 comment · Fixed by #49
Closed

Support mixing shorthand and non-shorthand format args #47

dtolnay opened this issue Nov 29, 2019 · 1 comment · Fixed by #49

Comments

@dtolnay
Copy link
Owner

dtolnay commented Nov 29, 2019

As in:

mod msg {
    pub const ERR_INVALID_UTF8: &str = "argument not convertible to UTF-8";
}

#[derive(Error, Debug)]
pub enum Error {
    #[error("{}: {value:?}", msg::ERR_INVALID_UTF8)]
    InvalidUtf8 { value: std::ffi::OsString },
}

Currently this fails because, as documented in the readme, our "{value:?}" shorthand does not kick in if any explicit format args are specified.

@dtolnay
Copy link
Owner Author

dtolnay commented Nov 29, 2019

The current heuristic is:

  • If the user provided any explicit format args, make no change.
  • Otherwise for each {var} in the format string change it to {} and append , var to the args.

The heuristic instead would be:

  • For each {var} in the format string append , var = var to the args.

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 a pull request may close this issue.

1 participant