-
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
Relax termination_trait's error bound #47544
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @shepmaster (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@U007D could you add a test with the following main: |
Done, for the positive ( fn main() -> Result<(), Box<Error>> { Ok(()) } I'd also like to test the negative ( fn main() -> Result<(), Box<Error>> {
Err(Box::new(Error::new(ErrorKind::Other, "returned Box<Error> from main()")))
} but after looking at spending some time with both Let me know if you know a way to include the negative test--with just the positive case, at least we know it compiles... :) |
@U007D Please add the negative case also :) Add the test to |
@bkchr I tried, and it didn't. Near as I can tell, it was expecting a panic, not a non-zero status code. I also tried:
All failed for me. :( |
@U007D Look at |
Sweet. I'll try that. |
Ahh, I think that is wrong :( Are you somewhere on irc or so? |
// error-pattern:nonzero
#![feature(termination_trait)]
use std::io::{Error, ErrorKind};
fn main() -> Result<(), Box<Error>> {
Err(Box::new(Error::new(ErrorKind::Other, "returned Box<Error> from main()")))
} gives:
Any ideas? |
@bkchr I am--U007D on irc.mozilla.org. ( |
@bkchr Well, it's past midnight here--I think I'll call it a night. You can leave any ideas you may have here or |
@U007D I would propose the following patch for
And as test just:
|
Thanks, @bkchr, that was helpful. I ended up having to do a couple of hours of poking around to make it work: In Once I figured out which way was was up ;), your patch worked like a charm and the solution ended up being simple--it was a good learning process for me :). TL;DR: There is now a negative test and it passes. :) |
I also have the change ready for index dc7fa53aab..f2ae7e99df 100644
--- a/src/libstd/termination.rs
+++ b/src/libstd/termination.rs
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use fmt::Debug;
+use fmt::Display;
#[cfg(target_arch = "wasm32")]
mod exit {
pub const SUCCESS: i32 = 0;
@@ -45,12 +45,12 @@ impl Termination for () {
}
#[unstable(feature = "termination_trait", issue = "43301")]
-impl<T: Termination, E: Debug> Termination for Result<T, E> {
+impl<T: Termination, E: Display> Termination for Result<T, E> {
fn report(self) -> i32 {
match self {
Ok(val) => val.report(),
Err(err) => {
- eprintln!("Error: {:?}", err);
+ eprintln!("Error: {}", err);
exit::FAILURE
}
} But I don't know the process well enough (i.e. does feature gating let us try different implementations on for size to see how we like them, or for stability's sake, do we make the decision before pushing the change?, How much consensus is needed first? etc.) to push it until someone gives me the go-ahead. |
src/tools/compiletest/src/runtest.rs
Outdated
self.fatal_proc_rec( | ||
&format!("failure produced the wrong error: {}", proc_res.status), | ||
&format!("failure must not return success exit status! Returned status: {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the branch is taken, the error code is always 0, so printing it is not required ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! That is an excellent point! :)
The PR won't be merged until we reach a preliminary decision, its not particularly important what is pushed to your branch (you just might have to revert it). |
@withoutboats Ah, great. I'll just go ahead and push my preferred impl, and will wait to hear back from folks re: feedback. And thanks for that information! |
Another thought, here -- if part of the goal here is to let people turn |
Nominated to talk about |
Lang team met today and discussed this. We agreed that this should use the We're also open to PRs to improve the readability of Debug impls on error types in std :) |
Ok, I'll roll back the last commit and will re-submit with Haha--I'm not sure I'm up for a PR just yet! ;) But I'll definitely continue to look for areas I can contribute. Thanks for all your guidance! |
…est header command and appropriate tests
@bors r+ |
📌 Commit 7948afd has been approved by |
⌛ Testing commit 7948afd with merge d5cf0de2663003c2b9e3a42b95c1e1f846fc7f69... |
💔 Test failed - status-travis |
@bors retry |
⌛ Testing commit 7948afd with merge fc30141e836b571eaca4976f2f771e6cf81543ad... |
💔 Test failed - status-appveyor |
@bors retry 3 hour timeout |
Relax termination_trait's error bound As per [this conversation](https://github.com/withoutboats/failure/issues/130#issuecomment-358572413) with @withoutboats and @bkchr
☀️ Test successful - status-appveyor, status-travis |
Thanks, @kennytm, for getting this landed! :) FYI, I tried using the feature on Playground but it Update: fixed link to demo panic. Playground reports:
The same code running on my machine compiles and runs successfully. |
Seems to work for me. What kind of panic are you seeing? |
Running the code from the run-pass test was enough to get it to panic for me. I've fixed the link to reproduce the panic. |
@U007D please file an issue |
Took my best guess and filed it here. |
As per this conversation with @withoutboats and @bkchr