-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for ?
operator and try
blocks (RFC 243, question_mark
& try_blocks
features)
#31436
Comments
The accompanying RFC discusses a desugaring based on labeled return/break, are we getting that too or will there just be special treatment for EDIT: I think labeled return/break is an excellent idea separate from |
Labeled return/break is purely for explanatory purposes. On Fri, Feb 5, 2016 at 3:56 PM, Jonathan Reem notifications@github.com
|
Another unresolved question we have to resolve before stabilizing is what the contract which |
Please do! |
On the subject of the |
How this is treated during parsing?
|
@petrochenkov Well, the definition couldn't affect parsing, but I think we still have a lookahead rule, based on the second token after |
Also
+ rust-lang/rfcs#306 if (when!) implemented. Given the examples above I'm for the simplest solution (as usual) - always treat |
It would be easier if a keyword was used instead of |
This is the keywords list: http://doc.rust-lang.org/nightly/grammar.html#keywords |
@bluss yeah, I admit none of them are great... |
|
Can't
You will get a panic stack trace starting from the first occurrence of But when debugging foreign libraries written by people who haven't implemented that trick, one relies on It would be cool if overriding Later on when the macro system gets more features you can even panic! only for specific types. If this proposal requires an RFC please let me know. |
Ideally |
Stack traces are just one example (though a very useful one, seems to me). On Sun, Feb 7, 2016 at 4:14 PM, Russell Johnston notifications@github.com
|
Without wanting to speculate, I think that it could work, albeit with some issues. Consider the usual case where one has code returning some This would require everybody, even those who don't want to debug, to import their wished trait implementation when using Possibly E0117 can be an issue too if wanting to do custom Having the possibility to override via a macro would provide a greater flexibility without the additional burden on the original implementor (they don't have to import their wished implementation). But I also see that rust never had a macro based operator before, and that implementing I am okay with any setup which enables one to get |
Just to chime in on bikeshedding: |
|
Also, not that I expect this to change anything, but a note that this is going to break multi-arm macros that were accepting |
Don't overdo the backwards compatibility, just treat I can also imagine some possible problems that don't involve struct literals (e.g. Didn't we have a for adding new keywords, anyways? We could offer some kind of |
I agree. This isn't even the first RFC where this has come up (rust-lang/rfcs#1444 is another example). I expect it won't be the last. (Also |
Wasn't the whole argument for not reserving several keywords prior to 1.0 that we'd definitely be introducing a way to add new keywords to the language backward compatibly (possibly by explicitly opting in), so there was no point? Seems like now would be a good time. |
@japaric Are you interested in reviving your old PR and taking this on? |
@aturon My implementation simply desugared |
@japaric What was the reason for restricting it to methods and function calls? Wouldn't parsing it be easier as a general postfix operator? |
I think the syntactic similarity to a function definition would be harmful because it suggests that But For this reason I actually think we should revisit the spelling of try?: MyResult {
// ...
} |
I think that try type annotations will probably not be a thing for the same reason that generic type ascription got removed from the compiler: pretty much all solutions end up being just a worse version of Ultimately, we're talking about a miniscule number of characters saved here, and a bunch of weird inference bugs that could result. Doesn't really seem like a priority over just getting the existing syntax out there. |
@clarfonthey oh, yeah, that works too. An alternative could be added later anyway. |
@clarfonthey I completely agree. Not only does |
Is all that is required here a stabilization PR proposing that the assignment notation for inferring the type is consistent with other block types such as Edit: here is basically the same question asked in September 2022: #31436 (comment) |
I also believe that bad inference shouldn't be a blocker, we have already merged RPITIT with improving the iffy parts later on, so there is a precedent. This is also a very wanted feature by many people in the community and if this was stabilized just by having people using it they will notice the most common problems with type inference and will likely work on it, give solutions, ideas etc.
|
Suggestion: what if the The obvious downside is that it's obviously inconsistent with the behaviour of |
This is consistent with |
So, that'd render it useless for most code I work on, because ours goes the other way. We almost always rely on the implicit conversion of But once you have, Maybe it's worth stabilizing something that requires unification, but it wouldn't get me to use the feature. I do see value in the other error handling pattern wherein someone does actually make sure to use the same error type, though it is hard for me to think of many complex cases that would only use one error type, simply because of dependencies all bringing their own. It'd also be surprising behavior anyway: the |
…h-arm, r=compiler-errors add test for try-block-in-match-arm This is noted as an implementation concern under the tracking issue for `?` and `try` blocks. (Issue 31436) Refs: rust-lang#31436
…h-arm, r=compiler-errors add test for try-block-in-match-arm This is noted as an implementation concern under the tracking issue for `?` and `try` blocks. (Issue 31436) Refs: rust-lang#31436
To be clear, @afetisov was suggesting that the conversation still happens when the return type on the try block is annotated. |
I feel like that when That is the inference solver could maybe forward the inference constraints from inner try blocks to outer try blocks (if they are the direct parent in the AST). I think it's fine to error and ask for annotations if that does not lead to a inference solution. More concretely, given: #![feature(try_blocks)]
fn main() {
match try {
let r: Result::<(), ()> = try {
Err(())?;
};
r?;
} {
Err(()) => (),
Ok(()) => (),
}
} It seems very reasonable that Are there cases where this would obviously not work? And, are there inference problems which are not related to try block nesting? Edit: Ok I suppose this is really asking why Edit 2: It seems the inference problem can be summed up by this code which was linked to from the rust/compiler/rustc_codegen_ssa/src/back/linker.rs Lines 529 to 573 in 7cf2056
|
Isn't the core part of this discussion blocking at least in part on syntax to annotate the blocks, though? I did slightly misread, to be fair--if annotating causes the conversion to happen then yeah that works for me and the codebases I work on. But I think that "pruning" ideas might be the better thing to do, and nothing says that Rust can't just shrug and go "always annotate" and land. There's definitely precedent for that by now, e.g. rpitit. |
So after reading the small pile of RFCs which are in one way or other related to this feature (but not well linked from the OP) (probably because the OP outdates some of these):
There doesn't seem to be any comprehensive reference for From the try trait v2 RFC:
So it seems to me that the best way to move forward here would really be to make a dedicated try blocks RFC where a reference can be made for what the implementation should conform to, and try to make a direction for how to handle the inference problems, as well as documenting which concerns actually need to be figured out before stabilization and which can be left for future possibilities. Maybe that's a bit heavy handed, and perhaps people don't think that's necessary but that's probably the direction I would opt to take before wanting to make PRs to adjust the compiler inference for try blocks in specific... if no one directs otherwise an RFC is what I plan to do... Edit: It seems I missed the try-blocks Zulip discussion from 2022: In the top of that thread, scottmcm says:
For those who don't want to dig into the thread, there was a draft at https://github.com/scottmcm/rfcs/blob/try-again/text/0000-resolving-try-annotations.md#summary |
I think that before another RFC, a useful step forward would be to summarize all the existing RFCs and discussions from both GitHub and Zulip in a single document, so that it is easier to see the status quo, and the unresolved questions and blockers. |
…h-arm, r=compiler-errors add test for try-block-in-match-arm This is noted as an implementation concern under the tracking issue for `?` and `try` blocks. (Issue 31436) Refs: rust-lang#31436
Rollup merge of rust-lang#120540 - Fishrock123:test-try-block-in-match-arm, r=compiler-errors add test for try-block-in-match-arm This is noted as an implementation concern under the tracking issue for `?` and `try` blocks. (Issue 31436) Refs: rust-lang#31436
I don't agree. All of the discussion should happen here and all of the relevant points should be raised here. If anyone has heard of anything they might point to it but I don't think that it makes sense to require a document because nobody wants to go over all threads compiling information. It is my understanding that the only question left is about the inference, and based on the general sentiment that's not a blocking issue. I propose to stabilize! |
Of course that no one wants to do it, it's a lot of work, but that's what it takes to move these big features forwars :) For a stabilization PR, we'd need to do that anyway, to summarize the current state and precisely specify what are the current unresolved questions, potential blockers and alternatives. |
Actually, no. Discussion should be linked into the tracking issue, but tracking issues are not intended to be where discussion takes place. From the current tracking issue template:
It was my understanding that |
I asked @scottmcm if he still wanted to pursue his RFC in the Zulip thread, but with no reply https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/try.20blocks/near/419566066
I'm pretty sure I already did what you are referring by summarizing the discussion in the comment above that comment? Like I said, there isn't a clear design for what the feature should actually be; so honestly an RFC (or pre-rfc, or similar) - a "document", as you describe it, which I don't see why would be anything other than a RFC-like document. RFCs are for defining features with discussion. |
What are the blockers for stabilization right now? Does this need another RFC or can the initial implementation be added to stable? |
cc [`?` tracking issue](rust-lang/rust#31436)
Tracking issue for rust-lang/rfcs#243 and rust-lang/rfcs#1859.
Implementation concerns:
?
operator that is roughly equivalent totry!
- implement the?
operator #31954try { ... }
expression - implementcatch
expressions #39849do catch { ... }
syntax questiontry { .. }
, - Tracking issue for RFC 2388, reserve thetry
keyword and resolvedo catch { .. }
syntax question withtry { .. }
#50412catch
blocks are notOk
-wrapping their value #41414, now being settled anew in ResolvingOk
-wrapping fortry
blocks #70941)ExprWithBlock
, so works in a match arm without a commatry { expr? }?
currently requires an explicit type annotation somewhere).Try
trait (extend?
to operate over other types rfcs#1859)Try
trait (in place ofCarrier
) and convert?
to use it (Lower?
toTry
instead ofCarrier
#42275)Option
and so forth, and a suitable family of tests (Impl Try for Option #42526)?
error messages per RFC 1859 #35946)try
in new editiontry{}catch
(or other following idents) to leave design space open for the future, and point people to how to do what they want withmatch
insteadThe text was updated successfully, but these errors were encountered: