{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/22932","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/22932/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/22932/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/22932/events","html_url":"https://github.com/rust-lang/rust/issues/22932","id":59400560,"number":22932,"title":"panic!(\"{}\") shouldn't compile","user":{"login":"tomaka","id":1412254,"avatar_url":"https://avatars.githubusercontent.com/u/1412254?v=3","gravatar_id":"","url":"https://api.github.com/users/tomaka","html_url":"https://github.com/tomaka","followers_url":"https://api.github.com/users/tomaka/followers","following_url":"https://api.github.com/users/tomaka/following{/other_user}","gists_url":"https://api.github.com/users/tomaka/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaka/subscriptions","organizations_url":"https://api.github.com/users/tomaka/orgs","repos_url":"https://api.github.com/users/tomaka/repos","events_url":"https://api.github.com/users/tomaka/events{/privacy}","received_events_url":"https://api.github.com/users/tomaka/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-libs","name":"A-libs","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-macros","name":"A-macros","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/P-low","name":"P-low","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/rust-lang/rust/milestones/20","html_url":"https://github.com/rust-lang/rust/milestones/1.0","labels_url":"https://api.github.com/repos/rust-lang/rust/milestones/20/labels","id":452034,"number":20,"title":"1.0","description":"This will be the first major release of Rust, where we offer some guaranteed level of support and backwards compatibility.\r\n\r\nThe significant criteria for this release are:\r\n\r\n* Language backwards compatibility - All major features are in, and in their final form. Generally, the only new language features added after this milestone must be backwards compatible, or to fix soundness holes, though we do expect to have some leeway to make small incompatible fixes that have low impact on existing code bases.\r\n\r\n* Library stability - We have a system of measuring and ensuring the stability of API's, and a significant portion of the standard library is declared stable. Stable API's will not change. Large portions of the standard library need to be stable for 1.0, including primitive types, vectors, strings, option, numerics, collections, some I/O and concurrency.\r\n\r\n* User experience - The system is polished and the presentation is complete and professional. New users have a clear path to using and learning the system. This encompasses the web site, documentation, installation, and tooling.\r\n","creator":{"login":"brson","id":147214,"avatar_url":"https://avatars.githubusercontent.com/u/147214?v=3","gravatar_id":"","url":"https://api.github.com/users/brson","html_url":"https://github.com/brson","followers_url":"https://api.github.com/users/brson/followers","following_url":"https://api.github.com/users/brson/following{/other_user}","gists_url":"https://api.github.com/users/brson/gists{/gist_id}","starred_url":"https://api.github.com/users/brson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brson/subscriptions","organizations_url":"https://api.github.com/users/brson/orgs","repos_url":"https://api.github.com/users/brson/repos","events_url":"https://api.github.com/users/brson/events{/privacy}","received_events_url":"https://api.github.com/users/brson/received_events","type":"User","site_admin":false},"open_issues":41,"closed_issues":336,"state":"open","created_at":"2013-10-10T18:48:33Z","updated_at":"2015-03-07T05:57:38Z","due_on":null,"closed_at":null},"comments":6,"created_at":"2015-03-01T15:37:40Z","updated_at":"2015-03-07T08:49:22Z","closed_at":null,"body":"I didn't find any duplicate issue, but this problem has probably been there for a long time.\r\n\r\n- The code `panic!(\"{}\", 7)` compiles and prints `thread <main> panicked at \"7\", ...`\r\n- The code `panic!(\"{} {}\", 7)` doesn't compile as an argument is missing\r\n- The code `panic!(\"{}\")` **does compile** and prints `thread <main> panicked at \"{}\", ...`\r\n\r\nThe last one doesn't detect potential mistakes, and is inconsistent with `println!(\"{}\")` which doesn't compile.\r\n"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/77680032","html_url":"https://github.com/rust-lang/rust/issues/22932#issuecomment-77680032","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/22932","id":77680032,"user":{"login":"rprichard","id":1572855,"avatar_url":"https://avatars.githubusercontent.com/u/1572855?v=3","gravatar_id":"","url":"https://api.github.com/users/rprichard","html_url":"https://github.com/rprichard","followers_url":"https://api.github.com/users/rprichard/followers","following_url":"https://api.github.com/users/rprichard/following{/other_user}","gists_url":"https://api.github.com/users/rprichard/gists{/gist_id}","starred_url":"https://api.github.com/users/rprichard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rprichard/subscriptions","organizations_url":"https://api.github.com/users/rprichard/orgs","repos_url":"https://api.github.com/users/rprichard/repos","events_url":"https://api.github.com/users/rprichard/events{/privacy}","received_events_url":"https://api.github.com/users/rprichard/received_events","type":"User","site_admin":false},"created_at":"2015-03-07T08:49:22Z","updated_at":"2015-03-07T08:49:22Z","body":"If we make single-argument `panic!` use the formatting system like `write!`, then we need an alternate syntax for the current single-argument `panic!` in libstd, so we can still do things like:\r\n```rust\r\npanic!({ let x = \"{}\"; x })\r\npanic!(7)\r\n```\r\nMaybe add a `panic_arg!` or `panic_any!` macro?\r\n\r\nThe other thing needed for this issue is some way to convert a format string to an output string:\r\n\r\n * A new `format_arg!` macro.  (I suggest `format_args_literal!` as an alternate name.)\r\n\r\n * Use `format_args!` and a new method on `Arguments` to extract the lone string piece.  It will probably generate larger code then the previous option, but not worse than the current libstd `panic!`.  We'd like to place the string piece in a static item, like `core::panicking::panic` does, but we can't have a function call in a static.  This approach would generate a lot more code at each call-site, but it ought to be optimized out.\r\n\r\nI [benchmarked](https://gist.github.com/rprichard/f0528270cd2f65ded875) the size overhead of calling `panic!` with a single-argument on x86_64.  It's 52 bytes in libcore and 67 bytes in libstd.  Calling `core::panicking::panic_fmt` takes 110 bytes.\r\n"}}