-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Experimental feature postfix match #121619
Conversation
rustbot has assigned @petrochenkov. Use r? to explicitly pick a reviewer |
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
UI tests need to be culled |
787fec5
to
55ffeaa
Compare
This comment has been minimized.
This comment has been minimized.
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.
The rustfmt team prefers that support for experimental features be added in a PR to the rust-lang/rustfmt repo. I've proposed an alternative set of changes that should prevent rustfmt from removing the experimental postfix expressions, but not apply formatting to it.
ast::ExprKind::Match(ref cond, ref arms, kind) => { | ||
rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs, kind) |
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.
Given that the postfix match is an experimental feature I'd prefer not to add formatting support in this PR. For now I think it makes sene to add just enough support so that rustfmt doesn't completely remove the postfix match.
I think the following changes would achieve that.
match kind {
MatchKind::Prefix => rewrite_match(context, cond, arms, shape, expr.span, &expr.attrs),
MatchKind::Postfix => {
// experimental feature postfix match (link to RFC)
Some(context.snippet(expr.span).to_owned())
}
}
cc: @calebcartwright
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 is what I did originally and iirc it caused rustfmt to crash.
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.
The only way I can think for context.snippet(expr.span).to_owned()
to crash is if the expr.span
isn't valid, but that seems unlikely. You could also try returning None
from the MatchKind::Postfix
match arm.
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 actually don't have any concerns with the formatting implementation proposed here as this is rather trivial syntactically, a reasonable initial formatting, and in accordance with the style guide policy on nightly-only/experimental syntax.
the more intriguing part for me was the mention of it "crashing", the details of which I'd be interested in seeing (though that could be shared with us separately in Zulip)
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.
Some sort of panic occurred. I'll try to replicate it when I work on this and post it on Zulip. Probably won't be until Friday or Saturday though.
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.
Ok, here's a branch with the panic: https://github.com/RossSmyth/rust/tree/rustfmt_test_panic
It be may as designed? Looking at it again after just running x.py test rustfmt
Ran 589 system tests.
assertion `left == right` failed: 1 system tests failed
left: 1
right: 0
Failed to join a test thread: Any { .. }
failures:
test::system_tests
test result: FAILED. 171 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 7.15s
There are two panics that occur.
rust/src/tools/rustfmt/src/test/mod.rs
Lines 367 to 369 in 279c9ba
// Display results. println!("Ran {} idempotent tests.", count); assert_eq!(fails, 0, "{} idempotent tests failed", fails);
Fails with left == right failed: 1 idempotent tests failed
rust/src/tools/rustfmt/src/test/mod.rs
Lines 66 to 77 in 279c9ba
fn run_test_with<F>(test_setting: &TestSetting, f: F) where F: FnOnce(), F: Send + 'static, { thread::Builder::new() .stack_size(test_setting.stack_size) .spawn(f) .expect("Failed to create a test thread") .join() .expect("Failed to join a test thread") }
Fails with panicked at src\\tools\\rustfmt\\src\\test\\mod.rs:76:10:\nFailed to join a test thread: Any { .. }
Is it designed to just panic if a test fails? It also dumps a pretty large JSON object out.
Some changes occurred in match checking cc @Nadrieril |
This comment has been minimized.
This comment has been minimized.
Two new commits:
I'm not sure if the second commit is needed or desired. There is more worked needed, but as far as I can tell it doesn't break clippy. Since there are many other MatchSources, clippy guards against the other kinds well. So in the end it results in Clippy ignoring postfix match expression and not emitting any lints. A quick |
Hmm I'm not sure why this fails in CI. It works on my computer. It looks like ui_tests isn't normalizing the test paths for some reason. Which is strange as every other Clippy UI test uses |
There are too many tests in |
I am aware of that. I am talking about the Clippy UI test failure. |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Josh Stone <jistone@redhat.com>
This comment has been minimized.
This comment has been minimized.
Failed to set assignee to
|
Hello fellow lang folks! I'm not sure exactly what the process is on our side to approve this, but since it's not a one-way door let's try a poll: @rfcbot poll T-lang Are you ok with an experimental implementation of postfix match in nightly? I'm not planning on waiting for full checkboxes, since we can always revert the nightly implementation if necessary, but I want to give an opportunity for folks to raise objections just in case. |
Team member @scottmcm has asked teams: T-lang, for consensus on:
|
@bors r=petrochenkov |
Experimental feature postfix match This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, rust-lang#121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) `@scottmcm` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md). This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement. It is entirely implemented in the parser, so it should be relatively easy to remove if needed. This PR is split in to 5 commits to ease review. 1. The implementation of the feature & gating. 2. Add a MatchKind field, fix uses, fix pretty. 3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix. 4. Add new MatchSource to HIR for Clippy & other HIR consumers
Experimental feature postfix match This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, rust-lang#121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) ``@scottmcm`` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md). This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement. It is entirely implemented in the parser, so it should be relatively easy to remove if needed. This PR is split in to 5 commits to ease review. 1. The implementation of the feature & gating. 2. Add a MatchKind field, fix uses, fix pretty. 3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix. 4. Add new MatchSource to HIR for Clippy & other HIR consumers
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#121619 (Experimental feature postfix match) - rust-lang#122370 (Gracefully handle `AnonConst` in `diagnostic_hir_wf_check()`) - rust-lang#122537 (interpret/allocation: fix aliasing issue in interpreter and refactor getters a bit) - rust-lang#122542 (coverage: Clean up marker statements that aren't needed later) - rust-lang#122800 (Add `NonNull::<[T]>::is_empty`.) - rust-lang#122820 (Stop using `<DefId as Ord>` in various diagnostic situations) - rust-lang#122847 (Suggest `RUST_MIN_STACK` workaround on overflow) - rust-lang#122855 (Fix Itanium mangling usizes) - rust-lang#122863 (add more ice tests ) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#121619 - RossSmyth:pfix_match, r=petrochenkov Experimental feature postfix match This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, rust-lang#121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) ```@scottmcm``` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md). This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement. It is entirely implemented in the parser, so it should be relatively easy to remove if needed. This PR is split in to 5 commits to ease review. 1. The implementation of the feature & gating. 2. Add a MatchKind field, fix uses, fix pretty. 3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix. 4. Add new MatchSource to HIR for Clippy & other HIR consumers
Experimental feature postfix match This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, rust-lang#121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) ```@scottmcm``` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md). This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement. It is entirely implemented in the parser, so it should be relatively easy to remove if needed. This PR is split in to 5 commits to ease review. 1. The implementation of the feature & gating. 2. Add a MatchKind field, fix uses, fix pretty. 3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix. 4. Add new MatchSource to HIR for Clippy & other HIR consumers
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#121619 (Experimental feature postfix match) - rust-lang#122370 (Gracefully handle `AnonConst` in `diagnostic_hir_wf_check()`) - rust-lang#122537 (interpret/allocation: fix aliasing issue in interpreter and refactor getters a bit) - rust-lang#122542 (coverage: Clean up marker statements that aren't needed later) - rust-lang#122800 (Add `NonNull::<[T]>::is_empty`.) - rust-lang#122820 (Stop using `<DefId as Ord>` in various diagnostic situations) - rust-lang#122847 (Suggest `RUST_MIN_STACK` workaround on overflow) - rust-lang#122855 (Fix Itanium mangling usizes) - rust-lang#122863 (add more ice tests ) r? `@ghost` `@rustbot` modify labels: rollup
Experimental feature postfix match This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, rust-lang#121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) ```@scottmcm``` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md). This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement. It is entirely implemented in the parser, so it should be relatively easy to remove if needed. This PR is split in to 5 commits to ease review. 1. The implementation of the feature & gating. 2. Add a MatchKind field, fix uses, fix pretty. 3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix. 4. Add new MatchSource to HIR for Clippy & other HIR consumers
This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, #121618). Liaison is @scottmcm with the lang team's experimental feature gate process.
This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement.
It is entirely implemented in the parser, so it should be relatively easy to remove if needed.
This PR is split in to 5 commits to ease review.