-
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
Implement RFC 1925 #44108
Implement RFC 1925 #44108
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
src/libsyntax/feature_gate.rs
Outdated
fn visit_arm(&mut self, arm: &'a ast::Arm) { | ||
if arm.used_beginning_vert { | ||
gate_feature_post!(&self, match_beginning_vert, | ||
arm.pats[0].span, |
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.
Is there a better span to use here?
I suppose used_beginning_vert could become Option<Span>
...
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.
It should be possible to call emit_feature_err
immediately from parse_arm
, the precise span is available there.
In addition, changes to AST (used_beginning_vert: bool
) will likely break rustfmt
and you'll have to send PR to rustfmt repo as well, do submodule updates, etc, so I recommend against it.
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.
Oh, I didn't know that features were already available during parsing!
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.
I don't know if they are available as well, but it's worth trying, because the alternative is not especially pleasant.
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
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.
This needs a // gate-test-match_beginning_vert
annotation, so the test is counted as a feature gate test.
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.
That shouldn't be necessary as long as the test is named correctly, no? That's what tidy said, and most of the other tests (ex) don't have them.
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.
Okay, if this passes testing, then it's good.
src/libsyntax/parse/parser.rs
Outdated
@@ -3149,6 +3149,13 @@ impl<'a> Parser<'a> { | |||
maybe_whole!(self, NtArm, |x| x); | |||
|
|||
let attrs = self.parse_outer_attributes()?; | |||
// Allow a '|' before the pats (RFC 1925) | |||
let beginning_vert; |
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.
This should be just
let beginning_vert = if self.eat(&token::BinOp(token::Or)) {
Some(self.prev_span)
} else {
None
};
edit: Nevermind, that can work as well.
c9bb16e
to
f4dc91a
Compare
I can't find any way to query features in the parser, and I'm pretty sure it doesn't exist. Nothing else in the parser (outside of libsyntax_ext) uses features, and the features need to be parsed! I see a few paths forward:
|
Ok, sorry for pointing the wrong way.
Not issues, just possible inconveniences with updating rustfmt and rls. |
r? @arielb1 |
r? @petrochenkov - he's our parser guy |
But currently, I think a feature gate is wide-open
|
src/libsyntax/parse/parser.rs
Outdated
@@ -3149,6 +3150,14 @@ impl<'a> Parser<'a> { | |||
maybe_whole!(self, NtArm, |x| x); | |||
|
|||
let attrs = self.parse_outer_attributes()?; | |||
if self.eat(&token::BinOp(token::Or)) | |||
&& !self.sess.unstable_features.is_nightly_build() { |
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.
You should use sess.features.borrow().match_beginning_vert
here, otherwise the feature gate won't work
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.
sess
is a ParseSess
which does not have a features
field.
@arielb1 yep! waiting for confirmation that a feature gate is necessary/desired before I reimplement it by mucking with the AST. |
@mattico
Let's add a feature gate. |
@petrochenkov sounds good, will do! |
f531b24
to
e631b8d
Compare
Interesting failures. Taking a look. |
I ran a build of rustfmt, it works fine with this change. They only access single fields of Arm, so it doesn't break anything. RLS also works. Clippy was already broken before these changes. |
@bors r+ |
📌 Commit 22ca03b has been approved by |
☀️ Test successful - status-appveyor, status-travis |
cc #44101