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 upTracking issue for RFC 1937: `?` in `main` #43301
Comments
aturon
added
B-RFC-approved
T-lang
labels
Jul 17, 2017
This comment has been minimized.
This comment has been minimized.
ghost
commented
Jul 17, 2017
|
How are exit statuses going to be dealt with? |
This comment has been minimized.
This comment has been minimized.
|
This comment by @Screwtapello seems to have been made too close to the end of FCP for any alterations to be made to the RFC in response to it. In short: the RFC proposes returning 2 on failure on grounds which, while well-founded, are obscure and produce a slightly unusual result; the least surprising thing is to return 1 when the program has no indication it wants any more detail than just success or failure. Is this sufficiently bikesheddy that it can be discussed without it feeling like we're perverting the RFC process, or are we now locked into this specific implementation detail? |
This comment has been minimized.
This comment has been minimized.
ghost
commented
Jul 18, 2017
•
|
It's not an implementation detail though, is it? Some scripts use exit codes as a way to get information from a sub-process. |
This comment has been minimized.
This comment has been minimized.
|
This is specifically about the case when a sub-process (implemented in Rust) has no information to give, beyond a binary "everything's fine"/"something went wrong". |
This comment has been minimized.
This comment has been minimized.
NoraCodes
commented
Jul 18, 2017
That behavior is always extremely dependent on the program being called except in that non-zero means failure. Given that |
This comment has been minimized.
This comment has been minimized.
ghost
commented
Jul 18, 2017
|
I don't think SemVer has a "mostly insignificant detail" exception though. |
This comment has been minimized.
This comment has been minimized.
|
I think the exit code should be added to the unresolved questions list. @zackw also opened a related internals thread. |
Mark-Simulacrum
added
the
C-tracking-issue
label
Jul 27, 2017
This comment has been minimized.
This comment has been minimized.
|
Many people agree that the exit code should be |
Aceeri
referenced this issue
Sep 5, 2017
Closed
[wip] Implement error handling using error-chain #332
nikomatsakis
added
T-compiler
WG-compiler-middle
E-needs-mentor
labels
Sep 15, 2017
nikomatsakis
added this to the
impl period milestone
Sep 15, 2017
aturon
removed this from the
impl period milestone
Sep 15, 2017
arielb1
self-assigned this
Sep 18, 2017
This comment has been minimized.
This comment has been minimized.
|
@arielb1 are you going to implement this rfc? |
This comment has been minimized.
This comment has been minimized.
|
No, just to mentor it. I assigned so I won't forget to write the mentoring notes. |
This comment has been minimized.
This comment has been minimized.
|
Ahh nice, I would be interested in doing it :) |
This comment has been minimized.
This comment has been minimized.
|
That's why I'm here :-). I should write the mentoring instructions soon enough. |
This comment has been minimized.
This comment has been minimized.
|
Okay, then I'm waiting for your instructions. |
This comment has been minimized.
This comment has been minimized.
Mentoring InstructionsThis is a WG-compiler-middle issue. If you want to seek help, you can join #rustc on irc.mozilla.org (I'm arielby) or https://gitter.im/rust-impl-period/WG-compiler-middle (I'm @arielb1 there). There's a WIP compiler readme at #44505 - it describes some things in the compiler. Work plan for this RFC:
add the
|
This comment has been minimized.
This comment has been minimized.
|
Can you at least join the IRC/gitter? |
nikomatsakis
added
E-mentor
and removed
E-needs-mentor
labels
Sep 21, 2017
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
No sorry, no progress up to now. Currently I have a lot of things to do, but I hope that I will find some time this week to start on this. |
This comment has been minimized.
This comment has been minimized.
oblitum
commented
Jun 2, 2018
|
I just want to express that I thought the aim of this was to bring |
This comment has been minimized.
This comment has been minimized.
nixpulvis
commented
Jun 2, 2018
|
@oblitum It's not just for testing. It's just not (by default) going to use the |
This comment has been minimized.
This comment has been minimized.
|
Would it be possible to introduce a newtype in the #[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
#[must_use]
struct DisplayResult<E: fmt::Display>(Result<(), E>)
impl<E> Termination for DisplayResult<E> {
// ... same as Result, but use "{}" instead of "{:?}"
}
impl<E> From<Result<(), E>> for DisplayResult<E> {}
impl<E> Deref<Result<(), E>> for DisplayResult<E> {}
impl<E> Try for DisplayResult<E> {}
// ...This should allow users to write: fn main() -> DisplayResult<MyError> {
// Ordinary code; conversions happen automatically via From, Try, etc.
}The main motivations here are:
|
This comment has been minimized.
This comment has been minimized.
|
Follow-up: It occurs to me that the semantics of fn main() -> DisplayResult<io::Error> {
let f = io::File::open("path_to_file")?;
let result = String::new();
f.read_to_string(result)?
}Assuming that this doesn't work, perhaps instead this could be made a simple conditional compilation flag in Cargo.toml? |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Jul 30, 2018
|
@Lucretiel: you seem to assume programmers mainly just want to print an exit message to the console. This does not hold for non-technical desktop applications, daemons with logging plumbing, etc. I prefer us not to add ‘commonly useful’ stuff to the standard library without compelling evidence (e.g. numbers) it should be in there. |
This comment has been minimized.
This comment has been minimized.
|
I am assuming that programmers who are returning a There seems to be wide agreement in this thread that something should be printed to stderr; the key decision to be made are "Should it print with |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Jul 31, 2018
•
|
@Lucretiel, for me the value of returning a |
This comment has been minimized.
This comment has been minimized.
|
I used this recently and wished that it called A process failure I notice is that the decision was made by lang team (mainly Niko and I) rather than libs team, but the code in question lives entirely in std. Possibly libs would've made a better decision. |
This comment has been minimized.
This comment has been minimized.
|
@withoutboats is it too late to change? I notice that the feature is still tagged as nightly-only / experimental in the docs, but it's possible I don't understand some of the granularity behind the stabilization process. |
This comment has been minimized.
This comment has been minimized.
|
I too would like to see this change and regret not being a stronger advocate for it when the team asked me to change the implementation from |
This comment has been minimized.
This comment has been minimized.
|
@Lucretiel |
This comment has been minimized.
This comment has been minimized.
jdahlstrom
commented
Sep 21, 2018
|
Is there a ticket or a timeline for stabilizing the name of the trait? |
This comment has been minimized.
This comment has been minimized.
|
@xfix That would imply that it's possible to change the implementation, right? The behavior doesn't change ( impl<E: Debug> Termination for Result<(), E> ...to: impl<E: Display> Termination for Result<(), E> ... |
This comment has been minimized.
This comment has been minimized.
Not without breaking backwards compatibility. This code compiles in today's stable Rust: #[derive(Debug)]
struct X;
fn main() -> Result<(), X> {
Ok(())
}With the proposed change to require As has already been mentioned, it's possible something like specialization might help, but my current understanding of specialization is that would only be useful for those types which implement both trait ResultTerm {
fn which(&self);
}
impl<T: Debug> ResultTerm for T {
default fn which(&self) {
println!("{:?}", self)
}
}
impl<T: Debug + Display> ResultTerm for T {
fn which(&self) {
println!("{}", self)
}
}
enum MyResult<T, E> {
Ok(T),
Err(E),
}
impl<T, E> Termination for MyResult<T, E>
where
E: ResultTerm,
{
fn report(self) -> i32 {
match self {
MyResult::Err(e) => {
e.which();
1
}
_ => 0,
}
}
}This may be enough to cover all the common cases, but it does publicly expose specialization. |
This comment has been minimized.
This comment has been minimized.
|
Ah, I see what you mean about stable rust. For some reason I wasn't aware that this was available in stable. Is this something that could be switched at compile time with a Cargo flag? In the same way that other things are switchable, like |
This comment has been minimized.
This comment has been minimized.
|
Maybe? I could see it being feasible to have a different behaviour for |
This comment has been minimized.
This comment has been minimized.
|
Different crates in the same program can be in different editions but use the same |
BurntSushi
referenced this issue
Oct 9, 2018
Closed
replace `try_main` with with main, returning a Result #72
This comment has been minimized.
This comment has been minimized.
|
I don't think we need to deprecate anything. I'll echo @Aaronepower 's sentiment that limiting to only Display types could serve to just dissatisfy quick-script users (deriving Debug is trivial, implementing Display isn't) in the same way that the current situation dissatisfies production users. Even if we could, I don't think it would ultimately be a benefit to. I think the specialization approach laid out by @shepmaster has promise, in that it would create the following behavior:
Someone might object to point 2, in the case where you have a type with Display but you want it to print Debug for whatever reason; I think this case would be addressed by Niko's proposal of various predesigned output format Error types (which are probably worth exploring even if we go with the specialization route). As for point 3, it's a little janky (maybe we should have done |
This comment has been minimized.
This comment has been minimized.
A case where |
This comment has been minimized.
This comment has been minimized.
|
@SimonSapin I wouldn't say it is preferable in a quick scripting environment, or rather not preferable enough that I would be in a position where I wanted the String to be printed as |
This comment has been minimized.
This comment has been minimized.
|
FWIW what is formatted is not the Lines 1527 to 1533 in cb6eedd |
This comment has been minimized.
This comment has been minimized.
|
I think given the situation the best thing we can do is specialization for types that implement The main question is whether or not that impl falls under our current policy for specialized impls in std. We generally have a rule that we only use specialization in std where we don't provide a stable guarantee that the behavior won't change later (because specialization itself is an unstable feature). Are we comfortable providing this impl now in the awareness that its possible that someday these types will revert to printing their |
This comment has been minimized.
This comment has been minimized.
|
Actually, I think we cannot allow this specialization right now, because it could be used to introduce unsoundness. This impl is actually exactly the kind of specialization that causes us so many problems! use std::cell::Cell;
use std::fmt::*;
struct Foo<'a, 'b> {
a: &'a Cell<&'a i32>,
b: &'b i32,
}
impl<'a, 'b> Debug for Foo<'a, 'b> {
fn fmt(&self, _: &mut Formatter) -> Result {
Ok(())
}
}
impl<'a> Display for Foo<'a, 'a> {
fn fmt(&self, _: &mut Formatter) -> Result {
self.a.set(self.b);
Ok(())
}
}Because of the way specialization currently works, I could call |
nikomatsakis
referenced this issue
Nov 2, 2018
Closed
Tracking issue for RFC #2175: or-patterns in if / while let expressions #48215
This comment has been minimized.
This comment has been minimized.
Kixunil
commented
Nov 15, 2018
|
I don't know about you guys, but when I write quick "scripts", I just |
This comment has been minimized.
This comment has been minimized.
This is actually why I feel so strongly about |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Nov 17, 2018
|
@Kixunil: Alternatively, I would prefer a more elaborate error handling strategy and/or more extensive logging and/or debugging. |
aturon commentedJul 17, 2017
•
edited by carols10cents
This is a tracking issue for the RFC "
?inmain" (rust-lang/rfcs#1937).Steps:
?inmain(#46479)?in doctest?in#[test]Stabilizations:
mainwith non-() return types (#48453) Merged in #49162Related issues:
Unresolved questions:
this will be stabilized by #48453no longer true after #48497