Skip to content
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

[RFC] add the ? postfix operator #23040

Closed
wants to merge 1 commit into from
Closed

Conversation

japaric
Copy link
Member

@japaric japaric commented Mar 4, 2015

DO NOT MERGE NEEDS AN APPROVED RFC

The ? postfix operator is sugar equivalent to the try! macro, but is more amenable to chaining: File::open("foo")?.metadata()?.is_dir(). Currently the syntax is accepted in two places:

  • method calls: x.foo()?, and
  • function calls: foo()?

But it could be extended to idents: let x = y?; or foo(x?, y?).


cc @aturon @nikomatsakis

@rust-highfive
Copy link
Collaborator

r? @kmcallister

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member

eddyb commented Mar 4, 2015

Is there a reason for expr? to not be properly defined as a postfix operator?
I guess it binds tightly and only identifiers and function/method calls could result in a Result type, but what about (expr)??

ExprParen(P<Expr>),

/// `expr?`
ExprQuestion(P<Expr>),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably this could have a better name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExprTry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what's it's worth I think of ? as the exception propagation operator.

@nikomatsakis
Copy link
Contributor

👍 @japaric you are on a roll here.

@aturon
Copy link
Member

aturon commented Mar 5, 2015

@japaric thanks so much for taking the initiative here! As you point out, we need to have some accepted RFC for this, so @nikomatsakis and I will also work with @glaebhoerl to revise the existing RFC so we can move forward.

@huonw
Copy link
Member

huonw commented Apr 15, 2015

r? @nikomatsakis (to fill the 'no-one assigned' void)

@bors
Copy link
Contributor

bors commented Apr 30, 2015

☔ The latest upstream changes (presumably #24967) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

I'm going to close this PR, not because I don't want it, but because the lack of RFC is still blocking us. Hopefully we'll see motion there soon now that 1.0 is out the door! Thanks @japaric for the PR, in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants