-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Panic on errors in format!
or <T: Display>::to_string
#40117
Conversation
By the way, this function and this method are very similar, but only one calls |
Same for using |
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., |
@ollie27 commented 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? |
@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. |
I suppose it depends on how you read it. I'm seeing:
which to me implies 'does not panic' |
To me that precise quote means “Returning |
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
60a94e2
Compare
Done. |
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 |
@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) |
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 |
@ollie27 I think that what you describe is already what’s in the pull request? Note that I pushed an amended commit today. |
I hope I'm looking at the latest version. You added "The |
shrugs I added this because Alex asked for it. |
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. Fixes rust-lang#40103
60a94e2
to
f2017f4
Compare
Removed the new bit of module-level docs for |
@bors: r+ |
📌 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. Fixes rust-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. Fixes rust-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. Fixes rust-lang#40103
This is a breaking change. |
… instead of silently ignoring a result.
fmt::Write for String
never returnsErr
, so implementations ofDisplay
(or other traits of that family) never should either.Fixes #40103