Skip to content

Unnecessary "{}" suggestion for panic with const string #82026

New issue

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

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

Already on GitHub? # to your account

Closed
ldm0 opened this issue Feb 12, 2021 · 2 comments
Closed

Unnecessary "{}" suggestion for panic with const string #82026

ldm0 opened this issue Feb 12, 2021 · 2 comments

Comments

@ldm0
Copy link
Contributor

ldm0 commented Feb 12, 2021

#78088 implements suggestion for panic with first argument not literal, but forget to handle such code:

const ICE: &str = "Internal compiler error";
fn main() {
    panic!(ICE);
}

This code is actually legit., but non_fmt_panic suggestion is emitted.
Check: https://gist.github.com/6002a4f7fedfda0e615d0b1158015eee

@SNCPlay42
Copy link
Contributor

This isn't #78088's warning, it's #81645's.

And I don't think it's incorrect; only literals, not expressions can be used as format strings, even if the expression is evaluable at compile time. e.g. this doesn't work:

const FORMAT: &str = "{}";
fn main() {
    panic!(FORMAT, "Hello");
}

And indeed the code given does not compile in the 2021 edition.

@ldm0
Copy link
Contributor Author

ldm0 commented Feb 12, 2021

@SNCPlay42 Thanks!

@ldm0 ldm0 closed this as completed Feb 12, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants