2018 edition ? Kleene operator by mark-i-m · Pull Request #51587 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation95 Commits7 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

mark-i-m

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

r? @nikomatsakis

@mark-i-m

@mark-i-m

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

@mark-i-m mark-i-m changed the title2018 edition ? Kleene operator [WIP] 2018 edition ? Kleene operator

Jun 16, 2018

@alexreg

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

@mark-i-m

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

@alexreg

@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

@alexreg

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

nikomatsakis

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

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:

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:

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

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

Choose a reason for hiding this comment

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

So to clarify:

Choose a reason for hiding this comment

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

I would prefer this:

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

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?

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

@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

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

@mark-i-m

@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

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

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

@mark-i-m

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

@rust-highfive

This comment has been minimized.

nikomatsakis

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

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?

Choose a reason for hiding this comment

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

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)

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

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

@mark-i-m

@alexcrichton

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

@mark-i-m

@alexcrichton

@bors

📌 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: Blocked on something else such as an RFC or other implementation work.

labels

Jul 24, 2018

@bors

bors added a commit that referenced this pull request

Jul 24, 2018

@bors

2018 edition ? Kleene operator

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

r? @nikomatsakis

@bors bors mentioned this pull request

Jul 24, 2018

@bors

@rust-highfive

📣 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

@rust-highfive

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

[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 |             <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mi>o</mi><mi>n</mi><mi>e</mi><mi>f</mi><mi>n</mi></mrow><annotation encoding="application/x-tex">(one fn </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord mathnormal">o</span><span class="mord mathnormal">n</span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mord mathnormal">n</span></span></span></span>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.

kennytm added a commit to rust-lang/rustfmt that referenced this pull request

Jul 26, 2018

@kennytm

This was referenced

Jul 26, 2018

Labels

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.