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

2018 edition ? Kleene operator #51587

Merged
merged 7 commits into from
Jul 24, 2018
Merged

Conversation

mark-i-m
Copy link
Member

This is my first attempt at implementing the migration lint + 2018 behavior as discussed in #48075

r? @nikomatsakis

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 16, 2018
@mark-i-m
Copy link
Member Author

@nikomatsakis Is this close to what you had in mind?

@mark-i-m
Copy link
Member Author

Also, I think I should add some more tests for 2015 vs 2018 behavior.

@mark-i-m mark-i-m changed the title 2018 edition ? Kleene operator [WIP] 2018 edition ? Kleene operator Jun 16, 2018
@alexreg
Copy link
Contributor

alexreg commented Jun 16, 2018

Nice work, @mark-i-m! Hoping we can get this merged in soon.

@mark-i-m
Copy link
Member Author

I'm not quite sure I got the lint right... it's currently a straight up warning...

@alexreg
Copy link
Contributor

alexreg commented Jun 16, 2018

@mark-i-m Yes, there look to be 1001 different ways of linting in the compiler code. This is the sort of thing that could really do with a chapter in the rustc book!

@mark-i-m
Copy link
Member Author

@alexreg https://rust-lang-nursery.github.io/rustc-guide/diag.html

@alexreg
Copy link
Contributor

alexreg commented Jun 16, 2018

@mark-i-m Oh gosh, I really should have checked before making that comment! The rustc book has come a long way since I last read it. The one thing still really deficient is the macros chapter, sadly... Also, it reminds me I should submit a PR about incremental compilation tests.

}
return (Some(token::Question), op);
}
Ok(Ok(op)) => return (Some(token::Question), op),
Ok(Ok(op)) => {
if !features.macro_at_most_once_rep
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the feature gate is not quite acting like I expect. My expectation is:

  • In Edition 2015:
    • If you do $()?[*+], then you get "? as separator".
    • Else, if you do $(foo)?[^*+], treat as "optional":
      • But if feature gate is not enabled, error
  • In Edition 2018:
    • If you do $(foo)?, then treat as "optional":
      • But if feature gate is not enabled, error.

My goal is that, when it comes time to stabilize, we can just "constant propagate" as if the feature gate was always enabled and get the final behavior we want:

  • in Rust 2015 we fallback to old behavior
  • in Rust 2018 we use new behavior all the time

(Is this the plan? Do we have an official, FCP'd proposal somewhere, anyway?)

Copy link
Member Author

Choose a reason for hiding this comment

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

(Is this the plan? Do we have an official, FCP'd proposal somewhere, anyway?)

No, we don't TMK

in Rust 2015 we fallback to old behavior

Given that this is behavior that will only last for another couple of months, my preference is to

  • just keep this unstable on 2015 and only enable in 2018
  • make the feature flag always turn on 2018 behavior

Copy link
Member Author

Choose a reason for hiding this comment

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

So to clarify:

  • In edition 2015:
    • Without feature flag: ? is a separator. ? is not a Kleene op.
    • With feature flag: same as 2018
  • In edition 2018
    • ? is not a separator. ? is a Kleene op that does not accept a separator.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer this:

  • In edition 2015:
    • With or without feature flag: ? is a separator and there is no ?
    • However, using ? as a separator issues a rust_2018_migration warning
  • In edition 2018:
    • ? is always a separator
      • and feature-gate is required until we stabilize

Point is, as before, that the feature-gate should just be a "error or no error" filter -- the behavior should model what we eventually want when all is said and done otherwise. And we never want Rust 2015 to support ?.

Copy link
Member Author

Choose a reason for hiding this comment

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

In edition 2018:
? is always a separator

You mean "in 2018, ? is always a kleene op", right?

Copy link
Contributor

Choose a reason for hiding this comment

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

(I'd sure hope so heh!)

@mark-i-m
Copy link
Member Author

@nikomatsakis I think I have implemented what you specified with one major exception: currently, the warning for using ? as a separator in 2015 edition always fires (i.e. it's not informed by #[warn()]).

Do you know how I can hook up the warning to fire when the lint group is set? Also, should it be a rust_2018_compatibility warning or a rust_2018_idioms warning, as mentioned in #50620? My inclination is towards the former.

@rust-highfive

This comment has been minimized.

@mark-i-m
Copy link
Member Author

This still needs some work. I am currently fixing/writing some tests.

@mark-i-m
Copy link
Member Author

@nikomatsakis I pushed a few tests. Do these tests represent the behavior you were expecting?

@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

@mark-i-m
Copy link
Member Author

Ok, I think I've implemented and added tests for everything except that the migration warning is currently an unconditional warning.

All feedback is welcome!

@mark-i-m mark-i-m changed the title [WIP] 2018 edition ? Kleene operator [Almost not WIP] 2018 edition ? Kleene operator Jun 25, 2018
@rust-highfive

This comment has been minimized.

@mark-i-m
Copy link
Member Author

Doh. I forgot that I started using this in places in the compiler 😛

@mark-i-m
Copy link
Member Author

Hmm... some of these are going to be hard to fix...

@rust-highfive

This comment has been minimized.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Looks good to me!

// Feature gate test for macro_at_most_once_rep under 2018 edition.

// gate-test-macro_at_most_once_rep
// compile-flags: --edition=2018
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated, but we should really add a // edition: 2018 option, shouldn't we?

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #51800

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -0,0 +1,71 @@
error[E0658]: Using the `?` macro Kleene operator for "at most one" repetition is unstable (see issue #48075)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: start compiler messages w/ lower-case letters

@nikomatsakis
Copy link
Contributor

@mark-i-m travis is unhappy, but this code looks good to me overall

@nikomatsakis nikomatsakis 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 Jun 25, 2018
@mark-i-m
Copy link
Member Author

@nikomatsakis Is it ok that the warning is unconditional?

@alexcrichton
Copy link
Member

Great! @mark-i-m want to rebase and I'll do a final once-over and r+?

@mark-i-m
Copy link
Member Author

🎉 Rebased :)

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jul 24, 2018

📌 Commit 10ee0f6 has been approved by alexcrichton

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Jul 24, 2018
@bors
Copy link
Contributor

bors commented Jul 24, 2018

⌛ Testing commit 10ee0f6 with merge f498e4e...

bors added a commit that referenced this pull request Jul 24, 2018
2018 edition `?` Kleene operator

This is my first attempt at implementing the migration lint + 2018 behavior as discussed in #48075

r? @nikomatsakis
@bors
Copy link
Contributor

bors commented Jul 24, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing f498e4e to master...

@bors bors merged commit 10ee0f6 into rust-lang:master Jul 24, 2018
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #51587!

Tested on commit f498e4e.
Direct link to PR: #51587

💔 rls on windows: test-pass → build-fail (cc @nrc, @rust-lang/infra).
💔 rls on linux: test-pass → build-fail (cc @nrc, @rust-lang/infra).
💔 rustfmt on windows: test-pass → build-fail (cc @nrc, @rust-lang/infra).
💔 rustfmt on linux: test-pass → build-fail (cc @nrc, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Jul 24, 2018
Tested on commit rust-lang/rust@f498e4e.
Direct link to PR: <rust-lang/rust#51587>

💔 rls on windows: test-pass → build-fail (cc @nrc, @rust-lang/infra).
💔 rls on linux: test-pass → build-fail (cc @nrc, @rust-lang/infra).
💔 rustfmt on windows: test-pass → build-fail (cc @nrc, @rust-lang/infra).
💔 rustfmt on linux: test-pass → build-fail (cc @nrc, @rust-lang/infra).
@kennytm
Copy link
Member

kennytm commented Jul 24, 2018

[01:09:02]   --> /cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-syntax-182.0.0/ext/expand.rs:47:60
[01:09:02]    |
[01:09:02] 47 |             $(one fn $fold_ast:ident; fn $visit_ast:ident;)?
[01:09:02]    |                                                            ^
[01:09:02]    |
[01:09:02]    = note: `?` is not a macro repetition operator

We need to update rustc-ap-syntax?

Edit: We'll need to wait for rustc-ap-syntax v209 to include this PR that fixes the use of ? inside libsyntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018-lints Area: lints supporting the 2018 edition S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants