Uh oh!
There was an error while loading. Please reload this page.
Panic on errors in format! or <T: Display>::to_string - #40117
Conversation
SimonSapin
commented
Feb 26, 2017
By the way, this function and this method are very similar, but only one calls |
SimonSapin
commented
Feb 26, 2017
Same for using |
est31
commented
Feb 26, 2017
Isn't this a breaking change? It could in fact lead to UB in existing programs when people update their rustc. E.g. they checked the implementation of the functions and detected no panic, and then they assumed they can call it from C code without any code surrounding it. Now if it panics, it will give UB. |
It is a behavioral change and so there may be an argument that it's a breaking change and can't be done. But I strongly reject the idea that one can inspect Obviously some simple APIs are intended and can be assumed not to panic (e.g., |
alexcrichton
commented
Feb 27, 2017
@ollie27commented that this is a breaking change (e.g. we've documented the opposite) In light of that, could you elaborate @SimonSapin on why we should also update that documentation to say otherwise? |
SimonSapin
commented
Feb 27, 2017
@alexcrichton, I don’t understand how "this is a breaking change" follows from @ollie27’s comment. On the contrary, @ollie27 points out that the restriction enforced by this PR is already documented. In other words, this PR makes I don’t think we should update the documentation, it already says what I want it to say. |
alexcrichton
commented
Feb 27, 2017
I suppose it depends on how you read it. I'm seeing:
which to me implies 'does not panic' |
SimonSapin
commented
Feb 27, 2017
To me that precise quote means “Returning |
alexcrichton
commented
Feb 28, 2017
Discussed during libs triage today the conclusion was that this is a good PR to merge, but @SimonSapin can you update the docs that @ollie27 pointed out to clarify the panic semantics? |
a8b4bce to
60a94e2CompareSimonSapin
commented
Mar 1, 2017
Done. |
ollie27
commented
Mar 1, 2017
Do we really need to document that consumers of incorrectly implemented traits can As the aim here is to catch bugs in user code it might be better to add this assertion to the |
alexcrichton
commented
Mar 1, 2017
@ollie27 would you prefer we don't document it? Or would you prefer we don't change the behavior? Emprical evidence I think shows the documentation is necessary (I personally interpreted it differently) |
ollie27
commented
Mar 1, 2017
This seems like a perfectly reasonable change as long as there's no significant performance impact of course. We could add a comment saying that if you implement these traits incorrectly then consumers may |
SimonSapin
commented
Mar 1, 2017
@ollie27 I think that what you describe is already what’s in the pull request? Note that I pushed an amended commit today. |
ollie27
commented
Mar 1, 2017
I hope I'm looking at the latest version. You added "The |
SimonSapin
commented
Mar 1, 2017
shrugs I added this because Alex asked for it. |
alexcrichton
commented
Mar 1, 2017
Ok then let's remove it |
… instead of silently ignoring a result. `fmt::Write for String` never returns `Err`, so implementations of `Display` (or other traits of that family) never should either. Fixesrust-lang#40103
60a94e2 to
f2017f4CompareSimonSapin
commented
Mar 1, 2017
Removed the new bit of module-level docs for |
alexcrichton
commented
Mar 1, 2017
@bors: r+ |
bors
commented
Mar 1, 2017
📌 Commit f2017f4 has been approved by |
…ter, r=alexcrichton Panic on errors in `format!` or `<T: Display>::to_string` … instead of silently ignoring a result. `fmt::Write for String` never returns `Err`, so implementations of `Display` (or other traits of that family) never should either. Fixesrust-lang#40103
…ter, r=alexcrichton Panic on errors in `format!` or `<T: Display>::to_string` … instead of silently ignoring a result. `fmt::Write for String` never returns `Err`, so implementations of `Display` (or other traits of that family) never should either. Fixesrust-lang#40103
…ter, r=alexcrichton Panic on errors in `format!` or `<T: Display>::to_string` … instead of silently ignoring a result. `fmt::Write for String` never returns `Err`, so implementations of `Display` (or other traits of that family) never should either. Fixesrust-lang#40103
arielb1
commented
Apr 4, 2017
This is a breaking change. |
… instead of silently ignoring a result.
fmt::Write for Stringnever returnsErr, so implementations ofDisplay(or other traits of that family) never should either.Fixes#40103