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

Implement RFC 1925 #44108

Merged
merged 3 commits into from
Sep 3, 2017
Merged

Implement RFC 1925 #44108

merged 3 commits into from
Sep 3, 2017

Conversation

mattico
Copy link
Contributor

@mattico mattico commented Aug 26, 2017

cc #44101

@rust-highfive
Copy link
Collaborator

r? @steveklabnik

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

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,
Copy link
Contributor Author

@mattico mattico Aug 26, 2017

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>...

Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@@ -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;
Copy link
Contributor

@arqunis arqunis Aug 26, 2017

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.

@mattico mattico force-pushed the match-pipe branch 2 times, most recently from c9bb16e to f4dc91a Compare August 27, 2017 03:50
@mattico
Copy link
Contributor Author

mattico commented Aug 27, 2017

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:

  1. Enable this unconditionally. It's not too dangerous of a change, IMO.
  2. Enable this but only on nightly. This way we'd have a chance to catch any strange edge cases before it goes to stable, but it's not gated in the traditional sense. (currently implemented in this PR)
  3. Make the changes to have a real feature gate. Altering the AST to store this information is the path of least resistance, but it has some issues as pointed out by Implement RFC 1925 #44108 (comment)

@petrochenkov
Copy link
Contributor

I can't find any way to query features in the parser, and I'm pretty sure it doesn't exist

Ok, sorry for pointing the wrong way.

Altering the AST to store this information is the path of least resistance, but it has some issues

Not issues, just possible inconveniences with updating rustfmt and rls.

@carols10cents
Copy link
Member

r? @arielb1

@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2017
@arielb1
Copy link
Contributor

arielb1 commented Aug 29, 2017

r? @petrochenkov - he's our parser guy

@arielb1
Copy link
Contributor

arielb1 commented Aug 29, 2017

But currently, I think a feature gate is wide-open

[00:49:52] ---- [compile-fail] compile-fail/feature-gate-match_beginning_vert.rs stdout ----
[00:49:52] 	
[00:49:52] error: compile-fail test compiled successfully!
[00:49:52] status: exit code: 0

[00:49:52] command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/compile-fail/feature-gate-match_beginning_vert.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/feature-gate-match_beginning_vert.stage2-x86_64-unknown-linux-gnu" "-Crpath" "-O" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/compile-fail/feature-gate-match_beginning_vert.stage2-x86_64-unknown-linux-gnu.compile-fail.libaux" "-A" "unused"
[00:49:52] stdout:
[00:49:52] ------------------------------------------
[00:49:52] 
[00:49:52] ------------------------------------------
[00:49:52] stderr:
[00:49:52] ------------------------------------------
[00:49:52] 
[00:49:52] ------------------------------------------
[00:49:52] 
[00:49:52] thread '[compile-fail] compile-fail/feature-gate-match_beginning_vert.rs' panicked at 'explicit panic', /checkout/src/tools/compiletest/src/runtest.rs:2435:8
[00:49:52] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:49:52] 
[00:49:52] 
[00:49:52] failures:
[00:49:52]     [compile-fail] compile-fail/feature-gate-match_beginning_vert.rs
[00:49:52] 
[00:49:52] test result: FAILED. 2724 passed; 1 failed; 13 ignored; 0 measured; 0 filtered out
[00:49:52] 

@@ -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() {
Copy link
Contributor

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

Copy link
Contributor Author

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.

@mattico
Copy link
Contributor Author

mattico commented Aug 29, 2017

@arielb1 yep! waiting for confirmation that a feature gate is necessary/desired before I reimplement it by mucking with the AST.

@petrochenkov
Copy link
Contributor

@mattico
Citing @nikomatsakis:

Basically every time I've skipped a feature gate I've regretted it.

Let's add a feature gate.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 1, 2017
@mattico
Copy link
Contributor Author

mattico commented Sep 1, 2017

@petrochenkov sounds good, will do!

@mattico mattico force-pushed the match-pipe branch 2 times, most recently from f531b24 to e631b8d Compare September 1, 2017 17:27
@mattico
Copy link
Contributor Author

mattico commented Sep 1, 2017

Interesting failures. Taking a look.

@mattico
Copy link
Contributor Author

mattico commented Sep 1, 2017

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.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 2, 2017

📌 Commit 22ca03b has been approved by petrochenkov

@bors
Copy link
Contributor

bors commented Sep 2, 2017

⌛ Testing commit 22ca03b with merge 6f66730...

bors added a commit that referenced this pull request Sep 2, 2017
@bors
Copy link
Contributor

bors commented Sep 3, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing 6f66730 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants