Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uppanic!("{}") shouldn't compile #22932
Comments
kmcallister
added
A-libs
A-macros
labels
Mar 1, 2015
This comment has been minimized.
This comment has been minimized.
amaneureka
commented
Mar 1, 2015
|
Actually this is not an issue; If you go through the docs (http://doc.rust-lang.org/std/macro.panic!.html) |
This comment has been minimized.
This comment has been minimized.
|
I know why it compiles, but it's still an issue. |
This comment has been minimized.
This comment has been minimized.
|
It'd be nice if we could remove the inconsistency between single-argument and multiple-argument This same issue came up in #22335, which tried to optimize I'm interested in this stuff right now because I'm working on a bootloader, and the overhead of the panic formatting code is giving me trouble -- http://users.rust-lang.org/t/fixed-overhead-rust-bootloader-and-core-panicking/429/10. |
alexcrichton
added
the
I-nominated
label
Mar 2, 2015
This comment has been minimized.
This comment has been minimized.
|
The same inconsistency also applies to assert!(1 == 2, "{}"); // prints: '{}'
assert!(1 == 2, "{}", 1234); // prints: '1234'Currently the one-argument assert!("abc" == "{}"); // prints: 'assertion failed: "abc" == "{}"'Probably easy to fix. |
This comment has been minimized.
This comment has been minimized.
|
1.0 polish; P-low. If this gets fixed by 1.0, great; but if we shipped 1.0 with this semantics, its not the end of the world. |
pnkfelix
added
the
P-low
label
Mar 5, 2015
pnkfelix
added this to the 1.0 milestone
Mar 5, 2015
pnkfelix
removed
the
I-nominated
label
Mar 5, 2015
This comment has been minimized.
This comment has been minimized.
|
If we make single-argument panic!({ let x = "{}"; x })
panic!(7)Maybe add a The other thing needed for this issue is some way to convert a format string to an output string:
I benchmarked the size overhead of calling |
This comment has been minimized.
This comment has been minimized.
|
I found a mistake in a libstd test case that would presumably have been avoided were this issue fixed: assert_eq!((0 as $T).is_power_of_two(), false);
assert_eq!((1 as $T).is_power_of_two(), true);
assert_eq!((2 as $T).is_power_of_two(), true);
assert_eq!((3 as $T).is_power_of_two(), false);
assert_eq!((4 as $T).is_power_of_two(), true);
assert_eq!((5 as $T).is_power_of_two(), false);
assert!(($T::MAX / 2 + 1).is_power_of_two(), true);The last line should be What I was trying to find was a place invoking What if we changed the non-formatting |
This comment has been minimized.
This comment has been minimized.
|
triage: P-high I think the |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton In case it matters for bookkeeping: GitHub is still labeling this issue P-low, despite your triage: P-high comment. |
rust-highfive
added
P-medium
and removed
P-low
labels
Mar 9, 2015
rust-highfive
modified the milestones:
1.0 beta,
1.0
Mar 9, 2015
This comment has been minimized.
This comment has been minimized.
|
hehe, but it appears to have picked up your comment :) |
nrc
modified the milestones:
1.0 beta,
1.0
Mar 11, 2015
This comment has been minimized.
This comment has been minimized.
|
We need a patch to appear for this very soon for it to happen. |
This comment has been minimized.
This comment has been minimized.
|
I guess we also need a firm decision. |
This comment has been minimized.
This comment has been minimized.
|
Another question to consider: if we change single-argument I'm happy to write a patch, but I feel like it needs an RFC, and I haven't seen any discussion of this issue. Does it need to be posted on the forum? |
This comment has been minimized.
This comment has been minimized.
|
It prints I'd rather add a |
This comment has been minimized.
This comment has been minimized.
|
I created a post on the forum. http://internals.rust-lang.org/t/panic-shouldnt-compile/1851 |
This comment has been minimized.
This comment has been minimized.
|
Majority of the team says they want to preserve much of the existing behavor -- i.e. support passing a single arbitrary value, but also support the formatting form. The main strategy that was supported was to catch this error case (where a string-literal template string is being passed as the single argument, and it has placeholder braces), as a special case (perhaps via a lint) and only reject that case. E.g. any non string-literal unary input to |
pnkfelix
self-assigned this
Apr 9, 2015
This comment has been minimized.
This comment has been minimized.
|
(I think I have something put together to address this.) |
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Apr 13, 2015
pnkfelix
referenced this issue
Apr 13, 2015
Closed
Ensure a sole string-literal passed to `panic!` is not a fmt string. #24370
bors
added a commit
that referenced
this issue
Apr 13, 2015
bors
added a commit
that referenced
this issue
Apr 13, 2015
bors
added a commit
that referenced
this issue
Apr 13, 2015
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Apr 15, 2015
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Apr 15, 2015
bors
added a commit
that referenced
this issue
Apr 15, 2015
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Apr 17, 2015
pnkfelix
added a commit
to pnkfelix/rust
that referenced
this issue
Apr 18, 2015
This comment has been minimized.
This comment has been minimized.
|
(The backwards-compatible strategy for addressing this would be to just warn when format string literal is passed to unary |
pnkfelix
removed this from the 1.0 milestone
Apr 24, 2015
jonas-schievink
referenced this issue
Nov 24, 2015
Closed
panic!("{}") doesn't error out on compilation #30026
ollie27
referenced this issue
Dec 2, 2015
Closed
println!, eprintln! and writeln! accept other literals not just format strings #30143
This comment has been minimized.
This comment has been minimized.
|
Triage: this does reproduce today, printing
|
brson
added
the
T-libs
label
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
This is very similar to the recently closed #30143, so I'm going to tag this as such (rust-2-breakage-wishlist) and close. |
tomaka commentedMar 1, 2015
I didn't find any duplicate issue, but this problem has probably been there for a long time.
panic!("{}", 7)compiles and printsthread <main> panicked at "7", ...panic!("{} {}", 7)doesn't compile as an argument is missingpanic!("{}")does compile and printsthread <main> panicked at "{}", ...The last one doesn't detect potential mistakes, and is inconsistent with
println!("{}")which doesn't compile.