Skip to content

Implement RFC 1925#44108

Merged
bors merged 3 commits into
rust-lang:masterfrom
mattico:match-pipe
Sep 3, 2017
Merged

Implement RFC 1925#44108
bors merged 3 commits into
rust-lang:masterfrom
mattico:match-pipe

Conversation

@mattico

@mattico mattico commented Aug 26, 2017

Copy link
Copy Markdown
Contributor

cc #44101

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @steveklabnik

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

Comment thread src/libsyntax/feature_gate.rs Outdated

@mattico mattico Aug 26, 2017

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/libsyntax/parse/parser.rs Outdated

@arqunis arqunis Aug 26, 2017

Copy link
Copy Markdown
Contributor

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

mattico commented Aug 27, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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
Copy Markdown
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

arielb1 commented Aug 29, 2017

Copy link
Copy Markdown
Contributor

r? @petrochenkov - he's our parser guy

@arielb1

arielb1 commented Aug 29, 2017

Copy link
Copy Markdown
Contributor

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] 

Comment thread src/libsyntax/parse/parser.rs Outdated

Copy link
Copy Markdown
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
Copy Markdown
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

mattico commented Aug 29, 2017

Copy link
Copy Markdown
Contributor Author

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

@petrochenkov

Copy link
Copy Markdown
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

mattico commented Sep 1, 2017

Copy link
Copy Markdown
Contributor Author

@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

mattico commented Sep 1, 2017

Copy link
Copy Markdown
Contributor Author

Interesting failures. Taking a look.

@mattico

mattico commented Sep 1, 2017

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Sep 2, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 22ca03b has been approved by petrochenkov

@bors

bors commented Sep 2, 2017

Copy link
Copy Markdown
Collaborator

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

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

bors commented Sep 3, 2017

Copy link
Copy Markdown
Collaborator

☀️ 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